@Test public void testGetRolesForUser() { List<String> roles = Arrays.asList("admin", "user"); underTest.getSimpleRolesMap().put("user1", roles); List<GrantedAuthority> result1 = underTest.getRolesForUser("user1"); List<GrantedAuthority> result2 = underTest.getRolesForUser("user2"); Assert.assertEquals(result1.size(), 2); Assert.assertEquals(result2.size(), 0); }
public List<GrantedAuthority> getRolesForUser(String user) { List<GrantedAuthority> authorities = new ArrayList<>(); if (authPropsConfig.isFileAuthorization()) { List<String > roles = simpleRolesMap.get(user); if (!Collections.isEmpty(roles)) { for (String role : roles) { String roleName = "ROLE_" + role; logger.debug("Found role '{}' for user '{}'", roleName, user); authorities.add(createRoleWithReadPrivilage(roleName)); } } else { logger.warn("Not found roles for user '{}'", user); } return authorities; } else { return createDefaultAuthorities(); } }
RoleDao { public List<GrantedAuthority> getRolesForUser(String user) { List<GrantedAuthority> authorities = new ArrayList<>(); if (authPropsConfig.isFileAuthorization()) { List<String > roles = simpleRolesMap.get(user); if (!Collections.isEmpty(roles)) { for (String role : roles) { String roleName = "ROLE_" + role; logger.debug("Found role '{}' for user '{}'", roleName, user); authorities.add(createRoleWithReadPrivilage(roleName)); } } else { logger.warn("Not found roles for user '{}'", user); } return authorities; } else { return createDefaultAuthorities(); } } }
RoleDao { public List<GrantedAuthority> getRolesForUser(String user) { List<GrantedAuthority> authorities = new ArrayList<>(); if (authPropsConfig.isFileAuthorization()) { List<String > roles = simpleRolesMap.get(user); if (!Collections.isEmpty(roles)) { for (String role : roles) { String roleName = "ROLE_" + role; logger.debug("Found role '{}' for user '{}'", roleName, user); authorities.add(createRoleWithReadPrivilage(roleName)); } } else { logger.warn("Not found roles for user '{}'", user); } return authorities; } else { return createDefaultAuthorities(); } }  }
RoleDao { public List<GrantedAuthority> getRolesForUser(String user) { List<GrantedAuthority> authorities = new ArrayList<>(); if (authPropsConfig.isFileAuthorization()) { List<String > roles = simpleRolesMap.get(user); if (!Collections.isEmpty(roles)) { for (String role : roles) { String roleName = "ROLE_" + role; logger.debug("Found role '{}' for user '{}'", roleName, user); authorities.add(createRoleWithReadPrivilage(roleName)); } } else { logger.warn("Not found roles for user '{}'", user); } return authorities; } else { return createDefaultAuthorities(); } }  @SuppressWarnings("unchecked") @PostConstruct void init(); List<GrantedAuthority> getRolesForUser(String user); Map<String, List<String>> getSimpleRolesMap(); @VisibleForTesting void setAuthPropsConfig(AuthPropsConfig authPropsConfig); static List<GrantedAuthority> createDefaultAuthorities(); }
RoleDao { public List<GrantedAuthority> getRolesForUser(String user) { List<GrantedAuthority> authorities = new ArrayList<>(); if (authPropsConfig.isFileAuthorization()) { List<String > roles = simpleRolesMap.get(user); if (!Collections.isEmpty(roles)) { for (String role : roles) { String roleName = "ROLE_" + role; logger.debug("Found role '{}' for user '{}'", roleName, user); authorities.add(createRoleWithReadPrivilage(roleName)); } } else { logger.warn("Not found roles for user '{}'", user); } return authorities; } else { return createDefaultAuthorities(); } }  @SuppressWarnings("unchecked") @PostConstruct void init(); List<GrantedAuthority> getRolesForUser(String user); Map<String, List<String>> getSimpleRolesMap(); @VisibleForTesting void setAuthPropsConfig(AuthPropsConfig authPropsConfig); static List<GrantedAuthority> createDefaultAuthorities();  }