From 5de5a322a21bae9810bd0bb07c695bac38f25195 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 14 Jun 2013 12:47:37 -0400 Subject: [PATCH] VIVO-139 Use the I18n framework wherever DisplayMessage is loaded. --- .../webapp/controller/VitroHttpServlet.java | 12 +--- .../authenticate/AdminLoginController.java | 3 + .../authenticate/BaseLoginServlet.java | 23 +++--- .../authenticate/LoginExternalAuthReturn.java | 12 ++-- .../authenticate/LoginExternalAuthSetup.java | 2 +- .../authenticate/LoginRedirector.java | 25 +++---- .../webapp/controller/edit/Authenticate.java | 27 +++---- .../vitro/webapp/controller/edit/Logout.java | 5 +- .../controller/login/LoginProcessBean.java | 72 +++++++------------ .../selection/LocaleSelectionController.java | 4 +- .../vitro/webapp/web/widgets/LoginWidget.java | 5 +- .../controller/edit/AuthenticateTest.java | 23 +++--- webapp/web/i18n/all.properties | 23 +++++- webapp/web/i18n/all_es.properties | 25 ++++++- .../body/accounts/userAccounts-add.ftl | 2 +- .../userAccounts-firstTimeExternal.ftl | 2 +- .../body/admin/admin-restrictLogins.ftl | 8 +-- .../freemarker/body/login/adminLogin.ftl | 4 +- .../freemarker/widgets/widget-login.ftl | 2 +- 19 files changed, 151 insertions(+), 128 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java index bbff11b44..dd25369b9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java @@ -30,6 +30,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAct import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; public class VitroHttpServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -63,15 +64,6 @@ public class VitroHttpServlet extends HttpServlet { super.service(req, resp); } - /** - * Show this to the user if they are logged in, but still not authorized to - * view the page. - */ - private static final String INSUFFICIENT_AUTHORIZATION_MESSAGE = "We're sorry, " - + "but you are not authorized to view the page you requested. " - + "If you think this is an error, " - + "please contact us and we'll be happy to help."; - /** * doGet does nothing. */ @@ -148,7 +140,7 @@ public class VitroHttpServlet extends HttpServlet { HttpServletRequest request, HttpServletResponse response) { try { DisplayMessage.setMessage(request, - INSUFFICIENT_AUTHORIZATION_MESSAGE); + I18n.bundle(request).text("insufficient_authorization")); response.sendRedirect(request.getContextPath()); } catch (IOException e) { log.error("Could not redirect to show insufficient authorization."); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java index 9863a3436..c789d7e51 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java @@ -171,6 +171,9 @@ public class AdminLoginController extends FreemarkerHttpServlet { body.put("password", password); body.put("newPassword", newPassword); body.put("confirmPassword", confirmPassword); + + body.put("minPasswordLength", MIN_PASSWORD_LENGTH); + body.put("maxPasswordLength", MAX_PASSWORD_LENGTH); for (String code : codes) { body.put(code, Boolean.TRUE); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BaseLoginServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BaseLoginServlet.java index 20bcd402e..3892662ce 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BaseLoginServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BaseLoginServlet.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; +import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.MLevel; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message; /** @@ -21,14 +22,15 @@ public class BaseLoginServlet extends HttpServlet { private static final Log log = LogFactory.getLog(BaseLoginServlet.class); /** A general purpose error message for the user to see. */ - protected static final Message MESSAGE_LOGIN_FAILED = new LoginProcessBean.Message( - "External login failed.", LoginProcessBean.MLevel.ERROR); - + protected static Message messageLoginFailed(HttpServletRequest req) { + return new LoginProcessBean.Message(req, MLevel.ERROR, "external_login_failed"); + } + /** Tell the user that it's nothing personal, they just aren't allowed in. */ - protected static final Message MESSAGE_LOGIN_DISABLED = new LoginProcessBean.Message( - "User logins are temporarily disabled while the system is being maintained.", - LoginProcessBean.MLevel.ERROR); - + protected static Message messageLoginDisabled(HttpServletRequest req) { + return new LoginProcessBean.Message(req, MLevel.ERROR, "logins_temporarily_disabled"); + } + protected Authenticator getAuthenticator(HttpServletRequest req) { return Authenticator.getInstance(req); } @@ -40,10 +42,9 @@ public class BaseLoginServlet extends HttpServlet { */ protected void complainAndReturnToReferrer(HttpServletRequest req, HttpServletResponse resp, String sessionAttributeForReferrer, - Message message, Object... args) throws IOException { - log.debug(message.getMessageLevel() + ": " - + message.formatMessage(args)); - LoginProcessBean.getBean(req).setMessage(message, args); + Message message) throws IOException { + log.debug(message); + LoginProcessBean.getBean(req).setMessage(message); String referrer = (String) req.getSession().getAttribute( sessionAttributeForReferrer); 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 878a60b30..d37c1cf7d 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 @@ -71,7 +71,7 @@ public class LoginExternalAuthReturn extends BaseLoginServlet { if (externalAuthId == null) { complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, - MESSAGE_LOGIN_FAILED); + messageLoginFailed(req)); return; } @@ -84,7 +84,7 @@ public class LoginExternalAuthReturn extends BaseLoginServlet { if (!getAuthenticator(req).isUserPermittedToLogin(userAccount)) { log.debug("Logins disabled for " + userAccount); complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, - MESSAGE_LOGIN_DISABLED); + messageLoginDisabled(req)); return; } @@ -107,7 +107,7 @@ public class LoginExternalAuthReturn extends BaseLoginServlet { // should have been caught by isUserPermittedToLogin() log.debug("Logins disabled for " + userAccount); complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, - MESSAGE_LOGIN_DISABLED); + messageLoginDisabled(req)); return; } } @@ -115,10 +115,10 @@ public class LoginExternalAuthReturn extends BaseLoginServlet { @Override protected void complainAndReturnToReferrer(HttpServletRequest req, HttpServletResponse resp, String sessionAttributeForReferrer, - Message message, Object... args) throws IOException { - DisplayMessage.setMessage(req, message.formatMessage(args)); + Message message) throws IOException { + DisplayMessage.setMessage(req, message.getText()); super.complainAndReturnToReferrer(req, resp, - sessionAttributeForReferrer, message, args); + sessionAttributeForReferrer, message); } private void removeLoginProcessArtifacts(HttpServletRequest req) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthSetup.java index e1d8db979..55c3a074a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/LoginExternalAuthSetup.java @@ -53,7 +53,7 @@ public class LoginExternalAuthSetup extends BaseLoginServlet { if (redirectUrl == null) { complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, - MESSAGE_LOGIN_FAILED); + messageLoginFailed(req)); } log.debug("redirecting to '" + redirectUrl + "'"); 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 92c8cda72..1fa147663 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 @@ -21,6 +21,8 @@ import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; /** * A user has just completed the login process. What page do we direct them to? @@ -30,6 +32,7 @@ public class LoginRedirector { private final HttpServletRequest request; private final HttpSession session; + private final I18nBundle i18n; private final String uriOfAssociatedIndividual; private final String afterLoginPage; @@ -37,6 +40,7 @@ public class LoginRedirector { public LoginRedirector(HttpServletRequest request, String afterLoginPage) { this.request = request; this.session = request.getSession(); + this.i18n = I18n.bundle(request); this.afterLoginPage = afterLoginPage; uriOfAssociatedIndividual = getAssociatedIndividualUri(); @@ -114,26 +118,23 @@ public class LoginRedirector { public String assembleWelcomeMessage() { if (!canSeeSiteAdminPage() && !isSelfEditorWithIndividual()) { // A special message for unrecognized self-editors: - return "You have logged in, " - + "but the system contains no profile for you."; + return i18n.text("logged_in_but_no_profile"); } - String backString = ""; - String greeting = ""; + String greeting = i18n.text("unknown_user_name"); + int loginCount = 0; UserAccount userAccount = LoginStatusBean.getCurrentUser(request); if (userAccount != null) { - greeting = userAccount.getEmailAddress(); - if (userAccount.getLoginCount() > 1) { - backString = " back"; - } - String name = userAccount.getFirstName(); - if (!StringUtils.isEmpty(name)) { - greeting = name; + loginCount = userAccount.getLoginCount(); + if (StringUtils.isNotEmpty(userAccount.getFirstName())) { + greeting = userAccount.getFirstName(); + } else if (StringUtils.isNotEmpty(userAccount.getEmailAddress())) { + greeting = userAccount.getEmailAddress(); } } - return "Welcome" + backString + ", " + greeting; + return i18n.text("login_welcome_message", greeting, loginCount); } public void redirectCancellingUser(HttpServletResponse response) 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 46af53601..142d9b4d4 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 @@ -4,6 +4,7 @@ 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.MLevel.ERROR; 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; @@ -37,7 +38,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator.Lo import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginInProcessFlag; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; -import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginLogoutEvent; @@ -309,7 +309,7 @@ public class Authenticate extends VitroHttpServlet { + bean); if ((username == null) || username.isEmpty()) { - bean.setMessage(Message.NO_USERNAME); + bean.setMessage(request, ERROR, "error_no_email_address"); return; } @@ -320,22 +320,22 @@ public class Authenticate extends VitroHttpServlet { log.trace("User is " + (user == null ? "null" : user.getUri())); if (user == null) { - bean.setMessage(Message.UNKNOWN_USERNAME, username); + bean.setMessage(request, ERROR, "error_incorrect_credentials"); return; } if ((password == null) || password.isEmpty()) { - bean.setMessage(Message.NO_PASSWORD); + bean.setMessage(request, ERROR, "error_no_password"); return; } if (!getAuthenticator(request).isUserPermittedToLogin(user)) { - bean.setMessage(Message.LOGIN_DISABLED); + bean.setMessage(request, ERROR, "logins_disabled_for_maintenance"); return; } if (!getAuthenticator(request).isCurrentPassword(user, password)) { - bean.setMessage(Message.INCORRECT_PASSWORD); + bean.setMessage(request, ERROR, "error_incorrect_credentials"); return; } @@ -347,7 +347,8 @@ public class Authenticate extends VitroHttpServlet { transitionToLoggedIn(request, user); } catch (LoginNotPermitted e) { // This should have been caught by isUserPermittedToLogin() - bean.setMessage(Message.LOGIN_DISABLED); + bean.setMessage(request, ERROR, + "logins_disabled_for_maintenance"); return; } } @@ -379,19 +380,19 @@ public class Authenticate extends VitroHttpServlet { + ", bean=" + bean); if ((newPassword == null) || newPassword.isEmpty()) { - bean.setMessage(Message.NO_NEW_PASSWORD); + bean.setMessage(request, ERROR, "error_no_new_password"); return; } if (!newPassword.equals(confirm)) { - bean.setMessage(Message.MISMATCH_PASSWORD); + bean.setMessage(request, ERROR, "error_passwords_dont_match"); return; } if ((newPassword.length() < MIN_PASSWORD_LENGTH) || (newPassword.length() > MAX_PASSWORD_LENGTH)) { - bean.setMessage(Message.PASSWORD_LENGTH, MIN_PASSWORD_LENGTH, - MAX_PASSWORD_LENGTH); + bean.setMessage(request, ERROR, "error_password_length", + MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH); return; } @@ -400,7 +401,7 @@ public class Authenticate extends VitroHttpServlet { UserAccount user = getAuthenticator(request).getAccountForInternalAuth( username); if (getAuthenticator(request).isCurrentPassword(user, newPassword)) { - bean.setMessage(Message.USING_OLD_PASSWORD); + bean.setMessage(request, ERROR, "error_previous_password"); return; } @@ -409,7 +410,7 @@ public class Authenticate extends VitroHttpServlet { transitionToLoggedIn(request, user, newPassword); } catch (LoginNotPermitted e) { // This should have been caught by isUserPermittedToLogin() - bean.setMessage(Message.LOGIN_DISABLED); + bean.setMessage(request, ERROR, "logins_disabled_for_maintenance"); return; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java index d052c627d..3ab84257d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; /** * Provide a means for programmatic logout. @@ -22,13 +23,14 @@ public class Logout extends HttpServlet { /** This http header holds the referring page. */ private static final String HEADING_REFERRER = "referer"; + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) { try { String referrer = getReferringPage(request); String redirectUrl = LogoutRedirector.getRedirectUrl(request, response, referrer); Authenticator.getInstance(request).recordUserIsLoggedOut(); - DisplayMessage.setMessage(request, "You have logged out."); + DisplayMessage.setMessage(request, I18n.bundle(request).text("logged_out")); response.sendRedirect(redirectUrl); } catch (Exception ex) { @@ -45,6 +47,7 @@ public class Logout extends HttpServlet { return referrer; } + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) { doPost(request, response); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginProcessBean.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginProcessBean.java index 5c4c5017c..9a2e6c456 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginProcessBean.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginProcessBean.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.login; -import java.text.MessageFormat; import java.util.Arrays; import javax.servlet.http.HttpServletRequest; @@ -11,6 +10,8 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; + /** * Where are we in the process of logging on? What message should we show to the * user? @@ -110,60 +111,32 @@ public class LoginProcessBean { } public static class Message { - public static final Message NO_MESSAGE = new Message("", MLevel.NONE); + public static final Message NO_MESSAGE = new Message(); - public static final Message PASSWORD_CHANGE_SAVED = new Message( - "Your password has been saved.
" + "Please log in.", - MLevel.INFO); - - public static final Message NO_USERNAME = new Message( - "Please enter your email address.", MLevel.ERROR); - - public static final Message NO_PASSWORD = new Message( - "Please enter your password.", MLevel.ERROR); - - public static final Message UNKNOWN_USERNAME = new Message( - "The email or password you entered is incorrect.", MLevel.ERROR); - - public static final Message LOGIN_DISABLED = new Message( - "User logins are temporarily disabled while the system is being maintained.", - MLevel.ERROR); - - public static final Message INCORRECT_PASSWORD = new Message( - "The email or password you entered is incorrect.", MLevel.ERROR); - - public static final Message NO_NEW_PASSWORD = new Message( - "Please enter your new password.", MLevel.ERROR); - - public static final Message MISMATCH_PASSWORD = new Message( - "The passwords entered do not match.", MLevel.ERROR); - - public static final Message PASSWORD_LENGTH = new Message( - "Please enter a password between {0} and {1} characters in length.", - MLevel.ERROR); - - public static final Message USING_OLD_PASSWORD = new Message( - "Your new password cannot match the current one.", MLevel.ERROR); - - private final String format; + private final String text; private final MLevel messageLevel; - public Message(String format, MLevel messageLevel) { - this.format = format; - this.messageLevel = messageLevel; + public Message() { + this.messageLevel = MLevel.NONE; + this.text = ""; } - + + public Message(HttpServletRequest req, MLevel messageLevel, String textKey, Object... parameters) { + this.messageLevel = messageLevel; + this.text = I18n.bundle(req).text(textKey, parameters); + } + public MLevel getMessageLevel() { return this.messageLevel; } - public String formatMessage(Object[] args) { - return new MessageFormat(this.format).format(args); + public String getText() { + return text; } @Override public String toString() { - return "Message[" + messageLevel + ", '" + format + "']"; + return "Message[" + messageLevel + ", '" + text + "']"; } } @@ -210,10 +183,15 @@ public class LoginProcessBean { } } - public void setMessage(Message message, Object... args) { + public void setMessage(Message message) { synchronized (messageSynchronizer) { this.message = message; - this.messageArguments = args; + } + } + + public void setMessage(HttpServletRequest req, MLevel level, String textKey, Object... parameters) { + synchronized (messageSynchronizer) { + this.message = new Message(req, level, textKey, parameters); } } @@ -221,7 +199,7 @@ public class LoginProcessBean { synchronized (messageSynchronizer) { String text = ""; if (message.getMessageLevel() == MLevel.INFO) { - text = message.formatMessage(messageArguments); + text = message.getText(); clearMessage(); } return text; @@ -232,7 +210,7 @@ public class LoginProcessBean { synchronized (messageSynchronizer) { String text = ""; if (message.getMessageLevel() == MLevel.ERROR) { - text = message.formatMessage(messageArguments); + text = message.getText(); clearMessage(); } return text; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionController.java index 523a263a2..76bf70012 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionController.java @@ -18,6 +18,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; /** * Call this at /selectLocale&selection=[locale_string] @@ -75,8 +76,7 @@ public class LocaleSelectionController extends HttpServlet { } catch (IllegalArgumentException e) { log.error("Failed to convert the selection to a Locale", e); DisplayMessage.setMessage(req, - "There was a problem in the system. " - + "Your language choice was rejected."); + I18n.bundle(req).text("language_selection_failed")); return; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java index 559b775df..6b314b282 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java @@ -12,6 +12,7 @@ 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.UserAccount; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginInProcessFlag; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; @@ -56,7 +57,8 @@ public class LoginWidget extends Widget { EXTERNAL_AUTH_NAME("externalAuthName"), EXTERNAL_AUTH_URL("externalAuthUrl"), CANCEL_URL("cancelUrl"), - SITE_NAME("siteName"); + SITE_NAME("siteName"), + MINIMUM_PASSWORD_LENGTH("minimumPasswordLength"); private final String variableName; @@ -172,6 +174,7 @@ public class LoginWidget extends Widget { Macro.FORCE_PASSWORD_CHANGE.toString()); values.put(TemplateVariable.FORM_ACTION.toString(), getAuthenticateUrl(request)); values.put(TemplateVariable.CANCEL_URL.toString(), getCancelUrl(request)); + values.put(TemplateVariable.MINIMUM_PASSWORD_LENGTH.toString(), UserAccount.MIN_PASSWORD_LENGTH); String errorMessage = bean.getErrorMessageAndClear(); if (!errorMessage.isEmpty()) { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/edit/AuthenticateTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/edit/AuthenticateTest.java index f91f71b37..bd13ae520 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/edit/AuthenticateTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/edit/AuthenticateTest.java @@ -26,6 +26,7 @@ import stubs.edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesStub import stubs.edu.cornell.mannlib.vitro.webapp.dao.IndividualDaoStub; import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub; import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub; +import stubs.edu.cornell.mannlib.vitro.webapp.i18n.I18nStub; import stubs.javax.servlet.ServletConfigStub; import stubs.javax.servlet.ServletContextStub; import stubs.javax.servlet.http.HttpServletRequestStub; @@ -120,6 +121,11 @@ public class AuthenticateTest extends AbstractTestClass { @Before public void setup() throws Exception { + // Create an I18n module that has a value for any key, but the value is + // the key itself. + @SuppressWarnings("unused") + I18nStub i18n = new I18nStub(); + authenticatorFactory = new AuthenticatorStub.Factory(); authenticator = authenticatorFactory.getInstance(request); authenticator.addUser(createUserFromUserInfo(NEW_DBA)); @@ -314,7 +320,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(LOGGING_IN, NO_USER, NO_MSG, - "Please enter your email address.", URL_LOGIN, URL_WITH_LINK); + "error_no_email_address", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -326,8 +332,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(LOGGING_IN, "unknownBozo", NO_MSG, - "The email or password you entered is incorrect.", URL_LOGIN, - URL_WITH_LINK); + "error_incorrect_credentials", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -339,7 +344,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(LOGGING_IN, NEW_DBA_NAME, NO_MSG, - "Please enter your password.", URL_LOGIN, URL_WITH_LINK); + "error_no_password", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -351,8 +356,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(LOGGING_IN, NEW_DBA_NAME, NO_MSG, - "The email or password you entered is incorrect.", URL_LOGIN, - URL_WITH_LINK); + "error_incorrect_credentials", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -403,8 +407,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG, - "Please enter a password between 6 and 12 " - + "characters in length.", URL_LOGIN, URL_WITH_LINK); + "error_password_length", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -417,7 +420,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG, - "The passwords entered do not match.", URL_LOGIN, URL_WITH_LINK); + "error_passwords_dont_match", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } @@ -430,7 +433,7 @@ public class AuthenticateTest extends AbstractTestClass { doTheRequest(); assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG, - "Your new password cannot match the current one.", URL_LOGIN, + "error_previous_password", URL_LOGIN, URL_WITH_LINK); assertRedirectToLoginProcessPage(); } diff --git a/webapp/web/i18n/all.properties b/webapp/web/i18n/all.properties index 53a10596e..c5192e028 100644 --- a/webapp/web/i18n/all.properties +++ b/webapp/web/i18n/all.properties @@ -108,6 +108,14 @@ updated_account_notification = A confirmation email has been sent to {0} \ deleted_accounts = Deleted {0} {0, choice, 0#accounts |1#account |1 -

${strings.minimum_password_length}

+

${strings.minimum_password_length(minimumLength)}

diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-firstTimeExternal.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-firstTimeExternal.ftl index 46f038772..d5aaf65a6 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-firstTimeExternal.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-firstTimeExternal.ftl @@ -47,7 +47,7 @@

${strings.or} - ${strings.cancel_link} + ${strings.cancel_link}

* ${strings.required_fields}

diff --git a/webapp/web/templates/freemarker/body/admin/admin-restrictLogins.ftl b/webapp/web/templates/freemarker/body/admin/admin-restrictLogins.ftl index 3d806fdbe..31ce05919 100644 --- a/webapp/web/templates/freemarker/body/admin/admin-restrictLogins.ftl +++ b/webapp/web/templates/freemarker/body/admin/admin-restrictLogins.ftl @@ -2,7 +2,7 @@ <#-- Template for restricting (or opening) access to logins. --> -

Restrict Logins

+

${i18n().restrict_logins}

<#if messageAlreadyRestricted??> <#assign errorMessage = "${i18n().logins_already_restricted}" /> @@ -35,10 +35,10 @@
<#if restricted == true> -

Logins are restricted

+

${i18n().logins_are_restricted}

${i18n().remove_restrictions}

<#else> -

Logins are open to all

-

${i18n().Restrict Logins}

+

${i18n().logins_are_open}

+

${i18n().restrict_logins}

diff --git a/webapp/web/templates/freemarker/body/login/adminLogin.ftl b/webapp/web/templates/freemarker/body/login/adminLogin.ftl index d09934eb7..152b827ee 100644 --- a/webapp/web/templates/freemarker/body/login/adminLogin.ftl +++ b/webapp/web/templates/freemarker/body/login/adminLogin.ftl @@ -22,7 +22,7 @@ <#if errorNewPasswordWrongLength??> - <#assign errorMessage = "${i18n().password_length}" /> + <#assign errorMessage = "${i18n().password_length(minPasswordLength, maxPasswordLength)}" /> <#if errorNewPasswordsDontMatch??> @@ -51,7 +51,7 @@ -

${i18n().Minimum of 6 characters in length.

+

${i18n().minimum_password_length(minPasswordLength)}

diff --git a/webapp/web/templates/freemarker/widgets/widget-login.ftl b/webapp/web/templates/freemarker/widgets/widget-login.ftl index c08d2215b..a08d44ed2 100644 --- a/webapp/web/templates/freemarker/widgets/widget-login.ftl +++ b/webapp/web/templates/freemarker/widgets/widget-login.ftl @@ -90,7 +90,7 @@ -

${i18n().minimum_six_chars}

+

${i18n().minimum_password_length(minimumPasswordLength)}