protected UserModel getUserAdapter(RealmModel realm, String userId, Long loaded, UserModel delegate) { CachedUser cached = cache.get(userId, CachedUser.class); if (cached == null) { return cacheUser(realm, delegate, loaded); } else { return validateCache(realm, cached); } }
@Override public UserModel getUserById(String id, RealmModel realm) { logger.tracev("getuserById {0}", id); if (isRegisteredForInvalidation(realm, id)) { logger.trace("registered for invalidation return delegate"); return getDelegate().getUserById(id, realm); } if (managedUsers.containsKey(id)) { logger.trace("return managedusers"); return managedUsers.get(id); } CachedUser cached = cache.get(id, CachedUser.class); UserModel adapter = null; if (cached == null) { logger.trace("not cached"); Long loaded = cache.getCurrentRevision(id); UserModel delegate = getDelegate().getUserById(id, realm); if (delegate == null) { logger.trace("delegate returning null"); return null; } adapter = cacheUser(realm, delegate, loaded); } else { adapter = validateCache(realm, cached); } managedUsers.put(id, adapter); return adapter; }
@Override public UserConsentModel getConsentByClient(RealmModel realm, String userId, String clientId) { logger.tracev("getConsentByClient: {0}", userId); String cacheKey = getConsentCacheKey(userId); if (realmInvalidations.contains(realm.getId()) || invalidations.contains(userId) || invalidations.contains(cacheKey)) { return getDelegate().getConsentByClient(realm, userId, clientId); } CachedUserConsents cached = cache.get(cacheKey, CachedUserConsents.class); if (cached == null) { Long loaded = cache.getCurrentRevision(cacheKey); List<UserConsentModel> consents = getDelegate().getConsents(realm, userId); cached = new CachedUserConsents(loaded, cacheKey, realm, consents); cache.addRevisioned(cached, startupRevision); } CachedUserConsent cachedConsent = cached.getConsents().get(clientId); if (cachedConsent == null) return null; return toConsentModel(realm, cachedConsent); }
@Override public List<UserConsentModel> getConsents(RealmModel realm, String userId) { logger.tracev("getConsents: {0}", userId); String cacheKey = getConsentCacheKey(userId); if (realmInvalidations.contains(realm.getId()) || invalidations.contains(userId) || invalidations.contains(cacheKey)) { return getDelegate().getConsents(realm, userId); } CachedUserConsents cached = cache.get(cacheKey, CachedUserConsents.class); if (cached == null) { Long loaded = cache.getCurrentRevision(cacheKey); List<UserConsentModel> consents = getDelegate().getConsents(realm, userId); cached = new CachedUserConsents(loaded, cacheKey, realm, consents); cache.addRevisioned(cached, startupRevision); return consents; } else { List<UserConsentModel> result = new LinkedList<>(); for (CachedUserConsent cachedConsent : cached.getConsents().values()) { UserConsentModel consent = toConsentModel(realm, cachedConsent); if (consent != null) { result.add(consent); } } return result; } }
@Override public Set<FederatedIdentityModel> getFederatedIdentities(UserModel user, RealmModel realm) { logger.tracev("getFederatedIdentities: {0}", user.getUsername()); String cacheKey = getFederatedIdentityLinksCacheKey(user.getId()); if (realmInvalidations.contains(realm.getId()) || invalidations.contains(user.getId()) || invalidations.contains(cacheKey)) { return getDelegate().getFederatedIdentities(user, realm); } CachedFederatedIdentityLinks cachedLinks = cache.get(cacheKey, CachedFederatedIdentityLinks.class); if (cachedLinks == null) { Long loaded = cache.getCurrentRevision(cacheKey); Set<FederatedIdentityModel> federatedIdentities = getDelegate().getFederatedIdentities(user, realm); cachedLinks = new CachedFederatedIdentityLinks(loaded, cacheKey, realm, federatedIdentities); cache.addRevisioned(cachedLinks, startupRevision); return federatedIdentities; } else { return new HashSet<>(cachedLinks.getFederatedIdentities()); } }
return getDelegate().getUserByEmail(email, realm); UserListQuery query = cache.get(cacheKey, UserListQuery.class);
return getDelegate().getUserByFederatedIdentity(socialLink, realm); UserListQuery query = cache.get(cacheKey, UserListQuery.class);
return getDelegate().getUserByUsername(username, realm); UserListQuery query = cache.get(cacheKey, UserListQuery.class);
return getDelegate().getServiceAccount(client); UserListQuery query = cache.get(cacheKey, UserListQuery.class);