Hi guys,
In my project, I am associating Areas with GrantedAuthority. For example:
And now, I need put this authorities using UserDetails interface. But, UserDetails not used MapBasedAttributes2GrantedAuthoritiesMapper (It's understood that I am using AuthenticationUserDetailsService).Code: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);
I'm afraid I'll have to create a custom UserDetails and custom AuthenticationUserDetailsService, and use them in my custom AuthenticationManager. Am I wrong?Code: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; }


Reply With Quote