Add External Authorization ID to the "Add Account" and "Edit Account" pages.

This commit is contained in:
j2blake 2011-06-15 19:51:46 +00:00
parent 6af401dd6f
commit 2bfb79995e
4 changed files with 50 additions and 2 deletions

View file

@ -22,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
public class UserAccountsAddPage extends UserAccountsPage { public class UserAccountsAddPage extends UserAccountsPage {
private static final String PARAMETER_SUBMIT = "submitAdd"; private static final String PARAMETER_SUBMIT = "submitAdd";
private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress"; 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_FIRST_NAME = "firstName";
private static final String PARAMETER_LAST_NAME = "lastName"; private static final String PARAMETER_LAST_NAME = "lastName";
private static final String PARAMETER_ROLE = "role"; 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_NO_EMAIL = "errorEmailIsEmpty";
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse"; private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
private static final String ERROR_EMAIL_INVALID_FORMAT = "errorEmailInvalidFormat"; 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_FIRST_NAME = "errorFirstNameIsEmpty";
private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty"; private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty";
private static final String ERROR_NO_ROLE = "errorNoRoleSelected"; private static final String ERROR_NO_ROLE = "errorNoRoleSelected";
@ -41,6 +43,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
/* The request parameters */ /* The request parameters */
private boolean submit; private boolean submit;
private String emailAddress = ""; private String emailAddress = "";
private String externalAuthId = "";
private String firstName = ""; private String firstName = "";
private String lastName = ""; private String lastName = "";
private String selectedRoleUri = ""; private String selectedRoleUri = "";
@ -68,6 +71,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
private void parseRequestParameters() { private void parseRequestParameters() {
submit = isFlagOnRequest(PARAMETER_SUBMIT); submit = isFlagOnRequest(PARAMETER_SUBMIT);
emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, ""); emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, "");
externalAuthId = getStringParameter(PARAMETER_EXTERNAL_AUTH_ID, "");
firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
lastName = getStringParameter(PARAMETER_LAST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, "");
selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
@ -88,6 +92,8 @@ public class UserAccountsAddPage extends UserAccountsPage {
errorCode = ERROR_EMAIL_IN_USE; errorCode = ERROR_EMAIL_IN_USE;
} else if (!isEmailValidFormat()) { } else if (!isEmailValidFormat()) {
errorCode = ERROR_EMAIL_INVALID_FORMAT; errorCode = ERROR_EMAIL_INVALID_FORMAT;
} else if (isExternalAuthIdInUse()) {
errorCode = ERROR_EXTERNAL_AUTH_ID_IN_USE;
} else if (firstName.isEmpty()) { } else if (firstName.isEmpty()) {
errorCode = ERROR_NO_FIRST_NAME; errorCode = ERROR_NO_FIRST_NAME;
} else if (lastName.isEmpty()) { } else if (lastName.isEmpty()) {
@ -103,10 +109,17 @@ public class UserAccountsAddPage extends UserAccountsPage {
return userAccountsDao.getUserAccountByEmail(emailAddress) != null; return userAccountsDao.getUserAccountByEmail(emailAddress) != null;
} }
private boolean isExternalAuthIdInUse() {
if (externalAuthId.isEmpty()) {
return false;
}
return userAccountsDao.getUserAccountByExternalAuthId(externalAuthId) != null;
}
private boolean isEmailValidFormat() { private boolean isEmailValidFormat() {
return Authenticator.isValidEmailAddress(emailAddress); return Authenticator.isValidEmailAddress(emailAddress);
} }
public boolean isValid() { public boolean isValid() {
return errorCode.isEmpty(); return errorCode.isEmpty();
} }
@ -116,7 +129,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
u.setEmailAddress(emailAddress); u.setEmailAddress(emailAddress);
u.setFirstName(firstName); u.setFirstName(firstName);
u.setLastName(lastName); u.setLastName(lastName);
u.setExternalAuthId(""); u.setExternalAuthId(externalAuthId);
u.setMd5Password(""); u.setMd5Password("");
u.setOldPassword(""); u.setOldPassword("");
@ -139,6 +152,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("emailAddress", emailAddress); body.put("emailAddress", emailAddress);
body.put("externalAuthId", externalAuthId);
body.put("firstName", firstName); body.put("firstName", firstName);
body.put("lastName", lastName); body.put("lastName", lastName);
body.put("selectedRole", selectedRoleUri); body.put("selectedRole", selectedRoleUri);

View file

@ -28,6 +28,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
private static final String PARAMETER_SUBMIT = "submitEdit"; private static final String PARAMETER_SUBMIT = "submitEdit";
private static final String PARAMETER_USER_URI = "editAccount"; private static final String PARAMETER_USER_URI = "editAccount";
private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress"; 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_FIRST_NAME = "firstName";
private static final String PARAMETER_LAST_NAME = "lastName"; private static final String PARAMETER_LAST_NAME = "lastName";
private static final String PARAMETER_ROLE = "role"; 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_NO_EMAIL = "errorEmailIsEmpty";
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse"; private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
private static final String ERROR_EMAIL_INVALID_FORMAT = "errorEmailInvalidFormat"; 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_FIRST_NAME = "errorFirstNameIsEmpty";
private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty"; private static final String ERROR_NO_LAST_NAME = "errorLastNameIsEmpty";
private static final String ERROR_NO_ROLE = "errorNoRoleSelected"; private static final String ERROR_NO_ROLE = "errorNoRoleSelected";
@ -48,6 +50,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
private boolean submit; private boolean submit;
private String userUri = ""; private String userUri = "";
private String emailAddress = ""; private String emailAddress = "";
private String externalAuthId = "";
private String firstName = ""; private String firstName = "";
private String lastName = ""; private String lastName = "";
private String selectedRoleUri = ""; private String selectedRoleUri = "";
@ -79,6 +82,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
submit = isFlagOnRequest(PARAMETER_SUBMIT); submit = isFlagOnRequest(PARAMETER_SUBMIT);
userUri = getStringParameter(PARAMETER_USER_URI, ""); userUri = getStringParameter(PARAMETER_USER_URI, "");
emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, ""); emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, "");
externalAuthId = getStringParameter(PARAMETER_EXTERNAL_AUTH_ID, "");
firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
lastName = getStringParameter(PARAMETER_LAST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, "");
selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
@ -117,6 +121,8 @@ public class UserAccountsEditPage extends UserAccountsPage {
errorCode = ERROR_EMAIL_IN_USE; errorCode = ERROR_EMAIL_IN_USE;
} else if (!isEmailValidFormat()) { } else if (!isEmailValidFormat()) {
errorCode = ERROR_EMAIL_INVALID_FORMAT; errorCode = ERROR_EMAIL_INVALID_FORMAT;
} else if (externalAuthIdIsChanged() && isExternalAuthIdInUse()) {
errorCode = ERROR_EXTERNAL_AUTH_ID_IN_USE;
} else if (firstName.isEmpty()) { } else if (firstName.isEmpty()) {
errorCode = ERROR_NO_FIRST_NAME; errorCode = ERROR_NO_FIRST_NAME;
} else if (lastName.isEmpty()) { } else if (lastName.isEmpty()) {
@ -140,6 +146,17 @@ public class UserAccountsEditPage extends UserAccountsPage {
return Authenticator.isValidEmailAddress(emailAddress); 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() { public boolean isValid() {
return errorCode.isEmpty(); return errorCode.isEmpty();
} }
@ -149,11 +166,13 @@ public class UserAccountsEditPage extends UserAccountsPage {
if (isSubmit()) { if (isSubmit()) {
body.put("emailAddress", emailAddress); body.put("emailAddress", emailAddress);
body.put("externalAuthId", externalAuthId);
body.put("firstName", firstName); body.put("firstName", firstName);
body.put("lastName", lastName); body.put("lastName", lastName);
body.put("selectedRole", selectedRoleUri); body.put("selectedRole", selectedRoleUri);
} else { } else {
body.put("emailAddress", userAccount.getEmailAddress()); body.put("emailAddress", userAccount.getEmailAddress());
body.put("externalAuthId", userAccount.getExternalAuthId());
body.put("firstName", userAccount.getFirstName()); body.put("firstName", userAccount.getFirstName());
body.put("lastName", userAccount.getLastName()); body.put("lastName", userAccount.getLastName());
body.put("selectedRole", getExistingRoleUri()); body.put("selectedRole", getExistingRoleUri());
@ -192,6 +211,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
userAccount.setEmailAddress(emailAddress); userAccount.setEmailAddress(emailAddress);
userAccount.setFirstName(firstName); userAccount.setFirstName(firstName);
userAccount.setLastName(lastName); userAccount.setLastName(lastName);
userAccount.setExternalAuthId(externalAuthId);
userAccount userAccount
.setPermissionSetUris(Collections.singleton(selectedRoleUri)); .setPermissionSetUris(Collections.singleton(selectedRoleUri));

View file

@ -16,6 +16,10 @@
<#assign errorMessage = "'${emailAddress}' is not a valid email address." /> <#assign errorMessage = "'${emailAddress}' is not a valid email address." />
</#if> </#if>
<#if errorExternalAuthIdInUse??>
<#assign errorMessage = "An account with that external authorization ID already exists." />
</#if>
<#if errorFirstNameIsEmpty??> <#if errorFirstNameIsEmpty??>
<#assign errorMessage = "You must supply a first name." /> <#assign errorMessage = "You must supply a first name." />
</#if> </#if>
@ -61,6 +65,9 @@
<label for="last-name">Last name<span class="requiredHint"> *</span></label> <label for="last-name">Last name<span class="requiredHint"> *</span></label>
<input type="text" name="lastName" value="${lastName}" id="last-name" role="input "/> <input type="text" name="lastName" value="${lastName}" id="last-name" role="input "/>
<label for="external-auth-id">External authorization ID (optional)</label>
<input type="text" name="externalAuthId" value="${externalAuthId}" id="external-auth-id" role="input "/>
<p>Roles<span class="requiredHint"> *</span> </p> <p>Roles<span class="requiredHint"> *</span> </p>
<#list roles as role> <#list roles as role>
<input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>selected</#if> /> <input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>selected</#if> />

View file

@ -16,6 +16,10 @@
<#assign errorMessage = "'${emailAddress}' is not a valid email address." /> <#assign errorMessage = "'${emailAddress}' is not a valid email address." />
</#if> </#if>
<#if errorExternalAuthIdInUse??>
<#assign errorMessage = "An account with that external authorization ID already exists." />
</#if>
<#if errorFirstNameIsEmpty??> <#if errorFirstNameIsEmpty??>
<#assign errorMessage = "You must supply a first name." /> <#assign errorMessage = "You must supply a first name." />
</#if> </#if>
@ -61,6 +65,9 @@
<label for="last-name">Last name<span class="requiredHint"> *</span></label> <label for="last-name">Last name<span class="requiredHint"> *</span></label>
<input type="text" name="lastName" value="${lastName}" id="last-name" role="input" /> <input type="text" name="lastName" value="${lastName}" id="last-name" role="input" />
<label for="external-auth-id">External authorization ID (optional)</label>
<input type="text" name="externalAuthId" value="${externalAuthId}" id="external-auth-id" role="input "/>
<p>Roles<span class="requiredHint"> *</span> </p> <p>Roles<span class="requiredHint"> *</span> </p>
<#list roles as role> <#list roles as role>
<input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>selected</#if> /> <input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>selected</#if> />