@Test public void testDecodeRoles() { Attributes attributes = new MapAttributes(); attributes.add(ATTRIBUTE_NAME_GROUPS, 0, ROLE_ADMIN); attributes.add(ATTRIBUTE_NAME_ROLES, 0, ROLE_TESTER); AuthorizationIdentity authIdentity = AuthorizationIdentity.basicIdentity(attributes); DefaultRoleDecoder defaultRoleDecoder = new DefaultRoleDecoder(); defaultRoleDecoder.groupsAttribute = ATTRIBUTE_NAME_GROUPS; Roles roles = defaultRoleDecoder.fromDefaultAttribute(authIdentity); Assertions.assertFalse(roles.isEmpty()); Assertions.assertTrue(roles.contains(ROLE_ADMIN)); Assertions.assertFalse(roles.contains(ROLE_TESTER)); defaultRoleDecoder.groupsAttribute = ATTRIBUTE_NAME_ROLES; roles = defaultRoleDecoder.fromDefaultAttribute(authIdentity); Assertions.assertFalse(roles.isEmpty()); Assertions.assertFalse(roles.contains(ROLE_ADMIN)); Assertions.assertTrue(roles.contains(ROLE_TESTER)); }
public Roles decodeRoles(AuthorizationIdentity authorizationIdentity) { if (userInstances.isUnsatisfied()) { return fromDefaultAttribute(authorizationIdentity); } else if (userInstances.isAmbiguous()) { List<Roles> allRoles = new ArrayList<>(); for (RoleDecoder i : userInstances) { allRoles.add(i.decodeRoles(authorizationIdentity)); } Roles r = allRoles.get(0); for (int i = 1; i < allRoles.size(); ++i) { r = r.or(allRoles.get(i)); } return r; } else { return userInstances.get().decodeRoles(authorizationIdentity); } }
DefaultRoleDecoder { public Roles decodeRoles(AuthorizationIdentity authorizationIdentity) { if (userInstances.isUnsatisfied()) { return fromDefaultAttribute(authorizationIdentity); } else if (userInstances.isAmbiguous()) { List<Roles> allRoles = new ArrayList<>(); for (RoleDecoder i : userInstances) { allRoles.add(i.decodeRoles(authorizationIdentity)); } Roles r = allRoles.get(0); for (int i = 1; i < allRoles.size(); ++i) { r = r.or(allRoles.get(i)); } return r; } else { return userInstances.get().decodeRoles(authorizationIdentity); } } }
DefaultRoleDecoder { public Roles decodeRoles(AuthorizationIdentity authorizationIdentity) { if (userInstances.isUnsatisfied()) { return fromDefaultAttribute(authorizationIdentity); } else if (userInstances.isAmbiguous()) { List<Roles> allRoles = new ArrayList<>(); for (RoleDecoder i : userInstances) { allRoles.add(i.decodeRoles(authorizationIdentity)); } Roles r = allRoles.get(0); for (int i = 1; i < allRoles.size(); ++i) { r = r.or(allRoles.get(i)); } return r; } else { return userInstances.get().decodeRoles(authorizationIdentity); } }  }
DefaultRoleDecoder { public Roles decodeRoles(AuthorizationIdentity authorizationIdentity) { if (userInstances.isUnsatisfied()) { return fromDefaultAttribute(authorizationIdentity); } else if (userInstances.isAmbiguous()) { List<Roles> allRoles = new ArrayList<>(); for (RoleDecoder i : userInstances) { allRoles.add(i.decodeRoles(authorizationIdentity)); } Roles r = allRoles.get(0); for (int i = 1; i < allRoles.size(); ++i) { r = r.or(allRoles.get(i)); } return r; } else { return userInstances.get().decodeRoles(authorizationIdentity); } }  Roles decodeRoles(AuthorizationIdentity authorizationIdentity); }
DefaultRoleDecoder { public Roles decodeRoles(AuthorizationIdentity authorizationIdentity) { if (userInstances.isUnsatisfied()) { return fromDefaultAttribute(authorizationIdentity); } else if (userInstances.isAmbiguous()) { List<Roles> allRoles = new ArrayList<>(); for (RoleDecoder i : userInstances) { allRoles.add(i.decodeRoles(authorizationIdentity)); } Roles r = allRoles.get(0); for (int i = 1; i < allRoles.size(); ++i) { r = r.or(allRoles.get(i)); } return r; } else { return userInstances.get().decodeRoles(authorizationIdentity); } }  Roles decodeRoles(AuthorizationIdentity authorizationIdentity);  }