From 2bfb79995e461146e0590bbd0588e62fc4f8eb58 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 15 Jun 2011 19:51:46 +0000 Subject: [PATCH] Add External Authorization ID to the "Add Account" and "Edit Account" pages. --- .../accounts/admin/UserAccountsAddPage.java | 18 +++++++++++++++-- .../accounts/admin/UserAccountsEditPage.java | 20 +++++++++++++++++++ .../body/accounts/userAccounts-add.ftl | 7 +++++++ .../body/accounts/userAccounts-edit.ftl | 7 +++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java index 51c723459..2add74003 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java @@ -22,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem public class UserAccountsAddPage extends UserAccountsPage { private static final String PARAMETER_SUBMIT = "submitAdd"; private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress"; + private static final String PARAMETER_EXTERNAL_AUTH_ID = "externalAuthId"; private static final String PARAMETER_FIRST_NAME = "firstName"; private static final String PARAMETER_LAST_NAME = "lastName"; private static final String PARAMETER_ROLE = "role"; @@ -30,6 +31,7 @@ public class UserAccountsAddPage extends UserAccountsPage { private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty"; private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse"; private static final String ERROR_EMAIL_INVALID_FORMAT = "errorEmailInvalidFormat"; + private static final String ERROR_EXTERNAL_AUTH_ID_IN_USE = "errorExternalAuthIdInUse"; private static final String ERROR_NO_FIRST_NAME = "errorFirstNameIsEmpty"; private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty"; private static final String ERROR_NO_ROLE = "errorNoRoleSelected"; @@ -41,6 +43,7 @@ public class UserAccountsAddPage extends UserAccountsPage { /* The request parameters */ private boolean submit; private String emailAddress = ""; + private String externalAuthId = ""; private String firstName = ""; private String lastName = ""; private String selectedRoleUri = ""; @@ -68,6 +71,7 @@ public class UserAccountsAddPage extends UserAccountsPage { private void parseRequestParameters() { submit = isFlagOnRequest(PARAMETER_SUBMIT); emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, ""); + externalAuthId = getStringParameter(PARAMETER_EXTERNAL_AUTH_ID, ""); firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, ""); selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); @@ -88,6 +92,8 @@ public class UserAccountsAddPage extends UserAccountsPage { errorCode = ERROR_EMAIL_IN_USE; } else if (!isEmailValidFormat()) { errorCode = ERROR_EMAIL_INVALID_FORMAT; + } else if (isExternalAuthIdInUse()) { + errorCode = ERROR_EXTERNAL_AUTH_ID_IN_USE; } else if (firstName.isEmpty()) { errorCode = ERROR_NO_FIRST_NAME; } else if (lastName.isEmpty()) { @@ -103,10 +109,17 @@ public class UserAccountsAddPage extends UserAccountsPage { return userAccountsDao.getUserAccountByEmail(emailAddress) != null; } + private boolean isExternalAuthIdInUse() { + if (externalAuthId.isEmpty()) { + return false; + } + return userAccountsDao.getUserAccountByExternalAuthId(externalAuthId) != null; + } + private boolean isEmailValidFormat() { return Authenticator.isValidEmailAddress(emailAddress); } - + public boolean isValid() { return errorCode.isEmpty(); } @@ -116,7 +129,7 @@ public class UserAccountsAddPage extends UserAccountsPage { u.setEmailAddress(emailAddress); u.setFirstName(firstName); u.setLastName(lastName); - u.setExternalAuthId(""); + u.setExternalAuthId(externalAuthId); u.setMd5Password(""); u.setOldPassword(""); @@ -139,6 +152,7 @@ public class UserAccountsAddPage extends UserAccountsPage { Map body = new HashMap(); body.put("emailAddress", emailAddress); + body.put("externalAuthId", externalAuthId); body.put("firstName", firstName); body.put("lastName", lastName); body.put("selectedRole", selectedRoleUri); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java index c939dfe24..b53b008ca 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java @@ -28,6 +28,7 @@ public class UserAccountsEditPage extends UserAccountsPage { private static final String PARAMETER_SUBMIT = "submitEdit"; private static final String PARAMETER_USER_URI = "editAccount"; private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress"; + private static final String PARAMETER_EXTERNAL_AUTH_ID = "externalAuthId"; private static final String PARAMETER_FIRST_NAME = "firstName"; private static final String PARAMETER_LAST_NAME = "lastName"; private static final String PARAMETER_ROLE = "role"; @@ -36,6 +37,7 @@ public class UserAccountsEditPage extends UserAccountsPage { private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty"; private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse"; private static final String ERROR_EMAIL_INVALID_FORMAT = "errorEmailInvalidFormat"; + private static final String ERROR_EXTERNAL_AUTH_ID_IN_USE = "errorExternalAuthIdInUse"; private static final String ERROR_NO_FIRST_NAME = "errorFirstNameIsEmpty"; private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty"; private static final String ERROR_NO_ROLE = "errorNoRoleSelected"; @@ -48,6 +50,7 @@ public class UserAccountsEditPage extends UserAccountsPage { private boolean submit; private String userUri = ""; private String emailAddress = ""; + private String externalAuthId = ""; private String firstName = ""; private String lastName = ""; private String selectedRoleUri = ""; @@ -79,6 +82,7 @@ public class UserAccountsEditPage extends UserAccountsPage { submit = isFlagOnRequest(PARAMETER_SUBMIT); userUri = getStringParameter(PARAMETER_USER_URI, ""); emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, ""); + externalAuthId = getStringParameter(PARAMETER_EXTERNAL_AUTH_ID, ""); firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, ""); selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); @@ -117,6 +121,8 @@ public class UserAccountsEditPage extends UserAccountsPage { errorCode = ERROR_EMAIL_IN_USE; } else if (!isEmailValidFormat()) { errorCode = ERROR_EMAIL_INVALID_FORMAT; + } else if (externalAuthIdIsChanged() && isExternalAuthIdInUse()) { + errorCode = ERROR_EXTERNAL_AUTH_ID_IN_USE; } else if (firstName.isEmpty()) { errorCode = ERROR_NO_FIRST_NAME; } else if (lastName.isEmpty()) { @@ -140,6 +146,17 @@ public class UserAccountsEditPage extends UserAccountsPage { return Authenticator.isValidEmailAddress(emailAddress); } + private boolean externalAuthIdIsChanged() { + return !externalAuthId.equals(userAccount.getExternalAuthId()); + } + + private boolean isExternalAuthIdInUse() { + if (externalAuthId.isEmpty()) { + return false; + } + return userAccountsDao.getUserAccountByExternalAuthId(externalAuthId) != null; + } + public boolean isValid() { return errorCode.isEmpty(); } @@ -149,11 +166,13 @@ public class UserAccountsEditPage extends UserAccountsPage { if (isSubmit()) { body.put("emailAddress", emailAddress); + body.put("externalAuthId", externalAuthId); body.put("firstName", firstName); body.put("lastName", lastName); body.put("selectedRole", selectedRoleUri); } else { body.put("emailAddress", userAccount.getEmailAddress()); + body.put("externalAuthId", userAccount.getExternalAuthId()); body.put("firstName", userAccount.getFirstName()); body.put("lastName", userAccount.getLastName()); body.put("selectedRole", getExistingRoleUri()); @@ -192,6 +211,7 @@ public class UserAccountsEditPage extends UserAccountsPage { userAccount.setEmailAddress(emailAddress); userAccount.setFirstName(firstName); userAccount.setLastName(lastName); + userAccount.setExternalAuthId(externalAuthId); userAccount .setPermissionSetUris(Collections.singleton(selectedRoleUri)); diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl index c6d4809c6..5106ca8d8 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl @@ -16,6 +16,10 @@ <#assign errorMessage = "'${emailAddress}' is not a valid email address." /> + <#if errorExternalAuthIdInUse??> + <#assign errorMessage = "An account with that external authorization ID already exists." /> + + <#if errorFirstNameIsEmpty??> <#assign errorMessage = "You must supply a first name." /> @@ -61,6 +65,9 @@ + + +

Roles *

<#list roles as role> selected /> diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl index 0d9e30718..816a6306a 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl @@ -16,6 +16,10 @@ <#assign errorMessage = "'${emailAddress}' is not a valid email address." /> + <#if errorExternalAuthIdInUse??> + <#assign errorMessage = "An account with that external authorization ID already exists." /> + + <#if errorFirstNameIsEmpty??> <#assign errorMessage = "You must supply a first name." /> @@ -61,6 +65,9 @@ + + +

Roles *

<#list roles as role> selected />