@Test public void testDeleteAccessPolicy() throws Exception { writeFile(primaryAuthorizations, AUTHORIZATIONS); writeFile(primaryTenants, TENANTS); authorizer.onConfigured(configurationContext); assertEquals(2, authorizer.getAccessPolicies().size()); final AccessPolicy policy = new AccessPolicy.Builder() .identifier("policy-1") .resource("resource-A") .addUser("user-A") .addGroup("group-A") .action(RequestAction.READ) .build(); final AccessPolicy deletedAccessPolicy = authorizer.deleteAccessPolicy(policy); assertNotNull(deletedAccessPolicy); assertEquals(policy.getIdentifier(), deletedAccessPolicy.getIdentifier()); assertEquals(1, authorizer.getAccessPolicies().size()); assertNull(authorizer.getAccessPolicy(policy.getIdentifier())); }
@Override public synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); final Tenants tenants = holder.getTenants(); final Authorizations authorizations = holder.getAuthorizations(); boolean deletedPolicy = false; Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator(); while (policyIter.hasNext()) { final Policy policy = policyIter.next(); if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { policyIter.remove(); deletedPolicy = true; break; } } if (!deletedPolicy) { return null; } saveAndRefreshHolder(authorizations, tenants); return accessPolicy; }
FileAuthorizer extends AbstractPolicyBasedAuthorizer { @Override public synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); final Tenants tenants = holder.getTenants(); final Authorizations authorizations = holder.getAuthorizations(); boolean deletedPolicy = false; Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator(); while (policyIter.hasNext()) { final Policy policy = policyIter.next(); if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { policyIter.remove(); deletedPolicy = true; break; } } if (!deletedPolicy) { return null; } saveAndRefreshHolder(authorizations, tenants); return accessPolicy; } }
FileAuthorizer extends AbstractPolicyBasedAuthorizer { @Override public synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); final Tenants tenants = holder.getTenants(); final Authorizations authorizations = holder.getAuthorizations(); boolean deletedPolicy = false; Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator(); while (policyIter.hasNext()) { final Policy policy = policyIter.next(); if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { policyIter.remove(); deletedPolicy = true; break; } } if (!deletedPolicy) { return null; } saveAndRefreshHolder(authorizations, tenants); return accessPolicy; }  }
FileAuthorizer extends AbstractPolicyBasedAuthorizer { @Override public synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); final Tenants tenants = holder.getTenants(); final Authorizations authorizations = holder.getAuthorizations(); boolean deletedPolicy = false; Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator(); while (policyIter.hasNext()) { final Policy policy = policyIter.next(); if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { policyIter.remove(); deletedPolicy = true; break; } } if (!deletedPolicy) { return null; } saveAndRefreshHolder(authorizations, tenants); return accessPolicy; }  @Override void initialize(final AuthorizerInitializationContext initializationContext); @Override void doOnConfigured(final AuthorizerConfigurationContext configurationContext); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override void preDestruction(); @Override synchronized Group doAddGroup(Group group); @Override Group getGroup(String identifier); @Override synchronized Group doUpdateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @Override Set<Group> getGroups(); @Override synchronized User doAddUser(final User user); @Override User getUser(final String identifier); @Override User getUserByIdentity(final String identity); @Override synchronized User doUpdateUser(final User user); @Override synchronized User deleteUser(final User user); @Override Set<User> getUsers(); @Override synchronized AccessPolicy doAddAccessPolicy(final AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(final String identifier); @Override synchronized AccessPolicy updateAccessPolicy(final AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy); @Override Set<AccessPolicy> getAccessPolicies(); @Override UsersAndAccessPolicies getUsersAndAccessPolicies(); }
FileAuthorizer extends AbstractPolicyBasedAuthorizer { @Override public synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); final Tenants tenants = holder.getTenants(); final Authorizations authorizations = holder.getAuthorizations(); boolean deletedPolicy = false; Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator(); while (policyIter.hasNext()) { final Policy policy = policyIter.next(); if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { policyIter.remove(); deletedPolicy = true; break; } } if (!deletedPolicy) { return null; } saveAndRefreshHolder(authorizations, tenants); return accessPolicy; }  @Override void initialize(final AuthorizerInitializationContext initializationContext); @Override void doOnConfigured(final AuthorizerConfigurationContext configurationContext); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override void preDestruction(); @Override synchronized Group doAddGroup(Group group); @Override Group getGroup(String identifier); @Override synchronized Group doUpdateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @Override Set<Group> getGroups(); @Override synchronized User doAddUser(final User user); @Override User getUser(final String identifier); @Override User getUserByIdentity(final String identity); @Override synchronized User doUpdateUser(final User user); @Override synchronized User deleteUser(final User user); @Override Set<User> getUsers(); @Override synchronized AccessPolicy doAddAccessPolicy(final AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(final String identifier); @Override synchronized AccessPolicy updateAccessPolicy(final AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy); @Override Set<AccessPolicy> getAccessPolicies(); @Override UsersAndAccessPolicies getUsersAndAccessPolicies();  }