AuthzHelper { public static boolean isMemberOfRole(Role role, final String member, GroupMembersFetcher groupMembersFetcher) { final List<RoleMember> members = role.getRoleMembers(); if (members == null) { return false; } return checkRoleMemberValidity(members, member, groupMembersFetcher); }  static void removeRoleMembers(List<RoleMember> originalRoleMembers, List<RoleMember> removeRoleMembers); static void removeGroupMembers(List<GroupMember> originalGroupMembers, List<GroupMember> removeGroupMembers); static boolean isMemberDisabled(Integer systemDisabled); static boolean isMemberExpired(Timestamp expiration, long currentTime); static boolean shouldSkipGroupMember(GroupMember member, long currentTime); static boolean isMemberOfGroup(List<GroupMember> groupMembers, final String member); static boolean checkGroupMemberValidity(List<GroupMember> groupMembers, final String member); static boolean memberNameMatch(final String memberName, final  String matchName); static boolean shouldRunDelegatedTrustCheck(final String trust, final String trustDomain); static String retrieveResourceDomain(String resource, String op, String trustDomain); static String extractResourceDomainName(final String resource); static boolean authorityAuthorizationAllowed(Principal principal); static boolean checkRoleMemberValidity(List<RoleMember> roleMembers, final String member,
                                                  GroupMembersFetcher groupMembersFetcher); static boolean isMemberOfRole(Role role, final String member, GroupMembersFetcher groupMembersFetcher); static boolean assumeRoleResourceMatch(String roleName, Assertion assertion); static boolean matchDelegatedTrustPolicy(Policy policy, final String roleName, final String roleMember,
                                                    List<Role> roles, GroupMembersFetcher groupMembersFetcher); static boolean matchDelegatedTrustAssertion(Assertion assertion, final String roleName, final String roleMember,
                                                       List<Role> roles, GroupMembersFetcher groupMembersFetcher);  }
@Test public void testIsMemberOfRole() { List<RoleMember> roleMembers = new ArrayList<>(); RoleMember roleMemberJoe = new RoleMember() .setMemberName("user.joe") .setPrincipalType(Principal.Type.USER.getValue()); RoleMember roleMemberJane = new RoleMember() .setMemberName("user.jane") .setPrincipalType(Principal.Type.USER.getValue()); RoleMember roleGroup1 = new RoleMember() .setMemberName("coretech:group.dev-team") .setPrincipalType(Principal.Type.GROUP.getValue()); roleMembers.add(roleMemberJoe); roleMembers.add(roleMemberJane); roleMembers.add(roleGroup1); Role role = new Role().setName("coretech:role.role1").setRoleMembers(roleMembers); assertTrue(AuthzHelper.isMemberOfRole(role, "user.joe", devTeamFetcher)); assertTrue(AuthzHelper.isMemberOfRole(role, "user.jane", devTeamFetcher)); assertFalse(AuthzHelper.isMemberOfRole(role, "user.john", devTeamFetcher)); assertTrue(AuthzHelper.isMemberOfRole(role, "user.valid", devTeamFetcher)); assertFalse(AuthzHelper.isMemberOfRole(role, "user.disabled", devTeamFetcher)); assertFalse(AuthzHelper.isMemberOfRole(role, "user.expired", devTeamFetcher)); assertFalse(AuthzHelper.isMemberOfRole(role, "user.unknown", devTeamFetcher)); }
@Test public void testIsMemberOfRoleNullMembers() { Role role = new Role().setName("coretech:role.role1"); assertFalse(AuthzHelper.isMemberOfRole(role, "user.joe", devTeamFetcher)); }