diff --git a/webapp/src/edu/cornell/mannlib/vedit/beans/LoginStatusBean.java b/webapp/src/edu/cornell/mannlib/vedit/beans/LoginStatusBean.java index 7f1fd9eee..318089279 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/beans/LoginStatusBean.java +++ b/webapp/src/edu/cornell/mannlib/vedit/beans/LoginStatusBean.java @@ -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) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java index 63459d849..3f0cfe775 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java @@ -2,48 +2,34 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; -import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.RevisionInfoController; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.SiteAdminController; public class User extends BaseTemplateModel { - - private static final Log log = LogFactory.getLog(User.class); - - private enum Access { - FILTER_SECURITY(LoginStatusBean.EDITOR); - - private final int requiredLoginLevel; - - Access(int requiredLoginLevel) { - this.requiredLoginLevel = requiredLoginLevel; - } - - int requiredLoginLevel() { - return this.requiredLoginLevel; - } - } - - private LoginStatusBean loginBean = null; - private VitroRequest vreq = null; + private final VitroRequest vreq; + + // TODO JB Modify this to use UserAccount instead of User. + private final edu.cornell.mannlib.vitro.webapp.beans.User currentUser; public User(VitroRequest vreq) { this.vreq = vreq; - loginBean = LoginStatusBean.getBean(vreq); + this.currentUser = LoginStatusBean.getCurrentUser(vreq); } public boolean isLoggedIn() { - return loginBean.isLoggedIn(); + return currentUser != null; + } + + public String getEmailAddress() { + return (currentUser == null) ? "" : currentUser.getUsername(); } public String getLoginName() { - return loginBean.getUsername(); + return (currentUser == null) ? "" + : (currentUser.getFirstName() + " " + currentUser.getLastName()); } public boolean getHasSiteAdminAccess() {