Announcement Announcement Module
No announcement yet.
MapBasedAttributes2GrantedAuthoritiesMapper and UserDetails. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MapBasedAttributes2GrantedAuthoritiesMapper and UserDetails.

    Hi guys,

    In my project, I am associating Areas with GrantedAuthority. For example:

    MapBasedAttributes2GrantedAuthoritiesMapper grantedAuthoritiesMap 
                                          = new MapBasedAttributes2GrantedAuthoritiesMapper();
    Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
    grantedAuthorities.add(new SimpleGrantedAuthority("admin"));
    grantedAuthoritiesMap.put("company_a", grantedAuthorities);
    // Not possible
    UserDetails userDetails = new MyUserDetails("user", "password", grantedAuthoritiesMap);
    And now, I need put this authorities using UserDetails interface. But, UserDetails not used MapBasedAttributes2GrantedAuthoritiesMapper (It's understood that I am using AuthenticationUserDetailsService).

    public interface UserDetails extends Serializable {
        Collection<? extends GrantedAuthority> getAuthorities();
        String getPassword();
        String getUsername();
        boolean isAccountNonExpired();
        boolean isAccountNonLocked();
        boolean isCredentialsNonExpired();
        boolean isEnabled();
    public interface AuthenticationUserDetailsService<T extends Authentication> {
        UserDetails loadUserDetails(T token) throws UsernameNotFoundException;
    I'm afraid I'll have to create a custom UserDetails and custom AuthenticationUserDetailsService, and use them in my custom AuthenticationManager. Am I wrong?