@Test public void testUpdateAccessPolicy() 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 updateAccessPolicy = accessPolicyProvider.updateAccessPolicy(policy); assertNotNull(updateAccessPolicy); assertEquals("policy-1", updateAccessPolicy.getIdentifier()); assertEquals("/flow", updateAccessPolicy.getResource()); assertEquals(1, updateAccessPolicy.getUsers().size()); assertTrue(updateAccessPolicy.getUsers().contains("user-A")); assertEquals(1, updateAccessPolicy.getGroups().size()); assertTrue(updateAccessPolicy.getGroups().contains("group-A")); assertEquals(RequestAction.READ, updateAccessPolicy.getAction()); }
@Override public synchronized AccessPolicy updateAccessPolicy(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(); Policy updatePolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { updatePolicy = policy; break; } } if (updatePolicy == null) { return null; } transferUsersAndGroups(accessPolicy, updatePolicy); saveAndRefreshHolder(authorizations); return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier()); }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy updateAccessPolicy(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(); Policy updatePolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { updatePolicy = policy; break; } } if (updatePolicy == null) { return null; } transferUsersAndGroups(accessPolicy, updatePolicy); saveAndRefreshHolder(authorizations); return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier()); } }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy updateAccessPolicy(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(); Policy updatePolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { updatePolicy = policy; break; } } if (updatePolicy == null) { return null; } transferUsersAndGroups(accessPolicy, updatePolicy); saveAndRefreshHolder(authorizations); return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier()); }  }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public synchronized AccessPolicy updateAccessPolicy(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(); Policy updatePolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { updatePolicy = policy; break; } } if (updatePolicy == null) { return null; } transferUsersAndGroups(accessPolicy, updatePolicy); saveAndRefreshHolder(authorizations); return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier()); }  @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 updateAccessPolicy(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(); Policy updatePolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) { updatePolicy = policy; break; } } if (updatePolicy == null) { return null; } transferUsersAndGroups(accessPolicy, updatePolicy); saveAndRefreshHolder(authorizations); return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier()); }  @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);  }