KEYCLOAK-1421 patched source formatting

This commit is contained in:
Vlastimil Elias 2015-06-16 09:09:14 +02:00
parent 82282c1c75
commit 4e8c6b3fc4

View file

@ -1,21 +1,21 @@
package org.keycloak.models.cache; package org.keycloak.models.cache;
import org.keycloak.models.ClientModel;
import org.keycloak.models.UserConsentModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserCredentialValueModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.entities.CachedUser;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserConsentModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserCredentialValueModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.entities.CachedUser;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
@ -38,22 +38,18 @@ public class UserAdapter implements UserModel {
if (updated == null) { if (updated == null) {
userProviderCache.registerUserInvalidation(realm, getId()); userProviderCache.registerUserInvalidation(realm, getId());
updated = userProviderCache.getDelegate().getUserById(getId(), realm); updated = userProviderCache.getDelegate().getUserById(getId(), realm);
if (updated == null) if (updated == null) throw new IllegalStateException("Not found in database");
throw new IllegalStateException("Not found in database");
} }
} }
@Override @Override
public String getId() { public String getId() {
if (updated != null) if (updated != null) return updated.getId();
return updated.getId();
return cached.getId(); return cached.getId();
} }
@Override @Override
public String getUsername() { public String getUsername() {
if (updated != null) if (updated != null) return updated.getUsername();
return updated.getUsername();
return cached.getUsername(); return cached.getUsername();
} }
@ -76,15 +72,13 @@ public class UserAdapter implements UserModel {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
if (updated != null) if (updated != null) return updated.isEnabled();
return updated.isEnabled();
return cached.isEnabled(); return cached.isEnabled();
} }
@Override @Override
public boolean isTotp() { public boolean isTotp() {
if (updated != null) if (updated != null) return updated.isTotp();
return updated.isTotp();
return cached.isTotp(); return cached.isTotp();
} }
@ -108,22 +102,19 @@ public class UserAdapter implements UserModel {
@Override @Override
public String getAttribute(String name) { public String getAttribute(String name) {
if (updated != null) if (updated != null) return updated.getAttribute(name);
return updated.getAttribute(name);
return cached.getAttributes().get(name); return cached.getAttributes().get(name);
} }
@Override @Override
public Map<String, String> getAttributes() { public Map<String, String> getAttributes() {
if (updated != null) if (updated != null) return updated.getAttributes();
return updated.getAttributes();
return cached.getAttributes(); return cached.getAttributes();
} }
@Override @Override
public Set<String> getRequiredActions() { public Set<String> getRequiredActions() {
if (updated != null) if (updated != null) return updated.getRequiredActions();
return updated.getRequiredActions();
return cached.getRequiredActions(); return cached.getRequiredActions();
} }
@ -153,8 +144,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public String getFirstName() { public String getFirstName() {
if (updated != null) if (updated != null) return updated.getFirstName();
return updated.getFirstName();
return cached.getFirstName(); return cached.getFirstName();
} }
@ -166,8 +156,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public String getLastName() { public String getLastName() {
if (updated != null) if (updated != null) return updated.getLastName();
return updated.getLastName();
return cached.getLastName(); return cached.getLastName();
} }
@ -179,8 +168,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public String getEmail() { public String getEmail() {
if (updated != null) if (updated != null) return updated.getEmail();
return updated.getEmail();
return cached.getEmail(); return cached.getEmail();
} }
@ -192,8 +180,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public boolean isEmailVerified() { public boolean isEmailVerified() {
if (updated != null) if (updated != null) return updated.isEmailVerified();
return updated.isEmailVerified();
return cached.isEmailVerified(); return cached.isEmailVerified();
} }
@ -217,8 +204,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public List<UserCredentialValueModel> getCredentialsDirectly() { public List<UserCredentialValueModel> getCredentialsDirectly() {
if (updated != null) if (updated != null) return updated.getCredentialsDirectly();
return updated.getCredentialsDirectly();
return cached.getCredentials(); return cached.getCredentials();
} }
@ -230,8 +216,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public String getFederationLink() { public String getFederationLink() {
if (updated != null) if (updated != null) return updated.getFederationLink();
return updated.getFederationLink();
return cached.getFederationLink(); return cached.getFederationLink();
} }
@ -239,12 +224,11 @@ public class UserAdapter implements UserModel {
public void setFederationLink(String link) { public void setFederationLink(String link) {
getDelegateForUpdate(); getDelegateForUpdate();
updated.setFederationLink(link); updated.setFederationLink(link);
} }
@Override @Override
public Set<RoleModel> getRealmRoleMappings() { public Set<RoleModel> getRealmRoleMappings() {
if (updated != null) if (updated != null) return updated.getRealmRoleMappings();
return updated.getRealmRoleMappings();
Set<RoleModel> roleMappings = getRoleMappings(); Set<RoleModel> roleMappings = getRoleMappings();
Set<RoleModel> realmMappings = new HashSet<RoleModel>(); Set<RoleModel> realmMappings = new HashSet<RoleModel>();
for (RoleModel role : roleMappings) { for (RoleModel role : roleMappings) {
@ -260,8 +244,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public Set<RoleModel> getClientRoleMappings(ClientModel app) { public Set<RoleModel> getClientRoleMappings(ClientModel app) {
if (updated != null) if (updated != null) return updated.getClientRoleMappings(app);
return updated.getClientRoleMappings(app);
Set<RoleModel> roleMappings = getRoleMappings(); Set<RoleModel> roleMappings = getRoleMappings();
Set<RoleModel> appMappings = new HashSet<RoleModel>(); Set<RoleModel> appMappings = new HashSet<RoleModel>();
for (RoleModel role : roleMappings) { for (RoleModel role : roleMappings) {
@ -277,15 +260,12 @@ public class UserAdapter implements UserModel {
@Override @Override
public boolean hasRole(RoleModel role) { public boolean hasRole(RoleModel role) {
if (updated != null) if (updated != null) return updated.hasRole(role);
return updated.hasRole(role); if (cached.getRoleMappings().contains(role.getId())) return true;
if (cached.getRoleMappings().contains(role.getId()))
return true;
Set<RoleModel> mappings = getRoleMappings(); Set<RoleModel> mappings = getRoleMappings();
for (RoleModel mapping : mappings) { for (RoleModel mapping: mappings) {
if (mapping.hasRole(role)) if (mapping.hasRole(role)) return true;
return true;
} }
return false; return false;
} }
@ -298,8 +278,7 @@ public class UserAdapter implements UserModel {
@Override @Override
public Set<RoleModel> getRoleMappings() { public Set<RoleModel> getRoleMappings() {
if (updated != null) if (updated != null) return updated.getRoleMappings();
return updated.getRoleMappings();
Set<RoleModel> roles = new HashSet<RoleModel>(); Set<RoleModel> roles = new HashSet<RoleModel>();
for (String id : cached.getRoleMappings()) { for (String id : cached.getRoleMappings()) {
RoleModel roleById = keycloakSession.realms().getRoleById(id, realm); RoleModel roleById = keycloakSession.realms().getRoleById(id, realm);