From 094cf675c739ec59fdb2b29405cc64ac9425d9e6 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 19 Jun 2014 08:50:19 -0400 Subject: [PATCH] user cache --- .../models/cache/entities/CachedRealm.java | 9 -- .../models/cache/entities/CachedUser.java | 103 ++++++++++++++++++ 2 files changed, 103 insertions(+), 9 deletions(-) create mode 100755 model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java index cd748eb21d..08f9b97bd8 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java @@ -74,7 +74,6 @@ public class CachedRealm { private Set auditListeners = new HashSet(); private List defaultRoles = new LinkedList(); private Map realmRoles = new HashMap(); - private Set rolesById = new HashSet(); private Map applications = new HashMap(); private Map clients = new HashMap(); @@ -134,7 +133,6 @@ public class CachedRealm { for (RoleModel role : model.getRoles()) { realmRoles.put(role.getName(), role.getId()); - rolesById.add(role.getId()); CachedRole cachedRole = new CachedRealmRole(role); cache.addCachedRole(cachedRole); } @@ -143,9 +141,6 @@ public class CachedRealm { applications.put(app.getName(), app.getId()); CachedApplication cachedApp = new CachedApplication(cache, delegate, model, app); cache.addCachedApplication(cachedApp); - for (String roleId : cachedApp.getRoles().values()) { - rolesById.add(roleId); - } } for (OAuthClientModel client : model.getOAuthClients()) { @@ -177,10 +172,6 @@ public class CachedRealm { return realmRoles; } - public Set getRolesById() { - return rolesById; - } - public Map getApplications() { return applications; } diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java new file mode 100755 index 0000000000..557e7e9feb --- /dev/null +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java @@ -0,0 +1,103 @@ +package org.keycloak.models.cache.entities; + +import org.keycloak.models.RoleModel; +import org.keycloak.models.UserCredentialValueModel; +import org.keycloak.models.UserModel; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Bill Burke + * @version $Revision: 1 $ + */ +public class CachedUser { + private String id; + private String loginName; + private String firstName; + private String lastName; + private String email; + private boolean emailVerified; + private int notBefore; + private List credentials = new LinkedList(); + private boolean enabled; + private boolean totp; + private Map attributes = new HashMap(); + private Set requiredActions = new HashSet(); + private Set roleMappings = new HashSet(); + + + public CachedUser(UserModel user) { + this.id = user.getId(); + this.loginName = user.getLoginName(); + this.firstName = user.getFirstName(); + this.lastName = user.getLastName(); + this.attributes.putAll(user.getAttributes()); + this.email = user.getEmail(); + this.emailVerified = user.isEmailVerified(); + this.notBefore = user.getNotBefore(); + this.credentials.addAll(user.getCredentialsDirectly()); + this.enabled = user.isEnabled(); + this.totp = user.isTotp(); + this.requiredActions.addAll(user.getRequiredActions()); + for (RoleModel role : user.getRoleMappings()) { + roleMappings.add(role.getId()); + } + } + + public String getId() { + return id; + } + + public String getLoginName() { + return loginName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getEmail() { + return email; + } + + public boolean isEmailVerified() { + return emailVerified; + } + + public int getNotBefore() { + return notBefore; + } + + public List getCredentials() { + return credentials; + } + + public boolean isEnabled() { + return enabled; + } + + public boolean isTotp() { + return totp; + } + + public Map getAttributes() { + return attributes; + } + + public Set getRequiredActions() { + return requiredActions; + } + + public Set getRoleMappings() { + return roleMappings; + } +}