Init non working version
This commit is contained in:
60
TestGWT/src/com/test/gwt/server/LoginServiceImpl.java
Normal file
60
TestGWT/src/com/test/gwt/server/LoginServiceImpl.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.test.gwt.server;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.test.gwt.client.LoginService;
|
||||
import com.test.gwt.shared.UserDTO;
|
||||
|
||||
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService
|
||||
{
|
||||
private static final long serialVersionUID = 4456105400553118785L;
|
||||
|
||||
@Override
|
||||
public UserDTO loginServer(String name, String password)
|
||||
{
|
||||
UserDTO user = new UserDTO(name, password);
|
||||
storeUserInSession(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO loginFromSessionServer()
|
||||
{
|
||||
return getUserAlreadyFromSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout()
|
||||
{
|
||||
deleteUserFromSession();
|
||||
}
|
||||
|
||||
private UserDTO getUserAlreadyFromSession()
|
||||
{
|
||||
UserDTO user = null;
|
||||
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
Object userObj = session.getAttribute("user");
|
||||
if (userObj != null && userObj instanceof UserDTO)
|
||||
{
|
||||
user = (UserDTO) userObj;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private void storeUserInSession(UserDTO user)
|
||||
{
|
||||
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
|
||||
HttpSession session = httpServletRequest.getSession(true);
|
||||
user.setSessionId(session.getId());
|
||||
session.setAttribute("user", user);
|
||||
}
|
||||
|
||||
private void deleteUserFromSession()
|
||||
{
|
||||
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
session.removeAttribute("user");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user