NIHVIVO-2279 Start transitioning toward UserAccount
This commit is contained in:
parent
d113061b91
commit
dbf7f5b809
2 changed files with 45 additions and 27 deletions
|
@ -2,12 +2,17 @@
|
|||
|
||||
package edu.cornell.mannlib.vedit.beans;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
* An immutable object that records the user's login info as a session
|
||||
* attribute.
|
||||
|
@ -91,6 +96,33 @@ public class LoginStatusBean {
|
|||
return (LoginStatusBean) o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user, or null if not logged in.
|
||||
*/
|
||||
public static User getCurrentUser(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
return getCurrentUser(request.getSession(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user, or null if not logged in.
|
||||
*/
|
||||
public static User getCurrentUser(HttpSession session) {
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ServletContext ctx = session.getServletContext();
|
||||
WebappDaoFactory wadf = (WebappDaoFactory) ctx
|
||||
.getAttribute("webappDaoFactory");
|
||||
UserDao userDao = wadf.getUserDao();
|
||||
|
||||
String userUri = getBean(session).getUserURI();
|
||||
return userDao.getUserByURI(userUri);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// the bean
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -129,7 +161,7 @@ public class LoginStatusBean {
|
|||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return securityLevel > ANYBODY;
|
||||
return authenticationSource != AuthenticationSource.UNKNOWN;
|
||||
}
|
||||
|
||||
public boolean isLoggedInExactly(int level) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue