Moved audit/tests and model/tests to testsuite
This commit is contained in:
1 parent
6e18a16f78
commit
511cc483cb
51 files changed
+304
-909
No files matched your search
+14
-2
@@ -243,14 +243,18 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
public RoleModel getRoleById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getRoleById(id, realm);
|
||||
CachedRole cached = cache.getRole(id);
|
||||
if (cached != null && !cached.getRealm().equals(realm.getId())) {
|
||||
cached = null;
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
RoleModel model = getDelegate().getRoleById(id, realm);
|
||||
if (model == null) return null;
|
||||
if (roleInvalidations.contains(id)) return model;
|
||||
if (model.getContainer() instanceof ApplicationModel) {
|
||||
cached = new CachedApplicationRole(((ApplicationModel) model.getContainer()).getId(), model);
|
||||
cached = new CachedApplicationRole(((ApplicationModel) model.getContainer()).getId(), model, realm);
|
||||
} else {
|
||||
cached = new CachedRealmRole(model);
|
||||
cached = new CachedRealmRole(model, realm);
|
||||
}
|
||||
cache.addCachedRole(cached);
|
||||
|
||||
@@ -268,6 +272,10 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getApplicationById(id, realm);
|
||||
CachedApplication cached = cache.getApplication(id);
|
||||
if (cached != null && !cached.getRealm().equals(realm.getId())) {
|
||||
cached = null;
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
ApplicationModel model = getDelegate().getApplicationById(id, realm);
|
||||
if (model == null) return null;
|
||||
@@ -288,6 +296,10 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getOAuthClientById(id, realm);
|
||||
CachedOAuthClient cached = cache.getOAuthClient(id);
|
||||
if (cached != null && !cached.getRealm().equals(realm.getId())) {
|
||||
cached = null;
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
OAuthClientModel model = getDelegate().getOAuthClientById(id, realm);
|
||||
if (model == null) return null;
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,6 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
@@ -726,8 +727,7 @@ public class RealmAdapter implements RealmModel {
|
||||
|
||||
@Override
|
||||
public ApplicationModel getMasterAdminApp() {
|
||||
if (updated != null) return updated.getMasterAdminApp();
|
||||
return getApplicationById(cached.getMasterAdminApp());
|
||||
return cacheSession.getRealm(Config.getAdminRealm()).getApplicationById(cached.getMasterAdminApp());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class CachedApplication extends CachedClient {
|
||||
bearerOnly = model.isBearerOnly();
|
||||
for (RoleModel role : model.getRoles()) {
|
||||
roles.put(role.getName(), role.getId());
|
||||
cache.addCachedRole(new CachedApplicationRole(id, role));
|
||||
cache.addCachedRole(new CachedApplicationRole(id, role, realm));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
|
||||
/**
|
||||
@@ -9,8 +10,8 @@ import org.keycloak.models.RoleModel;
|
||||
public class CachedApplicationRole extends CachedRole {
|
||||
private final String appId;
|
||||
|
||||
public CachedApplicationRole(String appId, RoleModel model) {
|
||||
super(model);
|
||||
public CachedApplicationRole(String appId, RoleModel model, RealmModel realm) {
|
||||
super(model, realm);
|
||||
this.appId = appId;
|
||||
|
||||
}
|
||||
|
||||
+6
@@ -16,6 +16,7 @@ import java.util.Set;
|
||||
public class CachedClient {
|
||||
protected String id;
|
||||
protected String name;
|
||||
protected String realm;
|
||||
protected long allowedClaimsMask;
|
||||
protected Set<String> redirectUris = new HashSet<String>();
|
||||
protected boolean enabled;
|
||||
@@ -30,6 +31,7 @@ public class CachedClient {
|
||||
id = model.getId();
|
||||
secret = model.getSecret();
|
||||
name = model.getClientId();
|
||||
this.realm = realm.getId();
|
||||
enabled = model.isEnabled();
|
||||
notBefore = model.getNotBefore();
|
||||
directGrantsOnly = model.isDirectGrantsOnly();
|
||||
@@ -51,6 +53,10 @@ public class CachedClient {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
||||
public long getAllowedClaimsMask() {
|
||||
return allowedClaimsMask;
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ public class CachedRealm {
|
||||
|
||||
for (RoleModel role : model.getRoles()) {
|
||||
realmRoles.put(role.getName(), role.getId());
|
||||
CachedRole cachedRole = new CachedRealmRole(role);
|
||||
CachedRole cachedRole = new CachedRealmRole(role, model);
|
||||
cache.addCachedRole(cachedRole);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
|
||||
/**
|
||||
@@ -9,8 +10,8 @@ import org.keycloak.models.RoleModel;
|
||||
public class CachedRealmRole extends CachedRole {
|
||||
|
||||
|
||||
public CachedRealmRole(RoleModel model) {
|
||||
super(model);
|
||||
public CachedRealmRole(RoleModel model, RealmModel realm) {
|
||||
super(model, realm);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -1,5 +1,6 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -12,15 +13,17 @@ import java.util.Set;
|
||||
public class CachedRole {
|
||||
final protected String id;
|
||||
final protected String name;
|
||||
final protected String realm;
|
||||
final protected String description;
|
||||
final protected boolean composite;
|
||||
final protected Set<String> composites = new HashSet<String>();
|
||||
|
||||
public CachedRole(RoleModel model) {
|
||||
public CachedRole(RoleModel model, RealmModel realm) {
|
||||
composite = model.isComposite();
|
||||
description = model.getDescription();
|
||||
id = model.getId();
|
||||
name = model.getName();
|
||||
this.realm = realm.getId();
|
||||
if (composite) {
|
||||
for (RoleModel child : model.getComposites()) {
|
||||
composites.add(child.getId());
|
||||
@@ -37,6 +40,10 @@ public class CachedRole {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user