@Test(expected = AuthorizerCreationException.class) public void testOnConfiguredWhenUsersWithSameIdentity() { User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build(); User user2 = new User.Builder().identifier("user-id-2").identity("user-1").build(); Set<User> users = new LinkedHashSet<>(); users.add(user1); users.add(user2); AuthorizerConfigurationContext context = Mockito.mock(AuthorizerConfigurationContext.class); AbstractPolicyBasedAuthorizer authorizer = new MockPolicyBasedAuthorizer(new HashSet<>(), users, new HashSet<>()); authorizer.onConfigured(context); }
@Override public final void onConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { doOnConfigured(configurationContext); for (AccessPolicy accessPolicy : getAccessPolicies()) { if (policyExists(accessPolicy)) { throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction())); } } for (User user : getUsers()) { if (tenantExists(user.getIdentifier(), user.getIdentity())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity())); } } for (Group group : getGroups()) { if (tenantExists(group.getIdentifier(), group.getName())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName())); } } }
AbstractPolicyBasedAuthorizer implements Authorizer { @Override public final void onConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { doOnConfigured(configurationContext); for (AccessPolicy accessPolicy : getAccessPolicies()) { if (policyExists(accessPolicy)) { throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction())); } } for (User user : getUsers()) { if (tenantExists(user.getIdentifier(), user.getIdentity())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity())); } } for (Group group : getGroups()) { if (tenantExists(group.getIdentifier(), group.getName())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName())); } } } }
AbstractPolicyBasedAuthorizer implements Authorizer { @Override public final void onConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { doOnConfigured(configurationContext); for (AccessPolicy accessPolicy : getAccessPolicies()) { if (policyExists(accessPolicy)) { throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction())); } } for (User user : getUsers()) { if (tenantExists(user.getIdentifier(), user.getIdentity())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity())); } } for (Group group : getGroups()) { if (tenantExists(group.getIdentifier(), group.getName())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName())); } } }  }
AbstractPolicyBasedAuthorizer implements Authorizer { @Override public final void onConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { doOnConfigured(configurationContext); for (AccessPolicy accessPolicy : getAccessPolicies()) { if (policyExists(accessPolicy)) { throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction())); } } for (User user : getUsers()) { if (tenantExists(user.getIdentifier(), user.getIdentity())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity())); } } for (Group group : getGroups()) { if (tenantExists(group.getIdentifier(), group.getName())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName())); } } }  @Override final void onConfigured(final AuthorizerConfigurationContext configurationContext); @Override final AuthorizationResult authorize(AuthorizationRequest request); final synchronized Group addGroup(Group group); abstract Group doAddGroup(Group group); abstract Group getGroup(String identifier); final synchronized Group updateGroup(Group group); abstract Group doUpdateGroup(Group group); abstract Group deleteGroup(Group group); abstract Set<Group> getGroups(); final synchronized User addUser(User user); abstract User doAddUser(User user); abstract User getUser(String identifier); abstract User getUserByIdentity(String identity); final synchronized User updateUser(final User user); abstract User doUpdateUser(User user); abstract User deleteUser(User user); abstract Set<User> getUsers(); final synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); abstract AccessPolicy getAccessPolicy(String identifier); abstract AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); abstract AccessPolicy deleteAccessPolicy(AccessPolicy policy); abstract Set<AccessPolicy> getAccessPolicies(); abstract UsersAndAccessPolicies getUsersAndAccessPolicies(); final void inheritFingerprint(final String fingerprint); final String getFingerprint(); }
AbstractPolicyBasedAuthorizer implements Authorizer { @Override public final void onConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { doOnConfigured(configurationContext); for (AccessPolicy accessPolicy : getAccessPolicies()) { if (policyExists(accessPolicy)) { throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction())); } } for (User user : getUsers()) { if (tenantExists(user.getIdentifier(), user.getIdentity())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity())); } } for (Group group : getGroups()) { if (tenantExists(group.getIdentifier(), group.getName())) { throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName())); } } }  @Override final void onConfigured(final AuthorizerConfigurationContext configurationContext); @Override final AuthorizationResult authorize(AuthorizationRequest request); final synchronized Group addGroup(Group group); abstract Group doAddGroup(Group group); abstract Group getGroup(String identifier); final synchronized Group updateGroup(Group group); abstract Group doUpdateGroup(Group group); abstract Group deleteGroup(Group group); abstract Set<Group> getGroups(); final synchronized User addUser(User user); abstract User doAddUser(User user); abstract User getUser(String identifier); abstract User getUserByIdentity(String identity); final synchronized User updateUser(final User user); abstract User doUpdateUser(User user); abstract User deleteUser(User user); abstract Set<User> getUsers(); final synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); abstract AccessPolicy getAccessPolicy(String identifier); abstract AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); abstract AccessPolicy deleteAccessPolicy(AccessPolicy policy); abstract Set<AccessPolicy> getAccessPolicies(); abstract UsersAndAccessPolicies getUsersAndAccessPolicies(); final void inheritFingerprint(final String fingerprint); final String getFingerprint(); static final String EMPTY_FINGERPRINT; }