Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5811 Fix rename user account #5814

Merged
merged 2 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
BuiltinUser bu = ctxt.builtinUsers().findByUserName(oldIdentifier);
au.setUserIdentifier(newIdentifier);

/*
5/3/2019
Related to 3575 and subsequent issues - we may decide to remove username from built in user as redundent
If so the code below will have to change, be careful around authenticated user lookup, could decide to leave as null if
AU lookup provider is built in.
*/

if (bu != null) {
bu.setUserName(newIdentifier);
AuthenticatedUserLookup aul = au.getAuthenticatedUserLookup();
aul.setPersistentUserId(newIdentifier);
//Validate the BuiltinUser change. Username validations are there.
//If we have our validation errors pass up to commands, this could be removed
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Expand All @@ -78,9 +87,6 @@ public void executeImpl(CommandContext ctxt) throws CommandException {

ctxt.actionLog().changeUserIdentifierInHistory("@" + oldIdentifier, "@" + newIdentifier);

AuthenticatedUserLookup aul = au.getAuthenticatedUserLookup();
aul.setPersistentUserId(newIdentifier);

for(RoleAssignment ra : raList) {
ra.setAssigneeIdentifier("@" + newIdentifier);
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ public void convertNonBcryptUserFromBuiltinToShib() {
makeShibUser.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.affiliation", equalTo("TestShib Test IdP"));

String newUsername = "newUser_" + UtilIT.getRandomString(4);
System.out.println("newUsername for change shib user: " + newUsername);
Response renameShib = UtilIT.changeAuthenticatedUserIdentifier(usernameOfNonBcryptUserToConvert, newUsername, superuserApiToken);
renameShib.prettyPrint();
renameShib.then().assertThat()
.statusCode(OK.getStatusCode());

}

Expand Down