From 15f23eb045e93a21b79334a897355147169a7c9a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 6 Dec 2016 12:08:48 -0200 Subject: [PATCH] [KEYCLOAK-3560]: Unable to import exported users which contain terms_and_conditions required action --- .../models/utils/RepresentationToModel.java | 2 +- .../java/org/keycloak/models/UserModel.java | 2 +- .../partialimport/PartialImportTest.java | 47 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index c0bfda13ca..d8b934fef9 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -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); diff --git a/server-spi/src/main/java/org/keycloak/models/UserModel.java b/server-spi/src/main/java/org/keycloak/models/UserModel.java index 15cc296ebd..91b3769873 100755 --- a/server-spi/src/main/java/org/keycloak/models/UserModel.java +++ b/server-spi/src/main/java/org/keycloak/models/UserModel.java @@ -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 } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java index bd3d785e78..783adbfaf2 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java @@ -197,6 +197,20 @@ public class PartialImportTest extends AbstractAuthTest { piRep.setUsers(users); } + private void addUsersWithTermsAndConditions() { + List users = new ArrayList<>(); + List 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 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 userIds = new HashSet<>(); + for (int i=0 ; i