@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Scope)) return false; Scope that = (Scope) o; return that.getId().equals(getId()); }
public CachedScope(Long revision, Scope scope) { super(revision, scope.getId()); this.name = scope.getName(); this.displayName = scope.getDisplayName(); this.iconUri = scope.getIconUri(); this.resourceServerId = scope.getResourceServer().getId(); }
@Override public void setDisplayName(String name) { getDelegateForUpdate(); updated.setDisplayName(name); }
@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 void setIconUri(String iconUri) { getDelegateForUpdate(); updated.setIconUri(iconUri); }
@Override public void setName(String name) { getDelegateForUpdate(); updated.setName(name); }
@Override public String getIconUri() { if (isUpdated()) return updated.getIconUri(); return cached.getIconUri(); }
@Override public String getName() { if (isUpdated()) return updated.getName(); return cached.getName(); }
@Override public String getDisplayName() { if (isUpdated()) return updated.getDisplayName(); return cached.getDisplayName(); }
public void updateScopes(Set<Scope> toUpdate) { for (Scope scope : toUpdate) { boolean hasScope = false; for (String existingScope : this.scopes) { if (existingScope.equals(scope.getId())) { hasScope = true; } } if (!hasScope) { this.scopes.add(scope.getId()); } } for (String scopeId : new HashSet<String>(this.scopes)) { boolean hasScope = false; for (Scope scope : toUpdate) { if (scopeId.equals(scope.getId())) { hasScope = true; } } if (!hasScope) { this.scopes.remove(scopeId); } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Scope)) return false; Scope that = (Scope) o; return that.getId().equals(getId()); }
@Override public String getId() { if (isUpdated()) return updated.getId(); return cached.getId(); }
public static ScopeEntity toEntity(EntityManager em, Scope scope) { if (scope instanceof ScopeAdapter) { return ((ScopeAdapter)scope).getEntity(); } else { return em.getReference(ScopeEntity.class, scope.getId()); } }
@Override public void updateScopes(Set<Scope> toUpdate) { throwExceptionIfReadonly(); Set<String> ids = new HashSet<>(); for (Scope scope : toUpdate) { ids.add(scope.getId()); } Iterator<ScopeEntity> it = entity.getScopes().iterator(); while (it.hasNext()) { ScopeEntity next = it.next(); if (!ids.contains(next.getId())) it.remove(); else ids.remove(next.getId()); } for (String addId : ids) { entity.getScopes().add(em.getReference(ScopeEntity.class, addId)); } }
@Override public void addScope(Scope scope) { getMongoEntity().addScope(scope.getId()); updateMongoEntity(); }
@Override public void removeScope(Scope scope) { getMongoEntity().removeScope(scope.getId()); updateMongoEntity(); }
@Override public void addScope(Scope scope) { getDelegateForUpdate(); cacheSession.registerPolicyInvalidation(cached.getId(), cached.getName(), cached.getResourcesIds(modelSupplier), new HashSet<>(Arrays.asList(scope.getId())), cached.getConfig(modelSupplier).get("defaultResourceType"), cached.getResourceServerId()); updated.addScope(scope); }
@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 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); }