From d9331998c3feecc86c2b3fefd09a070c06485208 Mon Sep 17 00:00:00 2001 From: mposolda Date: Thu, 23 Oct 2014 11:36:06 +0200 Subject: [PATCH 1/2] KEYCLOAK-778 InfinispanUserCacheProvider not working on EAP6 / AS7 --- .../InfinispanCacheUserProviderFactory.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/model/invalidation-cache/infinispan/src/main/java/org/keycloak/models/cache/infinispan/InfinispanCacheUserProviderFactory.java b/model/invalidation-cache/infinispan/src/main/java/org/keycloak/models/cache/infinispan/InfinispanCacheUserProviderFactory.java index 8fed69e6ee..c0ce985856 100755 --- a/model/invalidation-cache/infinispan/src/main/java/org/keycloak/models/cache/infinispan/InfinispanCacheUserProviderFactory.java +++ b/model/invalidation-cache/infinispan/src/main/java/org/keycloak/models/cache/infinispan/InfinispanCacheUserProviderFactory.java @@ -27,6 +27,9 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact protected final RealmLookup emailLookup = new RealmLookup(); + // Method CacheEntryCreatedEvent.getValue is available from ispn 6 (EAP6 and AS7 are on ispn 5) + private boolean isNewInfinispan; + @Override public CacheUserProvider create(KeycloakSession session) { lazyInit(session); @@ -37,6 +40,7 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact if (userCache == null) { synchronized (this) { if (userCache == null) { + checkIspnVersion(); Cache cache = session.getProvider(InfinispanConnectionProvider.class).getCache("users"); cache.addListener(new CacheListener()); userCache = new InfinispanUserCache(cache, usernameLookup, emailLookup); @@ -45,6 +49,15 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact } } + protected void checkIspnVersion() { + try { + CacheEntryCreatedEvent.class.getMethod("getValue"); + isNewInfinispan = true; + } catch (NoSuchMethodException nsme) { + isNewInfinispan = false; + } + } + @Override public void init(Config.Scope config) { } @@ -63,12 +76,24 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact @CacheEntryCreated public void userCreated(CacheEntryCreatedEvent event) { - if (!event.isPre() && event.getValue() != null) { - CachedUser cachedUser = event.getValue(); - String realm = cachedUser.getRealm(); - usernameLookup.put(realm, cachedUser.getUsername(), cachedUser.getId()); - if (cachedUser.getEmail() != null) { - emailLookup.put(realm, cachedUser.getEmail(), cachedUser.getId()); + if (!event.isPre()) { + + CachedUser cachedUser; + + // Try optimized version if available + if (isNewInfinispan) { + cachedUser = event.getValue(); + } else { + String userId = event.getKey(); + cachedUser = event.getCache().get(userId); + } + + if (cachedUser != null) { + String realm = cachedUser.getRealm(); + usernameLookup.put(realm, cachedUser.getUsername(), cachedUser.getId()); + if (cachedUser.getEmail() != null) { + emailLookup.put(realm, cachedUser.getEmail(), cachedUser.getId()); + } } } } From 319578f39062b098dcbcd4b34a38233f23a3e9f7 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Thu, 23 Oct 2014 20:42:45 +0200 Subject: [PATCH 2/2] KEYCLOAK-786 Value in input fields should be escaped --- .../src/main/resources/theme/account/base/account.ftl | 8 ++++---- .../resources/theme/login/base/login-update-profile.ftl | 6 +++--- .../src/main/resources/theme/login/base/login.ftl | 2 +- .../src/main/resources/theme/login/base/register.ftl | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/forms/common-themes/src/main/resources/theme/account/base/account.ftl b/forms/common-themes/src/main/resources/theme/account/base/account.ftl index f26f9206dc..0b8d18e301 100755 --- a/forms/common-themes/src/main/resources/theme/account/base/account.ftl +++ b/forms/common-themes/src/main/resources/theme/account/base/account.ftl @@ -20,7 +20,7 @@
- +
@@ -30,7 +30,7 @@
- +
@@ -41,7 +41,7 @@
- +
@@ -51,7 +51,7 @@
- +
diff --git a/forms/common-themes/src/main/resources/theme/login/base/login-update-profile.ftl b/forms/common-themes/src/main/resources/theme/login/base/login-update-profile.ftl index 1089e210d5..812e29eb70 100755 --- a/forms/common-themes/src/main/resources/theme/login/base/login-update-profile.ftl +++ b/forms/common-themes/src/main/resources/theme/login/base/login-update-profile.ftl @@ -11,7 +11,7 @@
- +
@@ -20,7 +20,7 @@
- +
@@ -29,7 +29,7 @@
- +
diff --git a/forms/common-themes/src/main/resources/theme/login/base/login.ftl b/forms/common-themes/src/main/resources/theme/login/base/login.ftl index 8ec24702ac..a1a3b23249 100755 --- a/forms/common-themes/src/main/resources/theme/login/base/login.ftl +++ b/forms/common-themes/src/main/resources/theme/login/base/login.ftl @@ -21,7 +21,7 @@
- +
diff --git a/forms/common-themes/src/main/resources/theme/login/base/register.ftl b/forms/common-themes/src/main/resources/theme/login/base/register.ftl index 0e17aa6634..113351b629 100755 --- a/forms/common-themes/src/main/resources/theme/login/base/register.ftl +++ b/forms/common-themes/src/main/resources/theme/login/base/register.ftl @@ -11,7 +11,7 @@
- +
@@ -20,7 +20,7 @@
- +
@@ -29,7 +29,7 @@
- +
@@ -38,7 +38,7 @@
- +