getAssociatedIndividualUris(
+ UserAccount userAccount);
/**
*
@@ -97,7 +102,7 @@ public abstract class Authenticator {
* - notify other users of the model
*
*/
- public abstract void recordLoginAgainstUserAccount(String username,
+ public abstract void recordLoginAgainstUserAccount(UserAccount userAccount,
AuthenticationSource authSource);
/**
@@ -106,9 +111,10 @@ public abstract class Authenticator {
* info, so no internal user account.
* - this involves everything except updating the user record.
*
+ *
+ * TODO JB This goes away.
*/
- public abstract void recordLoginWithoutUserAccount(String username,
- String individualUri, AuthenticationSource authSource);
+ public abstract void recordLoginWithoutUserAccount(String individualUri);
/**
*
@@ -140,4 +146,30 @@ public abstract class Authenticator {
}
}
+ /**
+ * Check whether the form of the emailAddress is syntactically correct. Does
+ * not allow multiple addresses. Does not allow local addresses (without a
+ * hostname).
+ *
+ * Does not confirm that the host actually exists, or has a mailbox by that
+ * name.
+ */
+ public static boolean isValidEmailAddress(String emailAddress) {
+ try {
+ // InternetAddress constructor will throw an exception if the
+ // address does not have valid format (if "strict" is true).
+ @SuppressWarnings("unused")
+ InternetAddress a = new InternetAddress(emailAddress, true);
+
+ // InternetAddress permits a localname without hostname.
+ // Guard against that.
+ if (emailAddress.indexOf('@') == -1) {
+ return false;
+ }
+
+ return true;
+ } catch (AddressException e) {
+ return false;
+ }
+ }
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java
index a24f5bf45..2135f007f 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java
@@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -15,15 +14,15 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
-import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole;
+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.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
-import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
+import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.LogoutEvent;
@@ -32,9 +31,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.LogoutEvent;
* The "standard" implementation of Authenticator.
*/
public class BasicAuthenticator extends Authenticator {
- /** User roles are recorded in the model like "role:/50", etc. */
- private static final String ROLE_NAMESPACE = "role:/";
-
private static final Log log = LogFactory.getLog(BasicAuthenticator.class);
private final HttpServletRequest request;
@@ -44,91 +40,104 @@ public class BasicAuthenticator extends Authenticator {
}
@Override
- public boolean isExistingUser(String username) {
- return getUserByUsername(username) != null;
- }
-
- @Override
- public User getUserByUsername(String username) {
- UserDao userDao = getUserDao();
- if (userDao == null) {
+ public UserAccount getAccountForInternalAuth(String emailAddress) {
+ UserAccountsDao userAccountsDao = getUserAccountsDao();
+ if (userAccountsDao == null) {
return null;
}
- return userDao.getUserByUsername(username);
+ return userAccountsDao.getUserAccountByEmail(emailAddress);
}
@Override
- public boolean isCurrentPassword(String username, String clearTextPassword) {
- User user = getUserDao().getUserByUsername(username);
- if (user == null) {
- log.trace("Checking password '" + clearTextPassword
- + "' for user '" + username + "', but user doesn't exist.");
+ public UserAccount getAccountForExternalAuth(String externalAuthId) {
+ UserAccountsDao userAccountsDao = getUserAccountsDao();
+ if (userAccountsDao == null) {
+ return null;
+ }
+ return userAccountsDao.getUserAccountByExternalAuthId(externalAuthId);
+ }
+
+ @Override
+ public boolean isCurrentPassword(UserAccount userAccount,
+ String clearTextPassword) {
+ if (userAccount == null) {
return false;
}
-
- String md5NewPassword = applyMd5Encoding(clearTextPassword);
- return md5NewPassword.equals(user.getMd5password());
+ if (clearTextPassword == null) {
+ return false;
+ }
+ String encodedPassword = applyMd5Encoding(clearTextPassword);
+ return encodedPassword.equals(userAccount.getMd5Password());
}
@Override
- public boolean isPasswordChangeRequired(String username) {
- User user = getUserDao().getUserByUsername(username);
- if ((user != null) && (user.getLoginCount() == 0)) {
+ public void recordNewPassword(UserAccount userAccount,
+ String newClearTextPassword) {
+ if (userAccount == null) {
+ log.error("Trying to change password on null user.");
+ return;
+ }
+ userAccount.setMd5Password(applyMd5Encoding(newClearTextPassword));
+ userAccount.setPasswordChangeRequired(false);
+ userAccount.setPasswordLinkExpires(0L);
+ getUserAccountsDao().updateUserAccount(userAccount);
+ }
+
+ @Override
+ public boolean accountRequiresEditing(UserAccount userAccount) {
+ if (userAccount == null) {
+ log.error("Trying to check for valid fields on a null user.");
+ return false;
+ }
+ if (userAccount.getFirstName().isEmpty()) {
return true;
- } else {
- return false;
}
+ if (userAccount.getLastName().isEmpty()) {
+ return true;
+ }
+ if (userAccount.getEmailAddress().isEmpty()) {
+ return true;
+ }
+ if (!isValidEmailAddress(userAccount.getEmailAddress())) {
+ return true;
+ }
+ return false;
}
@Override
- public void recordNewPassword(String username, String newClearTextPassword) {
- User user = getUserByUsername(username);
- if (user == null) {
- log.error("Trying to change password on non-existent user: "
- + username);
- return;
+ public List getAssociatedIndividualUris(UserAccount userAccount) {
+ List uris = new ArrayList();
+ if (userAccount == null) {
+ return uris;
}
- user.setOldPassword(user.getMd5password());
- user.setMd5password(applyMd5Encoding(newClearTextPassword));
- getUserDao().updateUser(user);
+ uris.addAll(getUrisAssociatedBySelfEditorConfig(userAccount));
+ return uris;
}
@Override
- public void recordLoginAgainstUserAccount(String username,
+ public void recordLoginAgainstUserAccount(UserAccount userAccount,
AuthenticationSource authSource) {
- User user = getUserByUsername(username);
- if (user == null) {
- log.error("Trying to record the login of a non-existent user: "
- + username);
+ if (userAccount == null) {
+ log.error("Trying to record the login of a null user. ");
return;
}
- recordLoginOnUserRecord(user);
-
- String userUri = user.getURI();
- String roleUri = user.getRoleURI();
- int securityLevel = parseUserSecurityLevel(user);
- recordLoginWithOrWithoutUserAccount(username, userUri, roleUri,
- securityLevel, authSource);
+ recordLoginOnUserRecord(userAccount);
+ recordLoginWithOrWithoutUserAccount(userAccount.getUri(), authSource);
}
+ // TODO JB This goes away.
@Override
- public void recordLoginWithoutUserAccount(String username,
- String individualUri, AuthenticationSource authSource) {
- String roleUri = AuthRole.USER.roleUri();
- int securityLevel = LoginStatusBean.NON_EDITOR;
- recordLoginWithOrWithoutUserAccount(username, individualUri, roleUri,
- securityLevel, authSource);
+ public void recordLoginWithoutUserAccount(String individualUri) {
+ recordLoginWithOrWithoutUserAccount(individualUri,
+ AuthenticationSource.EXTERNAL);
}
/** This much is in common on login, whether or not you have a user account. */
- private void recordLoginWithOrWithoutUserAccount(String username,
- String userUri, String roleUri, int securityLevel,
+ private void recordLoginWithOrWithoutUserAccount(String userUri,
AuthenticationSource authSource) {
HttpSession session = request.getSession();
- createLoginFormBean(username, userUri, roleUri, session);
- createLoginStatusBean(username, userUri, securityLevel, authSource,
- session);
+ createLoginStatusBean(userUri, authSource, session);
setSessionTimeoutLimit(session);
recordInUserSessionMap(userUri, session);
notifyOtherUsers(userUri, session);
@@ -137,41 +146,17 @@ public class BasicAuthenticator extends Authenticator {
/**
* Update the user record to record the login.
*/
- private void recordLoginOnUserRecord(User user) {
- user.setLoginCount(user.getLoginCount() + 1);
- if (user.getFirstTime() == null) { // first login
- user.setFirstTime(new Date());
- }
- getUserDao().updateUser(user);
+ private void recordLoginOnUserRecord(UserAccount userAccount) {
+ userAccount.setLoginCount(userAccount.getLoginCount() + 1);
+ getUserAccountsDao().updateUserAccount(userAccount);
}
/**
* Put the login bean into the session.
- *
- * TODO The LoginFormBean is being phased out.
*/
- private void createLoginFormBean(String username, String userUri,
- String roleUri, HttpSession session) {
- LoginFormBean lfb = new LoginFormBean();
- lfb.setUserURI(userUri);
- lfb.setLoginStatus("authenticated");
- lfb.setSessionId(session.getId());
- lfb.setLoginRole(roleUri);
- lfb.setLoginRemoteAddr(request.getRemoteAddr());
- lfb.setLoginName(username);
- session.setAttribute("loginHandler", lfb);
- }
-
- /**
- * Put the login bean into the session.
- *
- * TODO this should eventually replace the LoginFormBean.
- */
- private void createLoginStatusBean(String username, String userUri,
- int securityLevel, AuthenticationSource authSource,
- HttpSession session) {
- LoginStatusBean lsb = new LoginStatusBean(userUri, username,
- securityLevel, authSource);
+ private void createLoginStatusBean(String userUri,
+ AuthenticationSource authSource, HttpSession session) {
+ LoginStatusBean lsb = new LoginStatusBean(userUri, authSource);
LoginStatusBean.setBean(session, lsb);
log.debug("Adding status bean: " + lsb);
}
@@ -180,8 +165,9 @@ public class BasicAuthenticator extends Authenticator {
* Editors and other privileged users get a longer timeout interval.
*/
private void setSessionTimeoutLimit(HttpSession session) {
- if (LoginStatusBean.getBean(session).isLoggedInAtLeast(
- LoginStatusBean.EDITOR)) {
+ RoleLevel role = RoleLevel.getRoleFromLoginStatus(request);
+ if (role == RoleLevel.EDITOR || role == RoleLevel.CURATOR
+ || role == RoleLevel.DB_ADMIN) {
session.setMaxInactiveInterval(PRIVILEGED_TIMEOUT_INTERVAL);
} else {
session.setMaxInactiveInterval(LOGGED_IN_TIMEOUT_INTERVAL);
@@ -208,54 +194,23 @@ public class BasicAuthenticator extends Authenticator {
session.getServletContext(), session);
}
- @Override
- public List getAssociatedIndividualUris(String username) {
+ private List getUrisAssociatedBySelfEditorConfig(UserAccount user) {
List uris = new ArrayList();
- uris.addAll(getUrisAssociatedBySelfEditorConfig(username));
- uris.addAll(getUrisAssociatedByMayEditAs(username));
- return uris;
- }
-
- private List getUrisAssociatedBySelfEditorConfig(String username) {
- if (username == null) {
- return Collections.emptyList();
+ if (user == null) {
+ return uris;
}
IndividualDao iDao = getIndividualDao();
if (iDao == null) {
- return Collections.emptyList();
+ return uris;
}
- String selfEditorUri = SelfEditingConfiguration.getBean(request)
- .getIndividualUriFromUsername(iDao, username);
- if (selfEditorUri == null) {
- return Collections.emptyList();
- } else {
- return Collections.singletonList(selfEditorUri);
+ List associatedIndividuals = SelfEditingConfiguration
+ .getBean(request).getAssociatedIndividuals(iDao, user);
+ for (Individual ind : associatedIndividuals) {
+ uris.add(ind.getURI());
}
- }
-
- private List getUrisAssociatedByMayEditAs(String username) {
- if (username == null) {
- return Collections.emptyList();
- }
-
- UserDao userDao = getUserDao();
- if (userDao == null) {
- return Collections.emptyList();
- }
-
- User user = userDao.getUserByUsername(username);
- if (user == null) {
- return Collections.emptyList();
- }
-
- String userUri = user.getURI();
- if (userUri == null) {
- return Collections.emptyList();
- }
-
- return userDao.getIndividualsUserMayEditAs(userUri);
+ return uris;
}
@Override
@@ -266,42 +221,30 @@ public class BasicAuthenticator extends Authenticator {
}
private void notifyOtherUsersOfLogout(HttpSession session) {
- LoginStatusBean loginBean = LoginStatusBean.getBean(session);
- if (!loginBean.isLoggedIn()) {
+ String userUri = LoginStatusBean.getBean(session).getUserURI();
+ if ((userUri == null) || userUri.isEmpty()) {
return;
}
- UserDao userDao = getUserDao();
- if (userDao == null) {
- return;
- }
-
- String username = loginBean.getUsername();
- User user = userDao.getUserByUsername(username);
- if (user == null) {
- log.error("Unable to retrieve user " + username + " from model");
- return;
- }
-
- Authenticate.sendLoginNotifyEvent(new LogoutEvent(user.getURI()),
+ Authenticate.sendLoginNotifyEvent(new LogoutEvent(userUri),
session.getServletContext(), session);
}
/**
- * Get a reference to the UserDao, or null.
+ * Get a reference to the UserAccountsDao, or null.
*/
- private UserDao getUserDao() {
+ private UserAccountsDao getUserAccountsDao() {
WebappDaoFactory wadf = getWebappDaoFactory();
if (wadf == null) {
return null;
}
- UserDao userDao = wadf.getUserDao();
- if (userDao == null) {
- log.error("getUserDao: no UserDao");
+ UserAccountsDao userAccountsDao = wadf.getUserAccountsDao();
+ if (userAccountsDao == null) {
+ log.error("getUserAccountsDao: no UserAccountsDao");
}
- return userDao;
+ return userAccountsDao;
}
/**
@@ -341,23 +284,4 @@ public class BasicAuthenticator extends Authenticator {
return wadf;
}
- /**
- * Parse the role URI from User. Don't crash if it is not valid.
- */
- private int parseUserSecurityLevel(User user) {
- String roleURI = user.getRoleURI();
- try {
- if (roleURI.startsWith(ROLE_NAMESPACE)) {
- String roleLevel = roleURI.substring(ROLE_NAMESPACE.length());
- return Integer.parseInt(roleLevel);
- } else {
- return Integer.parseInt(roleURI);
- }
- } catch (NumberFormatException e) {
- log.warn("Invalid RoleURI '" + roleURI + "' for user '"
- + user.getURI() + "'");
- return 1;
- }
- }
-
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ExternalAuthHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ExternalAuthHelper.java
index 481649ddd..74168a2a3 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ExternalAuthHelper.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ExternalAuthHelper.java
@@ -34,8 +34,8 @@ public class ExternalAuthHelper {
/** This configuration property points to the external authorization server. */
private static final String PROPERTY_EXTERNAL_AUTH_SERVER_URL = "externalAuth.serverUrl";
- /** This configuration property says which HTTP header holds the username. */
- public static final String PROPERTY_EXTERNAL_AUTH_USERNAME_HEADER = "externalAuth.netIdHeaderName";
+ /** This configuration property says which HTTP header holds the auth ID. */
+ public static final String PROPERTY_EXTERNAL_AUTH_ID_HEADER = "externalAuth.netIdHeaderName";
// ----------------------------------------------------------------------
// static methods
@@ -82,7 +82,7 @@ public class ExternalAuthHelper {
String externalAuthServerUrl = ConfigurationProperties.getBean(ctx)
.getProperty(PROPERTY_EXTERNAL_AUTH_SERVER_URL);
String externalAuthHeaderName = ConfigurationProperties.getBean(ctx)
- .getProperty(PROPERTY_EXTERNAL_AUTH_USERNAME_HEADER);
+ .getProperty(PROPERTY_EXTERNAL_AUTH_ID_HEADER);
return new ExternalAuthHelper(externalAuthServerUrl,
externalAuthHeaderName);
@@ -134,7 +134,7 @@ public class ExternalAuthHelper {
}
}
- public String getExternalUsername(HttpServletRequest request) {
+ public String getExternalAuthId(HttpServletRequest request) {
if (request == null) {
log.error("request is null.");
return null;
@@ -143,13 +143,13 @@ public class ExternalAuthHelper {
if (externalAuthHeaderName == null) {
log.error("User asked for external authentication, "
+ "but deploy.properties doesn't contain a value for '"
- + PROPERTY_EXTERNAL_AUTH_USERNAME_HEADER + "'");
+ + PROPERTY_EXTERNAL_AUTH_ID_HEADER + "'");
return null;
}
- String username = request.getHeader(externalAuthHeaderName);
- log.debug("username=" + username);
- return username;
+ String externalAuthId = request.getHeader(externalAuthHeaderName);
+ log.debug("externalAuthId=" + externalAuthId);
+ return externalAuthId;
}
@Override
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/FakeExternalAuthController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/FakeExternalAuthController.java
index 829209ee1..fd1efd039 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/FakeExternalAuthController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/FakeExternalAuthController.java
@@ -117,7 +117,7 @@ public class FakeExternalAuthController extends FreemarkerHttpServlet {
}
@Override
- public String getExternalUsername(HttpServletRequest request) {
+ public String getExternalAuthId(HttpServletRequest request) {
log.debug("external username is '" + username + "'");
return username;
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthReturn.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthReturn.java
index 085005edd..b4eca1079 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthReturn.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthReturn.java
@@ -15,6 +15,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
+import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
/**
* Handle the return from the external authorization login server. If we are
@@ -40,36 +41,44 @@ public class LoginExternalAuthReturn extends BaseLoginServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
- String username = ExternalAuthHelper.getHelper(req)
- .getExternalUsername(req);
- List associatedUris = getAuthenticator(req)
- .getAssociatedIndividualUris(username);
-
- if (username == null) {
- log.debug("No username.");
+ String externalAuthId = ExternalAuthHelper.getHelper(req)
+ .getExternalAuthId(req);
+ if (externalAuthId == null) {
+ log.debug("No externalAuthId.");
complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER,
MESSAGE_LOGIN_FAILED);
- } else if (getAuthenticator(req).isExistingUser(username)) {
- log.debug("Logging in as " + username);
- getAuthenticator(req).recordLoginAgainstUserAccount(username,
+ return;
+ }
+
+ UserAccount userAccount = getAuthenticator(req)
+ .getAccountForExternalAuth(externalAuthId);
+ if (userAccount != null) {
+ log.debug("Logging in as " + userAccount.getUri());
+ getAuthenticator(req).recordLoginAgainstUserAccount(userAccount,
AuthenticationSource.EXTERNAL);
removeLoginProcessArtifacts(req);
new LoginRedirector(req, resp).redirectLoggedInUser();
- } else if (!associatedUris.isEmpty()) {
- log.debug("Recognize '" + username + "' as self-editor for "
+ return;
+ }
+
+ List associatedUris = getAuthenticator(req)
+ .getAssociatedIndividualUris(userAccount);
+ // TODO JB - this case should lead to creating a new account.
+ if (!associatedUris.isEmpty()) {
+ log.debug("Recognize '" + externalAuthId + "' as self-editor for "
+ associatedUris);
String uri = associatedUris.get(0);
- getAuthenticator(req).recordLoginWithoutUserAccount(username, uri,
- AuthenticationSource.EXTERNAL);
+ getAuthenticator(req).recordLoginWithoutUserAccount(uri);
removeLoginProcessArtifacts(req);
new LoginRedirector(req, resp).redirectLoggedInUser();
- } else {
- log.debug("User is not recognized: " + username);
- removeLoginProcessArtifacts(req);
- new LoginRedirector(req, resp)
- .redirectUnrecognizedExternalUser(username);
+ return;
}
+
+ log.debug("User is not recognized: " + externalAuthId);
+ removeLoginProcessArtifacts(req);
+ new LoginRedirector(req, resp)
+ .redirectUnrecognizedExternalUser(externalAuthId);
}
private void removeLoginProcessArtifacts(HttpServletRequest req) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalNewAccount.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalNewAccount.java
new file mode 100644
index 000000000..22d5a73f3
--- /dev/null
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalNewAccount.java
@@ -0,0 +1,24 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
+
+import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
+
+/**
+ * Handle the first login from an external authentication.
+ */
+public class LoginExternalNewAccount extends FreemarkerHttpServlet {
+
+ @Override
+ protected ResponseValues processRequest(VitroRequest vreq) {
+ String externalAuthId = ExternalAuthHelper.getHelper(vreq)
+ .getExternalAuthId(vreq);
+
+ // TODO Auto-generated method stub
+ throw new RuntimeException(
+ "LoginExternalNewAccount.processRequest() not implemented.");
+ }
+
+}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRedirector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRedirector.java
index 9e019d81e..d0746ad92 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRedirector.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRedirector.java
@@ -11,12 +11,14 @@ 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;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
+import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage;
-import edu.cornell.mannlib.vitro.webapp.beans.User;
+import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
@@ -48,22 +50,22 @@ public class LoginRedirector {
/** Is there an Individual associated with this user? */
private String getAssociatedIndividualUri() {
- String username = LoginStatusBean.getBean(request).getUsername();
- if (username == null) {
- log.warn("Not logged in? How did we get here?");
+ UserAccount userAccount = LoginStatusBean.getCurrentUser(request);
+ if (userAccount == null) {
+ log.debug("Not logged in? Must be cancelling the password change");
return null;
}
List uris = Authenticator.getInstance(request)
- .getAssociatedIndividualUris(username);
+ .getAssociatedIndividualUris(userAccount);
if (uris.isEmpty()) {
- log.debug("'" + username
+ log.debug("'" + userAccount.getEmailAddress()
+ "' is not associated with an individual.");
return null;
} else {
String uri = uris.get(0);
- log.debug("'" + username + "' is associated with an individual: "
- + uri);
+ log.debug("'" + userAccount.getEmailAddress()
+ + "' is associated with an individual: " + uri);
return uri;
}
}
@@ -104,19 +106,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 = "";
- if (user != null) {
- if (user.getLoginCount() > 1) {
+ UserAccount userAccount = LoginStatusBean.getCurrentUser(request);
+ if (userAccount != null) {
+ greeting = userAccount.getEmailAddress();
+ if (userAccount.getLoginCount() > 1) {
backString = " back";
}
- String name = user.getFirstName();
- if ((name != null) && (name.length() > 0)) {
+ String name = userAccount.getFirstName();
+ if (!StringUtils.isEmpty(name)) {
greeting = name;
}
}
@@ -152,8 +152,8 @@ public class LoginRedirector {
}
private boolean isMerelySelfEditor() {
- return LoginStatusBean.getBean(session).isLoggedInExactly(
- LoginStatusBean.NON_EDITOR);
+ RoleLevel role = RoleLevel.getRoleFromLoginStatus(request);
+ return role == RoleLevel.PUBLIC || role == RoleLevel.SELF;
}
private boolean isLoginPage(String page) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRepairAccountInfo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRepairAccountInfo.java
new file mode 100644
index 000000000..cf0633e15
--- /dev/null
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginRepairAccountInfo.java
@@ -0,0 +1,20 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
+
+import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
+
+/**
+ * TODO
+ */
+public class LoginRepairAccountInfo extends FreemarkerHttpServlet {
+
+ @Override
+ protected ResponseValues processRequest(VitroRequest vreq) {
+ // TODO Auto-generated method stub
+ throw new RuntimeException("LoginRepairAccountInfo.processRequest() not implemented.");
+ }
+
+}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ProgramLogin.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ProgramLogin.java
index a7cadb1f4..bdaef9162 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ProgramLogin.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/ProgramLogin.java
@@ -3,8 +3,8 @@
package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.INTERNAL;
-import static edu.cornell.mannlib.vitro.webapp.beans.User.MAX_PASSWORD_LENGTH;
-import static edu.cornell.mannlib.vitro.webapp.beans.User.MIN_PASSWORD_LENGTH;
+import static edu.cornell.mannlib.vitro.webapp.beans.UserAccount.MAX_PASSWORD_LENGTH;
+import static edu.cornell.mannlib.vitro.webapp.beans.UserAccount.MIN_PASSWORD_LENGTH;
import java.io.IOException;
import java.io.PrintWriter;
@@ -14,13 +14,18 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import edu.cornell.mannlib.vitro.webapp.beans.User;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
/**
* Provide a means for programmatic login If they provide the right parameters,
* log them in and send 200. Otherwise, send 403 error.
*/
public class ProgramLogin extends HttpServlet {
+ private static final Log log = LogFactory.getLog(ProgramLogin.class);
+
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -34,16 +39,16 @@ public class ProgramLogin extends HttpServlet {
}
static class ProgramLoginCore {
- public static final String PARAM_USERNAME = "username";
+ public static final String PARAM_EMAIL_ADDRESS = "email";
public static final String PARAM_PASSWORD = "password";
public static final String PARAM_NEW_PASSWORD = "newPassword";
public static final int ERROR_CODE = 403;
- private static final String MESSAGE_NEED_USERNAME = PARAM_USERNAME
+ private static final String MESSAGE_NEED_EMAIL_ADDRESS = PARAM_EMAIL_ADDRESS
+ " parameter is required.";
private static final String MESSAGE_NEED_PASSWORD = PARAM_PASSWORD
+ " parameter is required.";
- private static final String MESSAGE_WRONG_USER_OR_PASSWORD = PARAM_USERNAME
+ private static final String MESSAGE_WRONG_USER_OR_PASSWORD = PARAM_EMAIL_ADDRESS
+ " or " + PARAM_PASSWORD + " is incorrect.";
private static final String MESSAGE_NEED_NEW_PASSWORD = "first-time login: "
+ PARAM_NEW_PASSWORD + " parameter is required.";
@@ -63,24 +68,31 @@ public class ProgramLogin extends HttpServlet {
private final HttpServletResponse resp;
private final Authenticator auth;
- private final String username;
+ private final String emailAddress;
private final String password;
private final String newPassword;
+ private final UserAccount userAccount;
ProgramLoginCore(HttpServletRequest req, HttpServletResponse resp) {
this.req = req;
this.resp = resp;
- this.username = getParameter(PARAM_USERNAME);
+ this.emailAddress = getParameter(PARAM_EMAIL_ADDRESS);
this.password = getParameter(PARAM_PASSWORD);
this.newPassword = getParameter(PARAM_NEW_PASSWORD);
+ log.debug("request: email='" + emailAddress + "', password='"
+ + password + "', newPassword='" + newPassword + "'");
+
this.auth = Authenticator.getInstance(req);
+
+ this.userAccount = auth
+ .getAccountForInternalAuth(this.emailAddress);
}
void process() throws IOException {
- if (username.isEmpty()) {
- sendError(MESSAGE_NEED_USERNAME);
+ if (emailAddress.isEmpty()) {
+ sendError(MESSAGE_NEED_EMAIL_ADDRESS);
return;
}
if (password.isEmpty()) {
@@ -92,9 +104,7 @@ public class ProgramLogin extends HttpServlet {
return;
}
- boolean passwordChangeRequired = isFirstTimeLogin();
-
- if (!passwordChangeRequired) {
+ if (!isPasswordChangeRequired()) {
if (!newPassword.isEmpty()) {
sendError(MESSAGE_NEW_PASSWORD_NOT_NEEDED);
return;
@@ -104,7 +114,7 @@ public class ProgramLogin extends HttpServlet {
return;
}
- if (passwordChangeRequired) {
+ if (isPasswordChangeRequired()) {
if (newPassword.isEmpty()) {
sendError(MESSAGE_NEED_NEW_PASSWORD);
return;
@@ -134,8 +144,7 @@ public class ProgramLogin extends HttpServlet {
}
private boolean usernameAndPasswordAreValid() {
- return auth.isExistingUser(username)
- && auth.isCurrentPassword(username, password);
+ return auth.isCurrentPassword(userAccount, password);
}
private boolean newPasswordIsValidPasswordLength() {
@@ -147,18 +156,17 @@ public class ProgramLogin extends HttpServlet {
return newPassword.equals(password);
}
- private boolean isFirstTimeLogin() {
- User user = auth.getUserByUsername(username);
- return (user.getLoginCount() == 0);
+ private boolean isPasswordChangeRequired() {
+ return (userAccount.isPasswordChangeRequired());
}
private void recordLogin() {
- auth.recordLoginAgainstUserAccount(username, INTERNAL);
+ auth.recordLoginAgainstUserAccount(userAccount, INTERNAL);
}
private void recordLoginWithPasswordChange() {
- auth.recordNewPassword(username, newPassword);
- auth.recordLoginAgainstUserAccount(username, INTERNAL);
+ auth.recordNewPassword(userAccount, newPassword);
+ auth.recordLoginAgainstUserAccount(userAccount, INTERNAL);
}
private void sendError(String message) throws IOException {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java
index f91d3be49..232e08323 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java
@@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.controller.edit;
+import static edu.cornell.mannlib.vitro.webapp.beans.UserAccount.MAX_PASSWORD_LENGTH;
+import static edu.cornell.mannlib.vitro.webapp.beans.UserAccount.MIN_PASSWORD_LENGTH;
import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State.FORCED_PASSWORD_CHANGE;
import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State.LOGGED_IN;
import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State.LOGGING_IN;
@@ -10,8 +12,6 @@ import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
@@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.apache.commons.codec.binary.Hex;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -29,7 +28,7 @@ import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
-import edu.cornell.mannlib.vitro.webapp.beans.User;
+import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@@ -85,6 +84,7 @@ public class Authenticate extends VitroHttpServlet {
* Find out where they are in the login process, process any input, record
* the new state, and show the next page.
*/
+ @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
VitroRequest vreq = new VitroRequest(request);
@@ -313,8 +313,9 @@ public class Authenticate extends VitroHttpServlet {
bean.setUsername(username);
- User user = getAuthenticator(request).getUserByUsername(username);
- log.trace("User is " + (user == null ? "null" : user.getURI()));
+ UserAccount user = getAuthenticator(request).getAccountForInternalAuth(
+ username);
+ log.trace("User is " + (user == null ? "null" : user.getUri()));
if (user == null) {
bean.setMessage(Message.UNKNOWN_USERNAME, username);
@@ -326,16 +327,16 @@ public class Authenticate extends VitroHttpServlet {
return;
}
- if (!getAuthenticator(request).isCurrentPassword(username, password)) {
+ if (!getAuthenticator(request).isCurrentPassword(user, password)) {
bean.setMessage(Message.INCORRECT_PASSWORD);
return;
}
// Username and password are correct. What next?
- if (isFirstTimeLogin(user)) {
+ if (user.isPasswordChangeRequired()) {
transitionToForcedPasswordChange(request);
} else {
- transitionToLoggedIn(request, username);
+ transitionToLoggedIn(request, user);
}
}
@@ -374,40 +375,32 @@ public class Authenticate extends VitroHttpServlet {
return;
}
- if ((newPassword.length() < User.MIN_PASSWORD_LENGTH)
- || (newPassword.length() > User.MAX_PASSWORD_LENGTH)) {
- bean.setMessage(Message.PASSWORD_LENGTH, User.MIN_PASSWORD_LENGTH,
- User.MAX_PASSWORD_LENGTH);
+ if ((newPassword.length() < MIN_PASSWORD_LENGTH)
+ || (newPassword.length() > MAX_PASSWORD_LENGTH)) {
+ bean.setMessage(Message.PASSWORD_LENGTH, MIN_PASSWORD_LENGTH,
+ MAX_PASSWORD_LENGTH);
return;
}
String username = bean.getUsername();
- if (getAuthenticator(request).isCurrentPassword(username, newPassword)) {
+ UserAccount user = getAuthenticator(request).getAccountForInternalAuth(
+ username);
+ if (getAuthenticator(request).isCurrentPassword(user, newPassword)) {
bean.setMessage(Message.USING_OLD_PASSWORD);
return;
}
// New password is acceptable. Store it and go on.
- transitionToLoggedIn(request, username, newPassword);
+ transitionToLoggedIn(request, user, newPassword);
}
/**
- * They are already logged in. There's nothing to do; no transition.
+ * They are already logged in.
*/
@SuppressWarnings("unused")
private void processInputLoggedIn(HttpServletRequest request) {
- }
-
- /**
- * Has this user ever logged in before?
- */
- private boolean isFirstTimeLogin(User user) {
- if (user.getLoginCount() == 0) {
- return true;
- } else {
- return false;
- }
+ // Nothing to do. No transition.
}
/**
@@ -431,9 +424,9 @@ public class Authenticate extends VitroHttpServlet {
* State change: all requirements are satisfied. Log them in.
*/
private void transitionToLoggedIn(HttpServletRequest request,
- String username) {
- log.debug("Completed login: " + username);
- getAuthenticator(request).recordLoginAgainstUserAccount(username,
+ UserAccount user) {
+ log.debug("Completed login: " + user.getEmailAddress());
+ getAuthenticator(request).recordLoginAgainstUserAccount(user,
AuthenticationSource.INTERNAL);
}
@@ -442,10 +435,11 @@ public class Authenticate extends VitroHttpServlet {
* log them in.
*/
private void transitionToLoggedIn(HttpServletRequest request,
- String username, String newPassword) {
- log.debug("Completed login: " + username + ", password changed.");
- getAuthenticator(request).recordNewPassword(username, newPassword);
- getAuthenticator(request).recordLoginAgainstUserAccount(username,
+ UserAccount user, String newPassword) {
+ log.debug("Completed login: " + user.getEmailAddress()
+ + ", password changed.");
+ getAuthenticator(request).recordNewPassword(user, newPassword);
+ getAuthenticator(request).recordLoginAgainstUserAccount(user,
AuthenticationSource.INTERNAL);
}
@@ -477,7 +471,7 @@ public class Authenticate extends VitroHttpServlet {
log.debug("logging in.");
LoginInProcessFlag.set(vreq);
-
+
String loginProcessPage = LoginProcessBean.getBean(vreq)
.getLoginPageUrl();
response.sendRedirect(loginProcessPage);
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/DatapropRetryController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/DatapropRetryController.java
index 360c86b6e..ac926aa61 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/DatapropRetryController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/DatapropRetryController.java
@@ -25,6 +25,7 @@ import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vedit.validator.impl.IntValidator;
import edu.cornell.mannlib.vedit.validator.impl.XMLNameValidator;
+import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionListener;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
@@ -121,7 +122,7 @@ public class DatapropRetryController extends BaseEditController {
//set up any listeners
List changeListenerList = new ArrayList();
- //changeListenerList.add(new PropertyRestrictionListener(getServletContext()));
+ changeListenerList.add(new PropertyRestrictionListener(getServletContext()));
epo.setChangeListenerList(changeListenerList);
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java
index 338bb3bea..4c397e20e 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java
@@ -33,10 +33,9 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
+import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
-import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
-import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
@@ -507,12 +506,14 @@ public class N3MultiPartUpload extends VitroHttpServlet {
}
public void sendUserEmail(HttpServletRequest request, HttpSession session, String uploadFileName) {
- LoginStatusBean loginBean = LoginStatusBean.getBean(request);
- String userURI = loginBean.getUserURI();
+ UserAccount userAccount = LoginStatusBean.getCurrentUser(request);
+ if (userAccount == null) {
+ return;
+ }
+
try{
- System.out.println("User URI is " + userURI);
- UserDao uDao = (new VitroRequest(request)).getFullWebappDaoFactory().getUserDao();
- String email = uDao.getUserEmailAddress(userURI);
+ System.out.println("User URI is " + userAccount.getUri());
+ String email = userAccount.getEmailAddress();
String deliveryFrom = "hjk54@cornell.edu";//TO DO: replace with email address to be used
//Now send message
MailUtil mu = new MailUtil(request);
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PropertyRetryController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PropertyRetryController.java
index 8dd545df4..f039f9e90 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PropertyRetryController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PropertyRetryController.java
@@ -28,6 +28,7 @@ import edu.cornell.mannlib.vedit.forwarder.PageForwarder;
import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vedit.validator.impl.XMLNameValidator;
+import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionListener;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
@@ -117,8 +118,7 @@ public class PropertyRetryController extends BaseEditController {
//set up any listeners
List changeListenerList = new ArrayList();
- //changeListenerList.add(new HiddenFromDisplayListener(getServletContext()));
- //changeListenerList.add(new PropertyRestrictionListener(getServletContext()));
+ changeListenerList.add(new PropertyRestrictionListener(getServletContext()));
epo.setChangeListenerList(changeListenerList);
//make a postinsert pageforwarder that will send us to a new class's fetch screen
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserEditController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserEditController.java
deleted file mode 100644
index 49a1038c7..000000000
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserEditController.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/* $This file is distributed under the terms of the license in /doc/license.txt$ */
-
-package edu.cornell.mannlib.vitro.webapp.controller.edit;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import edu.cornell.mannlib.vedit.controller.BaseEditController;
-import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
-import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageUserAccounts;
-import edu.cornell.mannlib.vitro.webapp.beans.Individual;
-import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
-import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
-import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
-import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
-import edu.cornell.mannlib.vitro.webapp.beans.User;
-import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
-import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
-import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
-import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
-
-public class UserEditController extends BaseEditController {
-
- private String[] roleNameStr = new String[51];
- private static final Log log = LogFactory.getLog(UserEditController.class.getName());
-
- public UserEditController() {
- roleNameStr[1] = "self editor";
- roleNameStr[4] = "editor";
- roleNameStr[5] = "curator";
- roleNameStr[50] = "system administrator";
- }
-
- @Override
- public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException {
- if (!isAuthorizedToDisplayPage(request, response, new Actions(new ManageUserAccounts()))) {
- return;
- }
-
- VitroRequest vreq = new VitroRequest(request);
-
- UserDao uDao = vreq.getFullWebappDaoFactory().getUserDao();
-
- String userURIStr = request.getParameter("uri");
- User u = null;
-
- if (userURIStr == null) {
- throw new ServletException(this.getClass().getName()+" expects user URI in 'uri' request parameter");
- } else {
- u = uDao.getUserByURI(userURIStr);
- }
-
- if (u == null) {
- throw new ServletException(this.getClass().getName()+" could not find user "+userURIStr);
- }
-
- ArrayList results = new ArrayList();
- results.add("Email address");
- results.add("first name");
- results.add("last name");
- results.add("login count");
- results.add("role");
-
- String EMPTY = "";
-
- String usernameStr = (u.getUsername() != null) ? u.getUsername() : "";
- results.add(usernameStr);
- String firstNameStr = (u.getFirstName() != null) ? u.getFirstName() : EMPTY;
- results.add(firstNameStr);
- String lastNameStr = (u.getLastName() != null) ? u.getLastName() : EMPTY;
- results.add(lastNameStr);
- String loginCountStr = Integer.toString(u.getLoginCount());
- results.add(loginCountStr);
- String roleStr = "";
- try {
- roleStr = roleNameStr[Integer.decode(u.getRoleURI())];
- } catch (Exception e) {}
- results.add(roleStr);
-
- request.setAttribute("results",results);
-
- List mayEditAsUris = uDao.getIndividualsUserMayEditAs(u.getURI());
- if( mayEditAsUris != null && mayEditAsUris.size() > 0 ){
- List mayEditAsStmts =
- new ArrayList(mayEditAsUris.size());
- for(String objURI: mayEditAsUris){
- Individual editAs = vreq.getFullWebappDaoFactory().getIndividualDao().getIndividualByURI(objURI);
- ObjectPropertyStatement stmt = new ObjectPropertyStatementImpl();
- stmt.setSubjectURI(u.getURI());
- stmt.setPropertyURI(VitroVocabulary.MAY_EDIT_AS);
- stmt.setObjectURI(objURI);
- stmt.setObject(editAs);
- mayEditAsStmts.add(stmt);
- }
- request.setAttribute("mayEditAsStmts", mayEditAsStmts);
- }
-
- /* these are set so that we can use the PropertyEditLinks jsp tags */
- ObjectProperty prop = new ObjectProperty();
- prop.setURI(VitroVocabulary.MAY_EDIT_AS);
- request.setAttribute("mayEditObjProp",prop);
- Individual entity = new IndividualImpl();
- entity.setURI(u.getURI());
- request.setAttribute("entity", entity);
-
- request.setAttribute("results", results);
- request.setAttribute("columncount", new Integer(5));
- request.setAttribute("suppressquery", "true");
-
- RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
- request.setAttribute("user", u);
- request.setAttribute("bodyJsp","/templates/edit/specific/user_edit.jsp");
- request.setAttribute("title","User Account Control Panel");
- request.setAttribute("css", "");
-
- try {
- rd.forward(request, response);
- } catch (Exception e) {
- log.error(this.getClass().getName()+" could not forward to view.");
- log.error(e.getMessage());
- log.error(e.getStackTrace());
- }
-
- }
-
- public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException {
- doPost(request,response);
- }
-
-}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserRetryController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserRetryController.java
deleted file mode 100644
index 221270593..000000000
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/UserRetryController.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/* $This file is distributed under the terms of the license in /doc/license.txt$ */
-
-package edu.cornell.mannlib.vitro.webapp.controller.edit;
-
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import edu.cornell.mannlib.vedit.beans.EditProcessObject;
-import edu.cornell.mannlib.vedit.beans.FormObject;
-import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
-import edu.cornell.mannlib.vedit.beans.Option;
-import edu.cornell.mannlib.vedit.controller.BaseEditController;
-import edu.cornell.mannlib.vedit.forwarder.PageForwarder;
-import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
-import edu.cornell.mannlib.vedit.listener.ChangeListener;
-import edu.cornell.mannlib.vedit.util.FormUtils;
-import edu.cornell.mannlib.vedit.validator.ValidationObject;
-import edu.cornell.mannlib.vedit.validator.Validator;
-import edu.cornell.mannlib.vitro.webapp.auth.policy.setup.SelfEditingPolicySetup;
-import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
-import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageUserAccounts;
-import edu.cornell.mannlib.vitro.webapp.beans.User;
-import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
-import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
-import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
-import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
-
-public class UserRetryController extends BaseEditController {
-
- private static final String ROLE_PROTOCOL = "role:/"; // this is weird; need to revisit
- private static final Log log = LogFactory.getLog(UserRetryController.class.getName());
-
- @Override
- public void doPost (HttpServletRequest req, HttpServletResponse response) {
- if (!isAuthorizedToDisplayPage(req, response, new Actions(new ManageUserAccounts()))) {
- return;
- }
-
- VitroRequest request = new VitroRequest(req);
-
- //create an EditProcessObject for this and put it in the session
- EditProcessObject epo = super.createEpo(request);
- epo.setDataAccessObject(request.getFullWebappDaoFactory().getVClassDao());
-
- String action = null;
- if (epo.getAction() == null) {
- action = "insert";
- epo.setAction("insert");
- } else {
- action = epo.getAction();
- }
-
- UserDao uDao = request.getFullWebappDaoFactory().getUserDao();
- epo.setDataAccessObject(uDao);
-
- User userForEditing = null;
- if (!epo.getUseRecycledBean()){
- if (request.getParameter("uri") != null) {
- try {
- userForEditing = uDao.getUserByURI(request.getParameter("uri"));
- userForEditing.setRoleURI(ROLE_PROTOCOL+userForEditing.getRoleURI());
- action = "update";
- epo.setAction("udpate");
- } catch (NullPointerException e) {
- log.error("Need to implement 'record not found' error message.");
- }
- } else {
- userForEditing = new User();
- userForEditing.setRoleURI(ROLE_PROTOCOL+"1");
- }
- epo.setOriginalBean(userForEditing);
- } else {
- userForEditing = (User) epo.getNewBean();
- }
-
- populateBeanFromParams(userForEditing, request);
-
- //validators
- Validator v = new PairedPasswordValidator();
- HashMap> validatorMap = new HashMap>();
- List vList = Collections.singletonList(v);
- validatorMap.put("Md5password", vList);
- validatorMap.put("passwordConfirmation", vList);
- epo.setValidatorMap(validatorMap);
-
- //preprocessors
-
- //set up any listeners
- epo.setChangeListenerList(Collections.singletonList(new UserPasswordChangeListener()));
-
- //make a postinsert pageforwarder that will send us to a new class's fetch screen
- epo.setPostInsertPageForwarder(new UserInsertPageForwarder());
- //make a postdelete pageforwarder that will send us to the list of classes
- epo.setPostDeletePageForwarder(new UrlForwarder("listUsers"));
-
- //set the getMethod so we can retrieve a new bean after we've inserted it
- try {
- Class>[] args = new Class[] {String.class};
- epo.setGetMethod(uDao.getClass().getDeclaredMethod("getUserByURI",args));
- } catch (NoSuchMethodException e) {
- log.error(this.getClass().getName()+" could not find the getVClassByURI method");
- }
-
- HashMap> optionMap = new HashMap>();
-
- LoginStatusBean loginBean = LoginStatusBean.getBean(request);
- List