user cache

This commit is contained in:
Bill Burke 2014-06-19 08:50:19 -04:00
parent 1eafb01c8d
commit 094cf675c7
2 changed files with 103 additions and 9 deletions

View file

@ -74,7 +74,6 @@ public class CachedRealm {
private Set<String> auditListeners = new HashSet<String>();
private List<String> defaultRoles = new LinkedList<String>();
private Map<String, String> realmRoles = new HashMap<String, String>();
private Set<String> rolesById = new HashSet<String>();
private Map<String, String> applications = new HashMap<String, String>();
private Map<String, String> clients = new HashMap<String, String>();
@ -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<String> getRolesById() {
return rolesById;
}
public Map<String, String> getApplications() {
return applications;
}

View file

@ -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 <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @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<UserCredentialValueModel> credentials = new LinkedList<UserCredentialValueModel>();
private boolean enabled;
private boolean totp;
private Map<String, String> attributes = new HashMap<String, String>();
private Set<UserModel.RequiredAction> requiredActions = new HashSet<UserModel.RequiredAction>();
private Set<String> roleMappings = new HashSet<String>();
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<UserCredentialValueModel> getCredentials() {
return credentials;
}
public boolean isEnabled() {
return enabled;
}
public boolean isTotp() {
return totp;
}
public Map<String, String> getAttributes() {
return attributes;
}
public Set<UserModel.RequiredAction> getRequiredActions() {
return requiredActions;
}
public Set<String> getRoleMappings() {
return roleMappings;
}
}