Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PermissionTicketAdapter(CachedPermissionTicket cached, StoreFactoryCacheS
@Override
public PermissionTicket getDelegateForUpdate() {
if (updated == null) {
ResourceServer resourceServer = cacheSession.getResourceServerStoreDelegate().findById(cached.getResourceServerId());
ResourceServer resourceServer = cacheSession.getResourceServerStoreDelegate().findById(null, cached.getResourceServerId());
updated = cacheSession.getPermissionTicketStoreDelegate().findById(resourceServer, cached.getId());
if (updated == null) throw new IllegalStateException("Not found in database");
cacheSession.registerPermissionTicketInvalidation(cached.getId(), cached.getOwner(), cached.getRequester(), cached.getResourceId(), updated.getResource().getName(), cached.getScopeId(), cached.getResourceServerId());
Expand Down Expand Up @@ -70,7 +70,7 @@ public long getCacheTimestamp() {
protected boolean isUpdated() {
if (updated != null) return true;
if (!invalidated) return false;
ResourceServer resourceServer = cacheSession.getResourceServerStoreDelegate().findById(cached.getResourceServerId());
ResourceServer resourceServer = cacheSession.getResourceServerStoreDelegate().findById(null, cached.getResourceServerId());
updated = cacheSession.getPermissionTicketStoreDelegate().findById(resourceServer, cached.getId());
if (updated == null) throw new IllegalStateException("Not found in database");
return true;
Expand Down Expand Up @@ -122,13 +122,13 @@ public void setGrantedTimestamp(Long millis) {

@Override
public ResourceServer getResourceServer() {
return cacheSession.getResourceServerStore().findById(cached.getResourceServerId());
return cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId());
}

@Override
public Policy getPolicy() {
if (isUpdated()) return updated.getPolicy();
return cacheSession.getPolicyStore().findById(cacheSession.getResourceServerStore().findById(cached.getResourceServerId()), cached.getPolicy());
return cacheSession.getPolicyStore().findById(cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId()), cached.getPolicy());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public long getCacheTimestamp() {
protected boolean isUpdated() {
if (updated != null) return true;
if (!invalidated) return false;
updated = cacheSession.getPolicyStoreDelegate().findById(cacheSession.getResourceServerStore().findById(cached.getResourceServerId()), cached.getId());
updated = cacheSession.getPolicyStoreDelegate().findById(cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId()), cached.getId());
if (updated == null) throw new IllegalStateException("Not found in database");
return true;
}
Expand All @@ -112,7 +112,7 @@ public void setName(String name) {

@Override
public ResourceServer getResourceServer() {
return cacheSession.getResourceServerStore().findById(cached.getResourceServerId());
return cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId());
}

@Override
Expand Down Expand Up @@ -208,7 +208,7 @@ public Set<Policy> getAssociatedPolicies() {
PolicyStore policyStore = cacheSession.getPolicyStore();
String resourceServerId = cached.getResourceServerId();
for (String id : cached.getAssociatedPoliciesIds(modelSupplier)) {
Policy policy = policyStore.findById(cacheSession.getResourceServerStore().findById(resourceServerId), id);
Policy policy = policyStore.findById(cacheSession.getResourceServerStore().findById(null, resourceServerId), id);
cacheSession.cachePolicy(policy);
associatedPolicies.add(policy);
}
Expand Down Expand Up @@ -325,6 +325,6 @@ public int hashCode() {
}

private Policy getPolicyModel() {
return cacheSession.getPolicyStoreDelegate().findById(cacheSession.getResourceServerStore().findById(cached.getResourceServerId()), cached.getId());
return cacheSession.getPolicyStoreDelegate().findById(cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId()), cached.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void setIconUri(String iconUri) {

@Override
public ResourceServer getResourceServer() {
return cacheSession.getResourceServerStoreDelegate().findById(cached.getResourceServerId());
return cacheSession.getResourceServerStoreDelegate().findById(null, cached.getResourceServerId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.keycloak.authorization.model.CachedModel;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.models.ClientModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.infinispan.authorization.entities.CachedResourceServer;
import org.keycloak.representations.idm.authorization.DecisionStrategy;
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
Expand All @@ -40,7 +42,7 @@ public ResourceServerAdapter(CachedResourceServer cached, StoreFactoryCacheSessi
public ResourceServer getDelegateForUpdate() {
if (updated == null) {
cacheSession.registerResourceServerInvalidation(cached.getId());
updated = cacheSession.getResourceServerStoreDelegate().findById(cached.getId());
updated = cacheSession.getResourceServerStoreDelegate().findById(null, cached.getId());
if (updated == null) throw new IllegalStateException("Not found in database");
}
return updated;
Expand All @@ -67,7 +69,7 @@ public long getCacheTimestamp() {
protected boolean isUpdated() {
if (updated != null) return true;
if (!invalidated) return false;
updated = cacheSession.getResourceServerStoreDelegate().findById(cached.getId());
updated = cacheSession.getResourceServerStoreDelegate().findById(null, cached.getId());
if (updated == null) throw new IllegalStateException("Not found in database");
return true;
}
Expand Down Expand Up @@ -116,6 +118,16 @@ public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
updated.setDecisionStrategy(decisionStrategy);
}

@Override
public String getClientId() {
return getId();
}

@Override
public RealmModel getRealm() {
return getDelegateForUpdate().getRealm();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setIconUri(String iconUri) {

@Override
public ResourceServer getResourceServer() {
return cacheSession.getResourceServerStore().findById(cached.getResourceServerId());
return cacheSession.getResourceServerStore().findById(null, cached.getResourceServerId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakTransaction;
import org.keycloak.models.ModelException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.authorization.CachedStoreFactoryProvider;
import org.keycloak.models.cache.infinispan.authorization.entities.CachedPermissionTicket;
import org.keycloak.models.cache.infinispan.authorization.entities.CachedPolicy;
Expand Down Expand Up @@ -309,7 +310,7 @@ private Set<String> getResourceTypes(Set<String> resources, String serverId) {
return Collections.emptySet();
}

ResourceServer resourceServer = getResourceServerStore().findById(serverId);
ResourceServer resourceServer = getResourceServerStore().findById(null, serverId);
return resources.stream().map(resourceId -> {
Resource resource = getResourceStore().findById(resourceServer, resourceId);
String type = resource.getType();
Expand Down Expand Up @@ -450,7 +451,7 @@ public ResourceServer create(ClientModel client) {
public void delete(ClientModel client) {
String id = client.getId();
if (id == null) return;
ResourceServer server = findById(id);
ResourceServer server = findById(null, id);
if (server == null) return;

cache.invalidateObject(id);
Expand All @@ -461,7 +462,7 @@ public void delete(ClientModel client) {
}

@Override
public ResourceServer findById(String id) {
public ResourceServer findById(RealmModel realm, String id) {
if (id == null) return null;
CachedResourceServer cached = cache.get(id, CachedResourceServer.class);
if (cached != null) {
Expand All @@ -471,7 +472,7 @@ public ResourceServer findById(String id) {
if (cached == null) {
Long loaded = cache.getCurrentRevision(id);
if (! modelMightExist(id)) return null;
ResourceServer model = getResourceServerStoreDelegate().findById(id);
ResourceServer model = getResourceServerStoreDelegate().findById(realm, id);
if (model == null) {
setModelDoesNotExists(id, loaded);
return null;
Expand All @@ -480,7 +481,7 @@ public ResourceServer findById(String id) {
cached = new CachedResourceServer(loaded, model);
cache.addRevisioned(cached, startupRevision);
} else if (invalidations.contains(id)) {
return getResourceServerStoreDelegate().findById(id);
return getResourceServerStoreDelegate().findById(realm, id);
} else if (managedResourceServers.containsKey(id)) {
return managedResourceServers.get(id);
}
Expand All @@ -491,7 +492,7 @@ public ResourceServer findById(String id) {

@Override
public ResourceServer findByClient(ClientModel client) {
return findById(client.getId());
return findById(null, client.getId());
}
}

Expand Down Expand Up @@ -1238,13 +1239,13 @@ public List<PermissionTicket> findGranted(ResourceServer resourceServer, String
}

@Override
public List<Resource> findGrantedResources(String requester, String name, Integer first, Integer max) {
return getPermissionTicketStoreDelegate().findGrantedResources(requester, name, first, max);
public List<Resource> findGrantedResources(RealmModel realm, String requester, String name, Integer first, Integer max) {
return getPermissionTicketStoreDelegate().findGrantedResources(realm, requester, name, first, max);
}

@Override
public List<Resource> findGrantedOwnerResources(String owner, Integer firstResult, Integer maxResults) {
return getPermissionTicketStoreDelegate().findGrantedOwnerResources(owner, firstResult, maxResults);
public List<Resource> findGrantedOwnerResources(RealmModel realm, String owner, Integer firstResult, Integer maxResults) {
return getPermissionTicketStoreDelegate().findGrantedOwnerResources(realm, owner, firstResult, maxResults);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.common.util.Time;
import org.keycloak.models.RealmModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import javax.persistence.LockModeType;

Expand Down Expand Up @@ -290,7 +291,7 @@ public List<PermissionTicket> findGranted(ResourceServer resourceServer, String
}

@Override
public List<Resource> findGrantedResources(String requester, String name, Integer first, Integer max) {
public List<Resource> findGrantedResources(RealmModel realm, String requester, String name, Integer first, Integer max) {
TypedQuery<String> query = name == null ?
entityManager.createNamedQuery("findGrantedResources", String.class) :
entityManager.createNamedQuery("findGrantedResourcesByName", String.class);
Expand Down Expand Up @@ -318,7 +319,7 @@ public List<Resource> findGrantedResources(String requester, String name, Intege
}

@Override
public List<Resource> findGrantedOwnerResources(String owner, Integer firstResult, Integer maxResults) {
public List<Resource> findGrantedOwnerResources(RealmModel realm, String owner, Integer firstResult, Integer maxResults) {
TypedQuery<String> query = entityManager.createNamedQuery("findGrantedOwnerResources", String.class);

query.setFlushMode(FlushModeType.COMMIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.store.ResourceServerStore;
import org.keycloak.models.ModelException;
import org.keycloak.models.RealmModel;
import org.keycloak.storage.StorageId;

import javax.persistence.EntityManager;
Expand Down Expand Up @@ -58,7 +59,7 @@ public ResourceServer create(ClientModel client) {

this.entityManager.persist(entity);

return new ResourceServerAdapter(entity, entityManager, provider.getStoreFactory());
return new ResourceServerAdapter(client.getRealm(), entity, entityManager, provider.getStoreFactory());
}

@Override
Expand Down Expand Up @@ -122,14 +123,14 @@ public void delete(ClientModel client) {
}

@Override
public ResourceServer findById(String id) {
public ResourceServer findById(RealmModel realm, String id) {
ResourceServerEntity entity = entityManager.find(ResourceServerEntity.class, id);
if (entity == null) return null;
return new ResourceServerAdapter(entity, entityManager, provider.getStoreFactory());
return new ResourceServerAdapter(provider.getRealm(), entity, entityManager, provider.getStoreFactory());
}

@Override
public ResourceServer findByClient(ClientModel client) {
return findById(client.getId());
return findById(null, client.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import javax.persistence.EntityManager;

import org.keycloak.authorization.AuthorizationProvider;
import org.keycloak.authorization.jpa.entities.PermissionTicketEntity;
import org.keycloak.authorization.jpa.entities.PolicyEntity;
import org.keycloak.authorization.jpa.entities.ScopeEntity;
Expand Down Expand Up @@ -91,7 +90,7 @@ public void setGrantedTimestamp(Long millis) {

@Override
public ResourceServer getResourceServer() {
return storeFactory.getResourceServerStore().findById(entity.getResourceServer().getId());
return storeFactory.getResourceServerStore().findById(null, entity.getResourceServer().getId());
}

@Override
Expand All @@ -102,7 +101,7 @@ public Policy getPolicy() {
return null;
}

ResourceServer resourceServer = storeFactory.getResourceServerStore().findById(entity.getResourceServer().getId());
ResourceServer resourceServer = storeFactory.getResourceServerStore().findById(null, entity.getResourceServer().getId());
return storeFactory.getPolicyStore().findById(resourceServer, policy.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void setDescription(String description) {

@Override
public ResourceServer getResourceServer() {
return storeFactory.getResourceServerStore().findById(entity.getResourceServer().getId());
return storeFactory.getResourceServerStore().findById(null, entity.getResourceServer().getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void setIconUri(String iconUri) {

@Override
public ResourceServer getResourceServer() {
return storeFactory.getResourceServerStore().findById(entity.getResourceServer());
return storeFactory.getResourceServerStore().findById(null, entity.getResourceServer());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.keycloak.authorization.model.AbstractAuthorizationModel;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.RealmModel;
import org.keycloak.models.jpa.JpaModel;
import org.keycloak.representations.idm.authorization.DecisionStrategy;
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
Expand All @@ -35,7 +36,7 @@ public class ResourceServerAdapter extends AbstractAuthorizationModel implements
private EntityManager em;
private StoreFactory storeFactory;

public ResourceServerAdapter(ResourceServerEntity entity, EntityManager em, StoreFactory storeFactory) {
public ResourceServerAdapter(RealmModel realm, ResourceServerEntity entity, EntityManager em, StoreFactory storeFactory) {
super(storeFactory);
this.entity = entity;
this.em = em;
Expand Down Expand Up @@ -87,6 +88,16 @@ public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
entity.setDecisionStrategy(decisionStrategy);
}

@Override
public String getClientId() {
return getId();
}

@Override
public RealmModel getRealm() {
return null;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void setIconUri(String iconUri) {

@Override
public ResourceServer getResourceServer() {
return storeFactory.getResourceServerStore().findById(entity.getResourceServer().getId());
return storeFactory.getResourceServerStore().findById(null, entity.getResourceServer().getId());
}

public static ScopeEntity toEntity(EntityManager em, Scope scope) {
Expand Down
Loading