Merge pull request #3615 from abstractj/KEYCLOAK-3560

[KEYCLOAK-3560]: Unable to import exported users which contain terms_and_conditions required action
This commit is contained in:
Bill Burke 2016-12-06 22:07:58 -05:00 committed by GitHub
commit 31d2cde6e5
3 changed files with 49 additions and 2 deletions

View file

@ -1366,7 +1366,7 @@ public class RepresentationToModel {
} }
if (userRep.getRequiredActions() != null) { if (userRep.getRequiredActions() != null) {
for (String requiredAction : userRep.getRequiredActions()) { for (String requiredAction : userRep.getRequiredActions()) {
user.addRequiredAction(UserModel.RequiredAction.valueOf(requiredAction)); user.addRequiredAction(UserModel.RequiredAction.valueOf(requiredAction.toUpperCase()));
} }
} }
createCredentials(userRep, session, newRealm, user); createCredentials(userRep, session, newRealm, user);

View file

@ -121,6 +121,6 @@ public interface UserModel extends RoleMapperModel {
void setServiceAccountClientLink(String clientInternalId); void setServiceAccountClientLink(String clientInternalId);
public static enum RequiredAction { public static enum RequiredAction {
VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD, TERMS_AND_CONDITIONS
} }
} }

View file

@ -197,6 +197,20 @@ public class PartialImportTest extends AbstractAuthTest {
piRep.setUsers(users); piRep.setUsers(users);
} }
private void addUsersWithTermsAndConditions() {
List<UserRepresentation> users = new ArrayList<>();
List<String> requiredActions = new ArrayList<>();
requiredActions.add("terms_and_conditions");
for (int i = 0; i < NUM_ENTITIES; i++) {
UserRepresentation user = createUserRepresentation(USER_PREFIX + i, USER_PREFIX + i + "@foo.com", "foo", "bar", true);
user.setRequiredActions(requiredActions);
users.add(user);
}
piRep.setUsers(users);
}
private void addGroups() { private void addGroups() {
List<GroupRepresentation> groups = new ArrayList<>(); List<GroupRepresentation> groups = new ArrayList<>();
@ -306,6 +320,39 @@ public class PartialImportTest extends AbstractAuthTest {
} }
} }
@Test
public void testAddUsersWithTermsAndConditions() {
assertAdminEvents.clear();
setFail();
addUsersWithTermsAndConditions();
PartialImportResults results = doImport();
assertEquals(NUM_ENTITIES, results.getAdded());
// Need to do this way as admin events from partial import are unsorted
Set<String> userIds = new HashSet<>();
for (int i=0 ; i<NUM_ENTITIES ; i++) {
AdminEventRepresentation adminEvent = assertAdminEvents.poll();
Assert.assertEquals(realmId, adminEvent.getRealmId());
Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
String userId = adminEvent.getResourcePath().substring(6);
userIds.add(userId);
}
assertAdminEvents.assertEmpty();
for (PartialImportResult result : results.getResults()) {
String id = result.getId();
UserResource userRsc = testRealmResource().users().get(id);
UserRepresentation user = userRsc.toRepresentation();
assertTrue(user.getUsername().startsWith(USER_PREFIX));
Assert.assertTrue(userIds.contains(id));
}
}
@Test @Test
public void testAddClients() { public void testAddClients() {
setFail(); setFail();