AuthenticationServiceImpl implements AuthenticationService { @Override public boolean hasRoleInRoleArray(String[] rolesToCompare, String[] rolesBaseline) { for (String testRole: rolesToCompare){ if (testRole == null) continue; for (String myrole: rolesBaseline) { if (myrole == null) continue; if(myrole.equals(testRole)) return true; if(testRole.endsWith("*") && myrole.contains(StringUtils.substringBefore(testRole, "-") + "-")) return true; } } return false; }  void setUserDao(UserDao userDao); void setUserPendingDao(UserPendingDao userPendingDao); @Override User getAuthenticatedUser(); @Override boolean isAuthenticated(); @Override boolean isAuthenticatedWaspUser(); @SuppressWarnings("unchecked") @Override String[] getRoles(); @Override boolean isExternallyAuthenticated(); @Override boolean isAuthenticationSetExternal(); @Override boolean isAuthenticatedGuest(); @Override boolean hasRole(String theRole); @Override boolean hasRoleInRoleArray(String[] rolesToCompare, String[] rolesBaseline); @Override Integer getRoleValue(String role); @Override boolean hasRoleInRoleArray(String[] rolesToCompare); @Override boolean isSuperUser(); @Override boolean isFacilityMember(); @Override boolean isOnlyDepartmentAdministrator(); @Override boolean authenticate(String name, String password); @Override boolean authenticates(String name, String password); @Override boolean isLoginNameWellFormed(String login); @Override boolean isLoginAlreadyInUse(String login, String email); @Override String encodePassword(String s); @Override boolean validatePassword(String s); @Override boolean matchPassword(String s1, String s2); @Override String getRandomPassword(int length); @Override Set<Integer> idsOfDepartmentsManagedByCurrentUser(); @Override Set<Integer> idsOfLabsManagedByCurrentUser(); @Override boolean isThisExistingUserPIPending();  }
@Test public void hasRoleInRoleArray(){ String rolesToCompare [] = {"da","fm", "sa"}; String rolesBaseline [] = {"da","fm", "sa"}; String rolesToCompare2 [] = {null, null, null}; String rolesBaseline2 [] = {"da","fm", "sa"}; String rolesToCompare3 [] = {"da", "fm", "sa"}; String rolesBaseline3[] = {"asd","asd", "asd"}; String rolesToCompare4 [] = {"da", "fm", "sa"}; String rolesBaseline4 [] = {null,"fm", "sa"}; Assert.assertTrue(authServiceImpl.hasRoleInRoleArray(rolesToCompare, rolesBaseline)); Assert.assertFalse(authServiceImpl.hasRoleInRoleArray(rolesToCompare2, rolesBaseline2)); Assert.assertFalse(authServiceImpl.hasRoleInRoleArray(rolesToCompare3, rolesBaseline3)); }