Merge pull request #797 from mposolda/dynamic-adapter-registration
KEYCLOAK-778 InfinispanUserCacheProvider not working on EAP6 / AS7
This commit is contained in:
commit
1e68f63715
1 changed files with 31 additions and 6 deletions
|
@ -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<String, CachedUser> 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,8 +76,19 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact
|
|||
|
||||
@CacheEntryCreated
|
||||
public void userCreated(CacheEntryCreatedEvent<String, CachedUser> event) {
|
||||
if (!event.isPre() && event.getValue() != null) {
|
||||
CachedUser cachedUser = event.getValue();
|
||||
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) {
|
||||
|
@ -72,6 +96,7 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CacheEntryRemoved
|
||||
public void userRemoved(CacheEntryRemovedEvent<String, CachedUser> event) {
|
||||
|
|
Loading…
Reference in a new issue