[KEYCLOAK-3560]: Unable to import exported users which contain terms_and_conditions required action
This commit is contained in:
parent
77d17de14d
commit
15f23eb045
3 changed files with 49 additions and 2 deletions
|
@ -1366,7 +1366,7 @@ public class RepresentationToModel {
|
|||
}
|
||||
if (userRep.getRequiredActions() != null) {
|
||||
for (String requiredAction : userRep.getRequiredActions()) {
|
||||
user.addRequiredAction(UserModel.RequiredAction.valueOf(requiredAction));
|
||||
user.addRequiredAction(UserModel.RequiredAction.valueOf(requiredAction.toUpperCase()));
|
||||
}
|
||||
}
|
||||
createCredentials(userRep, session, newRealm, user);
|
||||
|
|
|
@ -121,6 +121,6 @@ public interface UserModel extends RoleMapperModel {
|
|||
void setServiceAccountClientLink(String clientInternalId);
|
||||
|
||||
public static enum RequiredAction {
|
||||
VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD
|
||||
VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD, TERMS_AND_CONDITIONS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,6 +197,20 @@ public class PartialImportTest extends AbstractAuthTest {
|
|||
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() {
|
||||
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
|
||||
public void testAddClients() {
|
||||
setFail();
|
||||
|
|
Loading…
Reference in a new issue