@Override public void setFullScopeAllowed(boolean value) { getDelegateForUpdate(); updated.setFullScopeAllowed(value); }
@Override public int hashCode() { return getId().hashCode(); }
@Override public boolean hasScope(RoleModel role) { if (isUpdated()) return updated.hasScope(role); if (cached.isFullScopeAllowed() || cached.getScope().contains(role.getId())) return true; Set<RoleModel> roles = getScopeMappings(); for (RoleModel mapping : roles) { if (mapping.hasRole(role)) return true; } roles = getRoles(); if (roles.contains(role)) return true; for (RoleModel mapping : roles) { if (mapping.hasRole(role)) return true; } return false; }
@Override public Map<String, String> getAttributes() { if (isUpdated()) return updated.getAttributes(); Map<String, String> copy = new HashMap<String, String>(); copy.putAll(cached.getAttributes()); return copy; }
@Override public boolean hasScope(RoleModel role) { if (updated != null) return updated.hasScope(role); if (cached.isFullScopeAllowed() || cached.getScope().contains(role.getId())) return true; Set<RoleModel> roles = getScopeMappings(); for (RoleModel mapping : roles) { if (mapping.hasRole(role)) return true; } roles = getRoles(); if (roles.contains(role)) return true; for (RoleModel mapping : roles) { if (mapping.hasRole(role)) return true; } return false; }
@Override public RoleModel addRole(String id, String name) { return cacheSession.addClientRole(getRealm(), this, id, name); }
@Override public ClientModel getClientById(String id, RealmModel realm) { if (!cache.isEnabled()) return getDelegate().getClientById(id, realm); CachedClient cached = cache.getApplication(id); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { ClientModel model = getDelegate().getClientById(id, realm); if (model == null) return null; if (appInvalidations.contains(id)) return model; cached = new CachedClient(cache, getDelegate(), realm, model); cache.addCachedClient(cached); } else if (appInvalidations.contains(id)) { return getDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientAdapter adapter = new ClientAdapter(realm, cached, this, cache); managedApplications.put(id, adapter); return adapter; } @Override
public Set<RoleModel> getRealmScopeMappings() { Set<RoleModel> roleMappings = getScopeMappings(); Set<RoleModel> appRoles = new HashSet<RoleModel>(); for (RoleModel role : roleMappings) { RoleContainerModel container = role.getContainer(); if (container instanceof RealmModel) { if (((RealmModel) container).getId().equals(cachedRealm.getId())) { appRoles.add(role); } } } return appRoles; }
public boolean validateSecret(String secret) { return secret.equals(getSecret()); }
@Override public Map<String, ClientScopeModel> getClientScopes(boolean defaultScope, boolean filterByProtocol) { if (isUpdated()) return updated.getClientScopes(defaultScope, filterByProtocol); List<String> clientScopeIds = defaultScope ? cached.getDefaultClientScopesIds() : cached.getOptionalClientScopesIds(); // Defaults to openid-connect String clientProtocol = getProtocol() == null ? "openid-connect" : getProtocol(); Map<String, ClientScopeModel> clientScopes = new HashMap<>(); for (String scopeId : clientScopeIds) { ClientScopeModel clientScope = cacheSession.getClientScopeById(scopeId, cachedRealm); if (clientScope != null) { if (!filterByProtocol || clientScope.getProtocol().equals(clientProtocol)) { clientScopes.put(clientScope.getName(), clientScope); } } } return clientScopes; }
private void invalidateClient(String id) { invalidations.add(id); ClientModel adapter = managedApplications.get(id); if (adapter != null && adapter instanceof ClientAdapter) ((ClientAdapter)adapter).invalidate(); }
@Override public Map<String, String> getAuthenticationFlowBindingOverrides() { if (isUpdated()) return updated.getAuthenticationFlowBindingOverrides(); Map<String, String> copy = new HashMap<String, String>(); copy.putAll(cached.getAuthFlowBindings()); return copy; }
@Override public RoleModel addRole(String name) { return cacheSession.addClientRole(getRealm(), this, name); }
protected ClientModel cacheClient(RealmModel realm, ClientModel delegate, Long revision) { if (invalidations.contains(delegate.getId())) return delegate; StorageId storageId = new StorageId(delegate.getId()); CachedClient cached = null; ClientAdapter adapter = null; if (!storageId.isLocal()) { ComponentModel component = realm.getComponent(storageId.getProviderId()); ClientStorageProviderModel model = new ClientStorageProviderModel(component); if (!model.isEnabled()) { return delegate; } ClientStorageProviderModel.CachePolicy policy = model.getCachePolicy(); if (policy != null && policy == ClientStorageProviderModel.CachePolicy.NO_CACHE) { return delegate; } cached = new CachedClient(revision, realm, delegate); adapter = new ClientAdapter(realm, cached, this); long lifespan = model.getLifespan(); if (lifespan > 0) { cache.addRevisioned(cached, startupRevision, lifespan); } else { cache.addRevisioned(cached, startupRevision); } } else { cached = new CachedClient(revision, realm, delegate); adapter = new ClientAdapter(realm, cached, this); cache.addRevisioned(cached, startupRevision); } return adapter; }
public Set<RoleModel> getRealmScopeMappings() { Set<RoleModel> roleMappings = getScopeMappings(); Set<RoleModel> appRoles = new HashSet<RoleModel>(); for (RoleModel role : roleMappings) { RoleContainerModel container = role.getContainer(); if (container instanceof RealmModel) { if (((RealmModel) container).getId().equals(cachedRealm.getId())) { appRoles.add(role); } } } return appRoles; }
public boolean validateSecret(String secret) { return MessageDigest.isEqual(secret.getBytes(), getSecret().getBytes()); }
private void roleRemovalInvalidations(String roleId, String roleName, String roleContainerId) { Set<String> newInvalidations = new HashSet<>(); cache.roleRemoval(roleId, roleName, roleContainerId, newInvalidations); invalidations.addAll(newInvalidations); // need to make sure that scope and group mapping clients and groups are invalidated for (String id : newInvalidations) { ClientModel adapter = managedApplications.get(id); if (adapter != null && adapter instanceof ClientAdapter){ ((ClientAdapter)adapter).invalidate(); continue; } GroupAdapter group = managedGroups.get(id); if (group != null) { group.invalidate(); continue; } ClientScopeAdapter clientScope = managedClientScopes.get(id); if (clientScope != null) { clientScope.invalidate(); continue; } RoleAdapter role = managedRoles.get(id); if (role != null) { role.invalidate(); continue; } } }
@Override public void removeAttribute(String name) { getDelegateForUpdate(); updated.removeAttribute(name); }
@Override public String getAttribute(String name) { if (isUpdated()) return updated.getAttribute(name); return cached.getAttributes().get(name); }