@Test public void testGetFingerprint() { User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build(); User user2 = new User.Builder().identifier("user-id-2").identity("user-2").build(); Group group1 = new Group.Builder().identifier("group-id-1").name("group-1").addUser(user1.getIdentifier()).build(); Group group2 = new Group.Builder().identifier("group-id-2").name("group-2").addUser(user2.getIdentifier()).build(); AccessPolicy policy1 = new AccessPolicy.Builder() .identifier("policy-id-1") .resource("resource1") .action(RequestAction.READ) .addUser(user1.getIdentifier()) .addUser(user2.getIdentifier()) .build(); AccessPolicy policy2 = new AccessPolicy.Builder() .identifier("policy-id-2") .resource("resource2") .action(RequestAction.READ) .addGroup(group1.getIdentifier()) .addGroup(group2.getIdentifier()) .addUser(user1.getIdentifier()) .addUser(user2.getIdentifier()) .build(); Set<Group> groups1 = new LinkedHashSet<>(); groups1.add(group1); groups1.add(group2); Set<User> users1 = new LinkedHashSet<>(); users1.add(user1); users1.add(user2); Set<AccessPolicy> policies1 = new LinkedHashSet<>(); policies1.add(policy1); policies1.add(policy2); AbstractPolicyBasedAuthorizer authorizer1 = Mockito.mock(AbstractPolicyBasedAuthorizer.class); when(authorizer1.getGroups()).thenReturn(groups1); when(authorizer1.getUsers()).thenReturn(users1); when(authorizer1.getAccessPolicies()).thenReturn(policies1); Set<Group> groups2 = new LinkedHashSet<>(); groups2.add(group2); groups2.add(group1); Set<User> users2 = new LinkedHashSet<>(); users2.add(user2); users2.add(user1); Set<AccessPolicy> policies2 = new LinkedHashSet<>(); policies2.add(policy2); policies2.add(policy1); AbstractPolicyBasedAuthorizer authorizer2 = Mockito.mock(AbstractPolicyBasedAuthorizer.class); when(authorizer2.getGroups()).thenReturn(groups2); when(authorizer2.getUsers()).thenReturn(users2); when(authorizer2.getAccessPolicies()).thenReturn(policies2); assertEquals(authorizer1.getFingerprint(), authorizer2.getFingerprint()); }
public final String getFingerprint() throws AuthorizationAccessException { final List<User> users = getSortedUsers(); final List<Group> groups = getSortedGroups(); final List<AccessPolicy> policies = getSortedAccessPolicies(); if (users.isEmpty() && groups.isEmpty() && policies.isEmpty()) { return EMPTY_FINGERPRINT; } XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("authorizations"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } return out.toString(); }
AbstractPolicyBasedAuthorizer implements Authorizer { public final String getFingerprint() throws AuthorizationAccessException { final List<User> users = getSortedUsers(); final List<Group> groups = getSortedGroups(); final List<AccessPolicy> policies = getSortedAccessPolicies(); if (users.isEmpty() && groups.isEmpty() && policies.isEmpty()) { return EMPTY_FINGERPRINT; } XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("authorizations"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } return out.toString(); } }
AbstractPolicyBasedAuthorizer implements Authorizer { public final String getFingerprint() throws AuthorizationAccessException { final List<User> users = getSortedUsers(); final List<Group> groups = getSortedGroups(); final List<AccessPolicy> policies = getSortedAccessPolicies(); if (users.isEmpty() && groups.isEmpty() && policies.isEmpty()) { return EMPTY_FINGERPRINT; } XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("authorizations"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } return out.toString(); }  }
AbstractPolicyBasedAuthorizer implements Authorizer { public final String getFingerprint() throws AuthorizationAccessException { final List<User> users = getSortedUsers(); final List<Group> groups = getSortedGroups(); final List<AccessPolicy> policies = getSortedAccessPolicies(); if (users.isEmpty() && groups.isEmpty() && policies.isEmpty()) { return EMPTY_FINGERPRINT; } XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("authorizations"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } return out.toString(); }  @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 { public final String getFingerprint() throws AuthorizationAccessException { final List<User> users = getSortedUsers(); final List<Group> groups = getSortedGroups(); final List<AccessPolicy> policies = getSortedAccessPolicies(); if (users.isEmpty() && groups.isEmpty() && policies.isEmpty()) { return EMPTY_FINGERPRINT; } XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("authorizations"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } return out.toString(); }  @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; }