@Test public void testDeleteAccessPolicy() throws Exception { writeFile(primaryAuthorizations, AUTHORIZATIONS); writeFile(primaryTenants, TENANTS); userGroupProvider.onConfigured(configurationContext); accessPolicyProvider.onConfigured(configurationContext); assertEquals(2, accessPolicyProvider.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 = accessPolicyProvider.deleteAccessPolicy(policy); assertNotNull(deletedAccessPolicy); assertEquals(policy.getIdentifier(), deletedAccessPolicy.getIdentifier()); assertEquals(1, accessPolicyProvider.getAccessPolicies().size()); assertNull(accessPolicyProvider.getAccessPolicy(policy.getIdentifier())); }
@Override public synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); 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); return accessPolicy; }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); 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); return accessPolicy; } }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); 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); return accessPolicy; }  }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); 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); return accessPolicy; }  @Override void initialize(AccessPolicyProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override UserGroupProvider getUserGroupProvider(); @Override Set<AccessPolicy> getAccessPolicies(); @Override synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(String identifier); @Override AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action); @Override synchronized AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); @Override void setUserDefaultAccesPilicy(User user); }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException { if (accessPolicy == null) { throw new IllegalArgumentException("AccessPolicy cannot be null"); } final AuthorizationsHolder holder = this.authorizationsHolder.get(); 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); return accessPolicy; }  @Override void initialize(AccessPolicyProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override UserGroupProvider getUserGroupProvider(); @Override Set<AccessPolicy> getAccessPolicies(); @Override synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(String identifier); @Override AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action); @Override synchronized AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); @Override void setUserDefaultAccesPilicy(User user);  }