NIHVIVO-2279 Remove username from LoginStatusBean

This commit is contained in:
j2blake 2011-06-06 15:47:56 +00:00
parent ccb6cc549d
commit 6f67a4da86
7 changed files with 54 additions and 57 deletions

View file

@ -22,7 +22,7 @@ public class LoginStatusBean {
/** A bean to return when the user has not logged in. */
private static final LoginStatusBean DUMMY_BEAN = new LoginStatusBean("",
"", AuthenticationSource.UNKNOWN);
AuthenticationSource.UNKNOWN);
/** The bean is attached to the session by this name. */
private static final String ATTRIBUTE_NAME = "loginStatus";
@ -96,17 +96,26 @@ public class LoginStatusBean {
return null;
}
if (!getBean(session).isLoggedIn()) {
return null;
}
ServletContext ctx = session.getServletContext();
WebappDaoFactory wadf = (WebappDaoFactory) ctx
.getAttribute("webappDaoFactory");
UserDao userDao = wadf.getUserDao();
if (getBean(session).isLoggedIn()) {
String userUri = getBean(session).getUserURI();
return userDao.getUserByURI(userUri);
} else {
if (wadf == null) {
log.error("No WebappDaoFactory");
return null;
}
UserDao userDao = wadf.getUserDao();
if (userDao == null) {
log.error("No UserDao");
return null;
}
String userUri = getBean(session).getUserURI();
return userDao.getUserByURI(userUri);
}
// ----------------------------------------------------------------------
@ -118,13 +127,11 @@ public class LoginStatusBean {
}
private final String userURI;
private final String username;
private final AuthenticationSource authenticationSource;
public LoginStatusBean(String userURI, String username,
public LoginStatusBean(String userURI,
AuthenticationSource authenticationSource) {
this.userURI = userURI;
this.username = username;
this.authenticationSource = authenticationSource;
}
@ -132,10 +139,6 @@ public class LoginStatusBean {
return userURI;
}
public String getUsername() {
return username;
}
public AuthenticationSource getAuthenticationSource() {
return authenticationSource;
}
@ -150,8 +153,8 @@ public class LoginStatusBean {
@Override
public String toString() {
return "LoginStatusBean[userURI=" + userURI + ", username=" + username
+ ", authenticationSource=" + authenticationSource + "]";
return "LoginStatusBean[userURI=" + userURI + ", authenticationSource="
+ authenticationSource + "]";
}
}

View file

@ -11,7 +11,6 @@ import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -23,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundleFactory;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.User;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -104,18 +104,12 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
HttpServletRequest req) {
Collection<Individual> individuals = new ArrayList<Individual>();
LoginStatusBean bean = LoginStatusBean.getBean(req);
String username = bean.getUsername();
if (!bean.isLoggedIn()) {
User user = LoginStatusBean.getCurrentUser(req);
if (user == null) {
log.debug("No Associated Individuals: not logged in.");
return individuals;
}
if (StringUtils.isEmpty(username)) {
log.debug("No Associated Individuals: username is empty.");
return individuals;
}
String username = user.getUsername();
WebappDaoFactory wdf = (WebappDaoFactory) context
.getAttribute("webappDaoFactory");
@ -150,5 +144,5 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
public String toString() {
return this.getClass().getSimpleName() + " - " + hashCode();
}
}

View file

@ -102,20 +102,20 @@ public class BasicAuthenticator extends Authenticator {
recordLoginOnUserRecord(user);
String userUri = user.getURI();
recordLoginWithOrWithoutUserAccount(username, userUri, authSource);
recordLoginWithOrWithoutUserAccount(userUri, authSource);
}
@Override
public void recordLoginWithoutUserAccount(String username,
String individualUri, AuthenticationSource authSource) {
recordLoginWithOrWithoutUserAccount(username, individualUri, authSource);
recordLoginWithOrWithoutUserAccount(individualUri, authSource);
}
/** This much is in common on login, whether or not you have a user account. */
private void recordLoginWithOrWithoutUserAccount(String username,
String userUri, AuthenticationSource authSource) {
private void recordLoginWithOrWithoutUserAccount(String userUri,
AuthenticationSource authSource) {
HttpSession session = request.getSession();
createLoginStatusBean(username, userUri, authSource, session);
createLoginStatusBean(userUri, authSource, session);
setSessionTimeoutLimit(session);
recordInUserSessionMap(userUri, session);
notifyOtherUsers(userUri, session);
@ -135,9 +135,9 @@ public class BasicAuthenticator extends Authenticator {
/**
* Put the login bean into the session.
*/
private void createLoginStatusBean(String username, String userUri,
private void createLoginStatusBean(String userUri,
AuthenticationSource authSource, HttpSession session) {
LoginStatusBean lsb = new LoginStatusBean(userUri, username, authSource);
LoginStatusBean lsb = new LoginStatusBean(userUri, authSource);
LoginStatusBean.setBean(session, lsb);
log.debug("Adding status bean: " + lsb);
}
@ -243,10 +243,10 @@ public class BasicAuthenticator extends Authenticator {
return;
}
String username = loginBean.getUsername();
User user = userDao.getUserByUsername(username);
String userUri = loginBean.getUserURI();
User user = userDao.getUserByURI(userUri);
if (user == null) {
log.error("Unable to retrieve user " + username + " from model");
log.error("Unable to retrieve user " + userUri + " from model");
return;
}

View file

@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -20,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage;
import edu.cornell.mannlib.vitro.webapp.beans.User;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
import freemarker.template.utility.StringUtil;
/**
* A user has just completed the login process. What page do we direct them to?
@ -49,11 +51,12 @@ public class LoginRedirector {
/** Is there an Individual associated with this user? */
private String getAssociatedIndividualUri() {
String username = LoginStatusBean.getBean(request).getUsername();
if (username == null) {
User user = LoginStatusBean.getCurrentUser(request);
if (user == null) {
log.warn("Not logged in? How did we get here?");
return null;
}
String username = user.getUsername();
List<String> uris = Authenticator.getInstance(request)
.getAssociatedIndividualUris(username);
@ -105,19 +108,17 @@ public class LoginRedirector {
+ "but the system contains no profile for you.";
}
LoginStatusBean bean = LoginStatusBean.getBean(request);
Authenticator auth = Authenticator.getInstance(request);
User user = auth.getUserByUsername(bean.getUsername());
String backString = "";
String greeting = bean.getUsername();
String greeting = "";
User user = LoginStatusBean.getCurrentUser(request);
if (user != null) {
greeting = user.getUsername();
if (user.getLoginCount() > 1) {
backString = " back";
}
String name = user.getFirstName();
if ((name != null) && (name.length() > 0)) {
if (!StringUtils.isEmpty(name)) {
greeting = name;
}
}