Class JPAPolicyStore

java.lang.Object
org.keycloak.authorization.jpa.store.JPAPolicyStore
All Implemented Interfaces:
PolicyStore

public class JPAPolicyStore extends Object implements PolicyStore
Author:
Pedro Igor
  • Constructor Details

    • JPAPolicyStore

      public JPAPolicyStore(jakarta.persistence.EntityManager entityManager, AuthorizationProvider provider)
  • Method Details

    • create

      public Policy create(ResourceServer resourceServer, AbstractPolicyRepresentation representation)
      Description copied from interface: PolicyStore
      Creates a new Policy instance. The new instance is not necessarily persisted though, which may require a call to the {#save} method to actually make it persistent.
      Specified by:
      create in interface PolicyStore
      Parameters:
      resourceServer - the resource server to which this policy belongs. Cannot be null.
      representation - the policy representation
      Returns:
      a new instance of Policy
    • delete

      public void delete(String id)
      Description copied from interface: PolicyStore
      Deletes a policy from the underlying persistence mechanism.
      Specified by:
      delete in interface PolicyStore
      Parameters:
      id - the id of the policy to delete
    • findById

      public Policy findById(ResourceServer resourceServer, String id)
      Description copied from interface: PolicyStore
      Returns a Policy with the given id
      Specified by:
      findById in interface PolicyStore
      Parameters:
      resourceServer - the resource server. Ignored if null.
      id - the identifier of the policy
      Returns:
      a policy with the given identifier.
    • findByName

      public Policy findByName(ResourceServer resourceServer, String name)
      Description copied from interface: PolicyStore
      Returns a Policy with the given name
      Specified by:
      findByName in interface PolicyStore
      Parameters:
      resourceServer - the resource server. Cannot be null
      name - the name of the policy
      Returns:
      a policy with the given name or null if no such policy exists.
    • findByResourceServer

      public List<Policy> findByResourceServer(ResourceServer resourceServer)
      Description copied from interface: PolicyStore
      Returns a list of Policy associated with the ResourceServer
      Specified by:
      findByResourceServer in interface PolicyStore
      Parameters:
      resourceServer - the resource server. Cannot be null.
      Returns:
      a list of policies that belong to the given resource server
    • find

      public List<Policy> find(ResourceServer resourceServer, Map<Policy.FilterOption,String[]> attributes, Integer firstResult, Integer maxResults)
      Description copied from interface: PolicyStore
      Returns a list of Policy associated with a ResourceServer with the given resourceServerId.
      Specified by:
      find in interface PolicyStore
      Parameters:
      resourceServer - the identifier of a resource server. Ignored if null.
      attributes - a map holding the attributes that will be used as a filter; possible filter options are given by Policy.FilterOption
      firstResult - first result to return. Ignored if negative or null.
      maxResults - maximum number of results to return. Ignored if negative or null.
      Returns:
      a list of policies that belong to the given resource server
    • findByResource

      public void findByResource(ResourceServer resourceServer, Resource resource, Consumer<Policy> consumer)
      Description copied from interface: PolicyStore
      Searches for all policies associated with the Resource and passes the result to the consumer
      Specified by:
      findByResource in interface PolicyStore
      Parameters:
      resourceServer - the resourceServer. Cannot be null.
      resource - the resource. Cannot be null.
      consumer - consumer of policies resulted from the search
    • findByResourceType

      public void findByResourceType(ResourceServer resourceServer, String resourceType, Consumer<Policy> consumer)
      Description copied from interface: PolicyStore
      Searches for policies associated with a ResourceServer and passes the result to the consumer
      Specified by:
      findByResourceType in interface PolicyStore
      Parameters:
      resourceServer - the resourceServer. Cannot be null.
      resourceType - the type of a resource
      consumer - consumer of policies resulted from the search
    • findByScopes

      public List<Policy> findByScopes(ResourceServer resourceServer, List<Scope> scopes)
      Description copied from interface: PolicyStore
      Returns a list of Policy associated with a Scope within the given scope.
      Specified by:
      findByScopes in interface PolicyStore
      Parameters:
      resourceServer - the resource server. Cannot be null.
      scopes - the scopes
      Returns:
      a list of policies associated with the given scopes
    • findByScopes

      public void findByScopes(ResourceServer resourceServer, Resource resource, List<Scope> scopes, Consumer<Policy> consumer)
      Description copied from interface: PolicyStore
      Effectively the same method as PolicyStore.findByScopes(ResourceServer, Resource, List), however in the end the consumer is fed with the result.
      Specified by:
      findByScopes in interface PolicyStore
    • findByType

      public List<Policy> findByType(ResourceServer resourceServer, String type)
      Description copied from interface: PolicyStore
      Returns a list of Policy with the given type.
      Specified by:
      findByType in interface PolicyStore
      Parameters:
      resourceServer - the resource server id. Cannot be null.
      type - the type of the policy
      Returns:
      a list of policies with the given type
    • findDependentPolicies

      public List<Policy> findDependentPolicies(ResourceServer resourceServer, String policyId)
      Description copied from interface: PolicyStore
      Returns a list of Policy that depends on another policy with the given id.
      Specified by:
      findDependentPolicies in interface PolicyStore
      Parameters:
      resourceServer - the resource server. Cannot be null.
      policyId - the id of the policy to query its dependents
      Returns:
      a list of policies that depends on the a policy with the given identifier