281 return new PolicyStore() {
286 public Policy create(AbstractPolicyRepresentation representation, ResourceServer resourceServer) {
287 Set<String> resources = representation.getResources();
289 if (resources != null) {
290 representation.setResources(resources.stream().map(
id -> {
293 if (resource == null) {
297 if (resource == null) {
298 throw new RuntimeException(
"Resource [" +
id +
"] does not exist or is not owned by the resource server.");
301 return resource.getId();
302 }).collect(Collectors.toSet()));
305 Set<String> scopes = representation.getScopes();
307 if (scopes != null) {
308 representation.setScopes(scopes.stream().map(
id -> {
316 throw new RuntimeException(
"Scope [" +
id +
"] does not exist");
319 return scope.getId();
320 }).collect(Collectors.toSet()));
324 Set<String> policies = representation.getPolicies();
326 if (policies != null) {
327 representation.setPolicies(policies.stream().map(
id -> {
330 if (policy == null) {
334 if (policy == null) {
335 throw new RuntimeException(
"Policy [" +
id +
"] does not exist");
338 return policy.getId();
339 }).collect(Collectors.toSet()));
342 return RepresentationToModel.toModel(representation,
AuthorizationProvider.this, policyStore.create(representation, resourceServer));
346 public void delete(String id) {
347 Policy policy = findById(
id, null);
349 if (policy != null) {
350 ResourceServer resourceServer = policy.getResourceServer();
352 findDependentPolicies(policy.getId(), resourceServer.getId()).forEach(dependentPolicy -> {
353 dependentPolicy.removeAssociatedPolicy(policy);
354 if (dependentPolicy.getAssociatedPolicies().isEmpty()) {
355 delete(dependentPolicy.getId());
359 policyStore.delete(
id);
364 public Policy findById(String
id, String resourceServerId) {
365 return policyStore.findById(
id, resourceServerId);
369 public Policy findByName(String name, String resourceServerId) {
370 return policyStore.findByName(name, resourceServerId);
374 public List<Policy> findByResourceServer(String resourceServerId) {
375 return policyStore.findByResourceServer(resourceServerId);
379 public List<Policy> findByResourceServer(Map<String, String[]> attributes, String resourceServerId,
int firstResult,
int maxResult) {
380 return policyStore.findByResourceServer(attributes, resourceServerId, firstResult, maxResult);
384 public List<Policy> findByResource(String resourceId, String resourceServerId) {
385 return policyStore.findByResource(resourceId, resourceServerId);
389 public void findByResource(String resourceId, String resourceServerId, Consumer<Policy> consumer) {
390 policyStore.findByResource(resourceId, resourceServerId, consumer);
394 public List<Policy> findByResourceType(String resourceType, String resourceServerId) {
395 return policyStore.findByResourceType(resourceType, resourceServerId);
399 public List<Policy> findByScopeIds(List<String> scopeIds, String resourceServerId) {
400 return policyStore.findByScopeIds(scopeIds, resourceServerId);
404 public List<Policy> findByScopeIds(List<String> scopeIds, String resourceId, String resourceServerId) {
405 return policyStore.findByScopeIds(scopeIds, resourceId, resourceServerId);
409 public void findByScopeIds(List<String> scopeIds, String resourceId, String resourceServerId, Consumer<Policy> consumer) {
410 policyStore.findByScopeIds(scopeIds, resourceId, resourceServerId, consumer);
414 public List<Policy> findByType(String type, String resourceServerId) {
415 return policyStore.findByType(type, resourceServerId);
419 public List<Policy> findDependentPolicies(String
id, String resourceServerId) {
420 return policyStore.findDependentPolicies(
id, resourceServerId);
424 public void findByResourceType(String type, String
id, Consumer<Policy> policyConsumer) {
425 policyStore.findByResourceType(type,
id, policyConsumer);
Policy findByName(String name, String resourceServerId)
AuthorizationProvider(KeycloakSession session, RealmModel realm, Map< String, PolicyProviderFactory > policyProviderFactories, PolicyEvaluator policyEvaluator)
Definition: AuthorizationProvider.java:85
Resource findById(String id, String resourceServerId)
PolicyStore getPolicyStore()
ScopeStore getScopeStore()
StoreFactory storeFactory
Definition: AuthorizationProvider.java:79
ResourceStore getResourceStore()
Scope findById(String id, String resourceServerId)
Policy findById(String id, String resourceServerId)
Scope findByName(String name, String resourceServerId)
Resource findByName(String name, String resourceServerId)