Add External Authorization ID to the "Add Account" and "Edit Account" pages.
This commit is contained in:
parent
6af401dd6f
commit
2bfb79995e
4 changed files with 50 additions and 2 deletions
|
@ -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<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
body.put("emailAddress", emailAddress);
|
||||
body.put("externalAuthId", externalAuthId);
|
||||
body.put("firstName", firstName);
|
||||
body.put("lastName", lastName);
|
||||
body.put("selectedRole", selectedRoleUri);
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue