@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof ResourceServer)) return false; ResourceServer that = (ResourceServer) o; return that.getId().equals(getId()); }
public CachedResourceServer(Long revision, ResourceServer resourceServer) { super(revision, resourceServer.getId()); this.allowRemoteResourceManagement = resourceServer.isAllowRemoteResourceManagement(); this.policyEnforcementMode = resourceServer.getPolicyEnforcementMode(); }
@Override public void setAllowRemoteResourceManagement(boolean allowRemoteResourceManagement) { getDelegateForUpdate(); updated.setAllowRemoteResourceManagement(allowRemoteResourceManagement); }
@Override public void setPolicyEnforcementMode(PolicyEnforcementMode enforcementMode) { getDelegateForUpdate(); updated.setPolicyEnforcementMode(enforcementMode); }
@Override public PolicyEnforcementMode getPolicyEnforcementMode() { if (isUpdated()) return updated.getPolicyEnforcementMode(); return cached.getPolicyEnforcementMode(); }
@Override public boolean isAllowRemoteResourceManagement() { if (isUpdated()) return updated.isAllowRemoteResourceManagement(); return cached.isAllowRemoteResourceManagement(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof ResourceServer)) return false; ResourceServer that = (ResourceServer) o; return that.getId().equals(getId()); }
public static ResourceServerEntity toEntity(EntityManager em, ResourceServer resource) { if (resource instanceof ResourceAdapter) { return ((ResourceServerAdapter)resource).getEntity(); } else { return em.getReference(ResourceServerEntity.class, resource.getId()); } }
@Override public String getId() { if (isUpdated()) return updated.getId(); return cached.getId(); }
@Override public List<Scope> getScopes() { return getMongoEntity().getScopes().stream() .map(id -> authorizationProvider.getStoreFactory().getScopeStore().findById(id, getResourceServer().getId())) .collect(toList()); }
@Override public void delete(String id) { if (id == null) return; Policy policy = findById(id, null); if (policy == null) return; cache.invalidateObject(id); Set<String> resources = policy.getResources().stream().map(resource -> resource.getId()).collect(Collectors.toSet()); ResourceServer resourceServer = policy.getResourceServer(); Set<String> resourceTypes = getResourceTypes(resources, resourceServer.getId()); String defaultResourceType = policy.getConfig().get("defaultResourceType"); if (Objects.nonNull(defaultResourceType)) { resourceTypes.add(defaultResourceType); } Set<String> scopes = policy.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()); invalidationEvents.add(PolicyRemovedEvent.create(id, policy.getName(), resources, resourceTypes, scopes, resourceServer.getId())); cache.policyRemoval(id, policy.getName(), resources, resourceTypes, scopes, resourceServer.getId(), invalidations); getPolicyStoreDelegate().delete(id); }
@Override public Resource create(String id, String name, ResourceServer resourceServer, String owner) { Resource resource = getResourceStoreDelegate().create(id, name, resourceServer, owner); Resource cached = findById(resource.getId(), resourceServer.getId()); registerResourceInvalidation(resource.getId(), resource.getName(), resource.getType(), resource.getUris(), resource.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()), resourceServer.getId(), resource.getOwner()); if (cached == null) { cached = findById(resource.getId(), resourceServer.getId()); } return cached; }
@Override public Policy create(AbstractPolicyRepresentation representation, ResourceServer resourceServer) { Policy policy = getPolicyStoreDelegate().create(representation, resourceServer); Policy cached = findById(policy.getId(), resourceServer.getId()); registerPolicyInvalidation(policy.getId(), representation.getName(), representation.getResources(), representation.getScopes(), null, resourceServer.getId()); if (cached == null) { cached = findById(policy.getId(), resourceServer.getId()); } return cached; }
private void updateResourceServer(ClientModel clientModel, RoleModel removedRole, ResourceServerStore resourceServerStore, PolicyStore policyStore) { ResourceServer resourceServer = resourceServerStore.findById(clientModel.getId()); if (resourceServer != null) { policyStore.findByType(getId(), resourceServer.getId()).forEach(policy -> { List<Map> roles = new ArrayList<>(); for (Map<String,Object> role : getRoles(policy)) { if (!role.get("id").equals(removedRole.getId())) { Map updated = new HashMap(); updated.put("id", role.get("id")); Object required = role.get("required"); if (required != null) { updated.put("required", required); } roles.add(updated); } } try { if (roles.isEmpty()) { policyStore.delete(policy.getId()); } else { policy.putConfig("roles", JsonSerialization.writeValueAsString(roles)); } } catch (IOException e) { throw new RuntimeException("Error while synchronizing roles with policy [" + policy.getName() + "].", e); } }); } }
@Override public void delete(String id) { if (id == null) return; Resource resource = findById(id, null); if (resource == null) return; cache.invalidateObject(id); invalidationEvents.add(ResourceRemovedEvent.create(id, resource.getName(), resource.getType(), resource.getUris(), resource.getOwner(), resource.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()), resource.getResourceServer().getId())); cache.resourceRemoval(id, resource.getName(), resource.getType(), resource.getUris(), resource.getOwner(), resource.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()), resource.getResourceServer().getId(), invalidations); getResourceStoreDelegate().delete(id); }
@Override public Scope getScope() { return cacheSession.getScopeStore().findById(cached.getScopeId(), getResourceServer().getId()); }
@Override public void delete(String id) { if (id == null) return; Scope scope = findById(id, null); if (scope == null) return; cache.invalidateObject(id); invalidationEvents.add(ScopeRemovedEvent.create(id, scope.getName(), scope.getResourceServer().getId())); cache.scopeRemoval(id, scope.getName(), scope.getResourceServer().getId(), invalidations); getScopeStoreDelegate().delete(id); }
@Override public Resource getResource() { return cacheSession.getResourceStore().findById(cached.getResourceId(), getResourceServer().getId()); }
this.name = policy.getName(); this.description = policy.getDescription(); this.resourceServerId = policy.getResourceServer().getId();
@Override public void delete(String id) { if (id == null) return; ResourceServer server = findById(id); if (server == null) return; cache.invalidateObject(id); invalidationEvents.add(ResourceServerRemovedEvent.create(id, server.getId())); cache.resourceServerRemoval(id, invalidations); getResourceServerStoreDelegate().delete(id); }