From 2599e774915682dde2a5ad95bb0113eba696dacd Mon Sep 17 00:00:00 2001 From: mposolda Date: Wed, 25 Mar 2015 12:37:33 +0100 Subject: [PATCH] Fix oracle --- .../resources/META-INF/jpa-changelog-1.2.0.Beta1.xml | 6 ++---- .../org/keycloak/models/cache/MemoryUserCache.java | 6 ++++-- ...grationUtils.java => DefaultMigrationProvider.java} | 10 +++++----- .../testsuite/broker/AbstractIdentityProviderTest.java | 2 +- .../testsuite/broker/IdentityProviderHintTest.java | 5 +++++ .../broker/SAMLKeyCloakServerBrokerBasicTest.java | 10 +++++++--- .../SAMLKeyCloakServerBrokerWithSignatureTest.java | 10 +++++++--- 7 files changed, 31 insertions(+), 18 deletions(-) rename services/src/main/java/org/keycloak/services/util/{MigrationUtils.java => DefaultMigrationProvider.java} (87%) diff --git a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.Beta1.xml b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.Beta1.xml index 9459ca3d53..079bee81dd 100755 --- a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.Beta1.xml +++ b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.Beta1.xml @@ -154,11 +154,9 @@ - - + - - + diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/MemoryUserCache.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/MemoryUserCache.java index 360a02d3fc..dcbf2c987d 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/MemoryUserCache.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/MemoryUserCache.java @@ -25,7 +25,9 @@ public class MemoryUserCache implements UserCache { @Override public CachedUser put(String key, CachedUser value) { - usersByUsername.put(value.getUsername(), value); + if (value.getUsername() != null) { + usersByUsername.put(value.getUsername(), value); + } if (value.getEmail() != null) { usersByEmail.put(value.getEmail(), value); } @@ -57,7 +59,7 @@ public class MemoryUserCache implements UserCache { } private void removeUser(CachedUser value) { - usersByUsername.remove(value.getUsername()); + if (value.getUsername() != null) usersByUsername.remove(value.getUsername()); if (value.getEmail() != null) usersByEmail.remove(value.getEmail()); } } diff --git a/services/src/main/java/org/keycloak/services/util/MigrationUtils.java b/services/src/main/java/org/keycloak/services/util/DefaultMigrationProvider.java similarity index 87% rename from services/src/main/java/org/keycloak/services/util/MigrationUtils.java rename to services/src/main/java/org/keycloak/services/util/DefaultMigrationProvider.java index f2a16763d9..178bf7a982 100644 --- a/services/src/main/java/org/keycloak/services/util/MigrationUtils.java +++ b/services/src/main/java/org/keycloak/services/util/DefaultMigrationProvider.java @@ -19,9 +19,9 @@ import org.keycloak.provider.ProviderFactory; * * @author Marek Posolda */ -public class MigrationUtils { +public class DefaultMigrationProvider { - private MigrationUtils() {} + private DefaultMigrationProvider() {} /** * @@ -29,11 +29,11 @@ public class MigrationUtils { * @param claimMask mask used on ClientModel in 1.1.0 * @return set of 1.2.0.Beta1 protocol mappers corresponding to given claimMask */ - public static Collection getMappersForClaimMask(KeycloakSession session, Long claimMask) { + public static List getMappersForClaimMask(KeycloakSession session, Long claimMask) { Map allMappers = getAllDefaultMappers(session); if (claimMask == null) { - return allMappers.values(); + return new ArrayList(allMappers.values()); } if (!ClaimMask.hasUsername(claimMask)) { @@ -48,7 +48,7 @@ public class MigrationUtils { allMappers.remove(OIDCLoginProtocolFactory.GIVEN_NAME); } - return allMappers.values(); + return new ArrayList(allMappers.values()); } private static Map getAllDefaultMappers(KeycloakSession session) { diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java index e6dbfcd7a5..3fa93f129c 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java @@ -153,7 +153,7 @@ public abstract class AbstractIdentityProviderTest { UserModel federatedUser = assertSuccessfulAuthentication(identityProviderModel, "test-user-noemail", null); - federatedUser.getRequiredActions().contains(RequiredAction.VERIFY_EMAIL); + assertTrue(federatedUser.getRequiredActions().contains(RequiredAction.VERIFY_EMAIL)); } finally { getRealm().setVerifyEmail(false); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/IdentityProviderHintTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/IdentityProviderHintTest.java index 20be993453..96818736b7 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/IdentityProviderHintTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/IdentityProviderHintTest.java @@ -38,6 +38,11 @@ public class IdentityProviderHintTest { protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) { server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json")); } + + @Override + protected String[] getTestRealms() { + return new String[] { "realm-with-oidc-identity-provider" }; + } }; @Rule diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerBasicTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerBasicTest.java index 4b235eb12e..ffddbd226a 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerBasicTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerBasicTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -55,9 +56,12 @@ public class SAMLKeyCloakServerBrokerBasicTest extends AbstractIdentityProviderT if (identityProviderModel.isUpdateProfileFirstLogin()) { super.doAssertFederatedUser(federatedUser, identityProviderModel, expectedEmail); } else { - if (expectedEmail == null) - expectedEmail = ""; - assertEquals(expectedEmail, federatedUser.getEmail()); + if (expectedEmail == null) { + // Need to handle differences for various databases (like Oracle) + assertTrue(federatedUser.getEmail() == null || federatedUser.getEmail().equals("")); + } else { + assertEquals(expectedEmail, federatedUser.getEmail()); + } assertNull(federatedUser.getFirstName()); assertNull(federatedUser.getLastName()); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerWithSignatureTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerWithSignatureTest.java index 5c7ac76ae1..bef306cbbe 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerWithSignatureTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerWithSignatureTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -54,9 +55,12 @@ public class SAMLKeyCloakServerBrokerWithSignatureTest extends AbstractIdentityP if (identityProviderModel.isUpdateProfileFirstLogin()) { super.doAssertFederatedUser(federatedUser, identityProviderModel, expectedEmail); } else { - if (expectedEmail == null) - expectedEmail = ""; - assertEquals(expectedEmail, federatedUser.getEmail()); + if (expectedEmail == null) { + // Need to handle differences for various databases (like Oracle) + assertTrue(federatedUser.getEmail() == null || federatedUser.getEmail().equals("")); + } else { + assertEquals(expectedEmail, federatedUser.getEmail()); + } assertNull(federatedUser.getFirstName()); assertNull(federatedUser.getLastName()); }