Java Code Examples for org.springframework.security.core.authority.SimpleGrantedAuthority#getAuthority()

The following examples show how to use org.springframework.security.core.authority.SimpleGrantedAuthority#getAuthority() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KylinUserGroupService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, List<String>> getGroupMembersMap() throws IOException {
    Map<String, List<String>> result = Maps.newHashMap();
    List<ManagedUser> users = userService.listUsers();
    for (ManagedUser user : users) {
        for (SimpleGrantedAuthority authority : user.getAuthorities()) {
            String role = authority.getAuthority();
            List<String> usersInGroup = result.get(role);
            if (usersInGroup == null) {
                result.put(role, Lists.newArrayList(user.getUsername()));
            } else {
                usersInGroup.add(user.getUsername());
            }
        }
    }
    return result;
}
 
Example 2
Source File: KylinUserGroupService.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, List<String>> getGroupMembersMap() throws IOException {
    Map<String, List<String>> result = Maps.newHashMap();
    List<ManagedUser> users = userService.listUsers();
    for (ManagedUser user : users) {
        for (SimpleGrantedAuthority authority : user.getAuthorities()) {
            String role = authority.getAuthority();
            List<String> usersInGroup = result.get(role);
            if (usersInGroup == null) {
                result.put(role, Lists.newArrayList(user.getUsername()));
            } else {
                usersInGroup.add(user.getUsername());
            }
        }
    }
    return result;
}
 
Example 3
Source File: CustomTokenEnhancer.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 5 votes vote down vote up
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    final Map<String, Object> additionalInfo = new HashMap<>();
    Collection<GrantedAuthority> authorities = authentication.getAuthorities();
    Object[] ga = authorities.toArray();
    SimpleGrantedAuthority sga = (SimpleGrantedAuthority) ga[0];
    String role = sga.getAuthority();
    additionalInfo.put("role", role);
    ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
    return accessToken;
}
 
Example 4
Source File: CustomTokenEnhancer.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 5 votes vote down vote up
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    final Map<String, Object> additionalInfo = new HashMap<>();
    Collection<GrantedAuthority> authorities = authentication.getAuthorities();
    Object[] ga = authorities.toArray();
    SimpleGrantedAuthority sga = (SimpleGrantedAuthority) ga[0];
    String role = sga.getAuthority();
    additionalInfo.put("role", role);
    ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
    return accessToken;
}