简单继承UserDetailsService

来源:互联网 发布:不用软件 鼠标控制 编辑:程序博客网 时间:2024/06/05 15:07
public class UserService implements UserDetailsService {
   
    public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException, DataAccessException {
        // TODO Auto-generated method stub
        GrantedAuthorityImpl grant = new GrantedAuthorityImpl("ROLE_SUPERVISOR");
        GrantedAuthority[] arrayAuths = {grant};
        //这里的后果就是无论什么用户名只要是这个密码就认可他
        //并且给他ROLE_SUPERVISOR的权限
        return new User(arg0, "koala", true, 
                                 true, true, true, arrayAuths);
    }

}

 UserDetailsService的功能,依照现在的理解UserDetailsService返回一个UserDetails用于验证用户名和密码
按照docbook上的说法
Remember the advantage that whatever your UserDetailsService returns can always be obtained from the SecurityContextHolder, as per the above code fragment.

那是否应该理解为SecurityContext.getAuthentication().getPrincipal()得到的就是由UserDetailsService返回的?
go on....
原创粉丝点击