//hostadmiral/trunk/src/ak/hostadmiral/core/action/LoginAction.java |
---|
18,6 → 18,7 |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.LoginInfo; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class LoginAction |
48,6 → 49,8 |
} |
else { |
request.getSession().setAttribute(SessionKeys.USER, user); |
request.getSession().setAttribute(SessionKeys.LOGIN_INFO, |
new LoginInfo(user.getId())); |
request.getSession().setAttribute(Globals.LOCALE_KEY, user.getLocale()); |
String origin = BackPath.findBackPath(request).getBackwardUrl(); |
//hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java |
---|
72,6 → 72,12 |
return user; |
} |
public User get(Long id) |
throws ModelException |
{ |
return store.get(id); |
} |
public boolean loginExists(User editor, User user, String login) |
throws ModelException |
{ |
//hostadmiral/trunk/src/ak/hostadmiral/core/servlet/LoginFilter.java |
---|
22,7 → 22,10 |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.core.servlet.LoginInfo; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
/** |
* Ensures that user is logged in to the system to process its request. |
127,16 → 130,40 |
throw new AccessControlException("No session"); |
Object userObj = session.getAttribute(SessionKeys.USER); |
if(userObj == null) { |
// try to relogin |
Object loginInfoObj = session.getAttribute(SessionKeys.LOGIN_INFO); |
if(loginInfoObj == null) |
throw new AccessControlException("No user"); |
if(!(loginInfoObj instanceof LoginInfo)) |
throw new ServletException( |
"Wrong type of login info information: " |
+ loginInfoObj.getClass().getName()); |
try { |
userObj = UserManager.getInstance().get(((LoginInfo)loginInfoObj).getId()); |
} |
catch(ModelException ex) { |
throw new AccessControlException("No user"); |
} |
if(userObj == null) |
throw new AccessControlException("No user"); |
session.setAttribute(SessionKeys.USER, userObj); |
logger.debug("User re-logined: " + userObj); |
} |
else { |
if(!(userObj instanceof User)) |
throw new ServletException( |
"Wrong type of user information: " + userObj.getClass().getName()); |
processNext = true; |
logger.debug("User found - OK"); |
} |
processNext = true; |
} |
catch(AccessControlException ex) { |
String redirectUrl; |
try { |
//hostadmiral/trunk/src/ak/hostadmiral/core/servlet/SessionKeys.java |
---|
3,4 → 3,5 |
public abstract class SessionKeys |
{ |
public static final String USER = "user"; |
public static final String LOGIN_INFO = LoginInfo.class.getName(); |
} |
//hostadmiral/trunk/src/ak/hostadmiral/core/servlet/LoginInfo.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.servlet; |
import java.io.Serializable; |
public class LoginInfo |
implements Serializable |
{ |
private Long id; |
public LoginInfo(Long id) |
{ |
this.id = id; |
} |
public Long getId() |
{ |
return id; |
} |
} |