Then on the server side for the LoginService public LoginResponse login(String username, String password) { LoginPService loginService = ServiceLocator.getLoginService(); PersonDTO personDTO = null;
try { personDTO = loginService.getUserByUsername(username); if (personDTO == null){ //.getInstance().info("Utilizador n√£o encontrado: "+username); return new LoginResponse(false, false); } else if (!loginService.checkPassword(password)){ //UCCLogger.getInstance().info("Password errada do utilizador: "+username); return new LoginResponse(false, false); } } catch (Throwable e) { return new LoginResponse(false, false); } LoginResponse response = new LoginResponse(); response.setLoginSuccess(true); PadroesSession padroesSession = PadroesSession.getInstance(); padroesSession.setRequest(getThreadLocalRequest()); padroesSession.setUser(personDTO); return response; } On Thu, Jun 3, 2010 at 9:33 PM, Bruno Lopes <bruno.lourenco.lo...@gmail.com>wrote: > YES > on the server side I have something like this: > > public class PadroesSession implements Serializable{ > > private static PadroesSession padroesSession=null; > > public static PadroesSession getInstance(){ > if(padroesSession == null){ > padroesSession = new PadroesSession(); > return padroesSession; > } else { > return padroesSession; > } > } > > private PadroesSession(){ > > } > > private static final String USER_SESSION = "userSession"; > private HttpServletRequest request = null; > private HttpSession session = null; > > > public PersonDTO getUser(){ > > if(null == session) return null; > > return session.getAttribute(USER_SESSION) != null ? > (PersonDTO)session.getAttribute(USER_SESSION) : null; > > } > > public HttpSession getSession(){ > return session; > } > > public void invalidate(){ > if(request!=null) > if(request.getSession(false)!= null) > request.getSession(false).invalidate(); > if(null != session){ > session.invalidate(); > session = null; > } > > > } > > public void setUser(PersonDTO user){ > if(null == user){ > if(session!=null) session.removeAttribute(USER_SESSION); > return; > } > > if(null != request) > this.session = request.getSession(true); > > if(session!=null) session.setAttribute(USER_SESSION, user); > } > > public String getId(){ > return request.getSession(false).getId(); > } > > public HttpServletRequest getRequest() { > return request; > } > > public void setRequest(HttpServletRequest request) { > this.request = request; > > } > > } > > > On Thu, Jun 3, 2010 at 2:45 PM, Magnus <alpineblas...@googlemail.com>wrote: > >> Hi, >> >> thank you for the code! I adopted it to my application. >> >> So you authenticate the user via the remote service! But how do you >> actually store the user context the app is running in? Do you do some >> session management? >> >> Thanks >> Magnus >> >> >> On Jun 2, 7:15 pm, Bruno Lopes <bruno.lourenco.lo...@gmail.com> wrote: >> > Hi Alpine Bluster, >> > >> > look at this code: >> > >> > public void onModuleLoad() { >> > >> > this.setLoginPanel(); >> > >> > loginButton = new Button("Login"); >> > >> > loginButton.addListener(new ButtonListenerAdapter() { >> > >> > public void onClick(Button button, EventObject e) { >> > >> > userAuthentication(); >> > >> > } >> > }); >> > >> > formPanel.addButton(loginButton); >> > >> > formPanel.setBorder(false); >> > >> > loginPanel.add(formPanel); >> > >> > Element appPanelEl = loginPanel.getElement(); >> > >> > @SuppressWarnings("unused") >> > >> > KeyMap map = new KeyMap(appPanelEl, new KeyMapConfig() { >> > >> > { >> > >> > setKey(EventObject.ENTER); >> > >> > setKeyListener(new KeyListener() { >> > >> > public void onKey(int key, EventObject e) { >> > >> > loginButton.focus(); >> > >> > } >> > }); >> > } >> > }); >> > >> > RootPanel.get("login_widget").add(loginPanel); >> > >> > } >> > >> > private void userAuthentication() { >> > >> > if (this.userNameField.getValueAsString().equals("")) >> > >> > Window.alert("username must not be empty."); >> > >> > else { >> > >> > loginService = GWT.create(LoginService.class); >> > >> > String username = this.userNameField.getValueAsString(); >> > >> > String password = this.passwordField.getValueAsString(); >> > >> > this.loginService.login(username, password, >> > >> > new AsyncCallback<LoginResponse>() { >> > >> > public void onFailure(Throwable caught) { >> > >> > Window.alert("server side failure: " + caught); >> > >> > } >> > >> > public void onSuccess(LoginResponse result) { >> > >> > if (result.isLoginSuccess()){ >> > >> > Window.Location.replace("./../Main.html"); >> > >> > } >> > >> > else Window.alert("username or password invalid."); >> > >> > } >> > }); >> > } >> > } >> > >> > ... >> > >> > FOR LOGOUT >> > .... >> > >> > private Panel northPanel = new Panel(); >> > >> > .... >> > >> > Toolbar toolbar = new Toolbar(); >> > >> > ToolbarButton logoutButton = new ToolbarButton("Sign Out"); >> > >> > logoutButton.addListener( new ButtonListenerAdapter() { >> > >> > public void onClick( Button button, EventObject e ) { >> > >> > LoginServiceAsync service = GWT.create(LoginService.class); >> > >> > service.logout(new AsyncCallback<Void>() { >> > >> > @Override >> > >> > public void onFailure(Throwable caught) { >> > >> > caught.printStackTrace(); >> > >> > } >> > >> > @Override >> > >> > public void onSuccess(Void result) { >> > >> > Window.Location.replace("./../Login.html"); >> > >> > } >> > }); >> > } >> > }); >> > >> > tabPanel = new TabPanel(); >> > >> > toolbar.addFill(); >> > >> > toolbar.addText("welcome," + someUser..); >> > >> > toolbar.addSeparator(); >> > >> > toolbar.addButton(logoutButton); >> > >> > tabPanel.setWidth(NORMALIZE_SPACING); >> > >> > tabPanel.setTopToolbar(toolbar); >> > >> > northPanel.add(tabPanel); >> > >> > On Wed, Jun 2, 2010 at 5:25 PM, Magnus <alpineblas...@googlemail.com> >> wrote: >> > > Hi, >> > >> > > I cannot find a minimalistic example that shows how to realize a >> login/ >> > > logout functionality. >> > > Could please someone point me to such an example? >> > >> > > I also wonder where to put the different things. For example, the code >> > > that immediately reacts on the "login" button could be placed within >> > > the "client" folder of a GWT project, or it could be realized as a >> > > servlet. >> > >> > > When do I use a servlet and how? >> > >> > > Thank you! >> > > Magnus >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "Google Web Toolkit" group. >> > > To post to this group, send email to >> google-web-tool...@googlegroups.com. >> > > To unsubscribe from this group, send email to >> > > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> >> <google-web-toolkit%2bunsubscr...@googlegroups.com<google-web-toolkit%252bunsubscr...@googlegroups.com> >> > >> > > . >> > > For more options, visit this group at >> > >http://groups.google.com/group/google-web-toolkit?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Web Toolkit" group. >> To post to this group, send email to google-web-tool...@googlegroups.com. >> To unsubscribe from this group, send email to >> google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-web-toolkit?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.