其他分享
首页 > 其他分享> > spring-Security《一》

spring-Security《一》

作者:互联网

源码介绍:
public interface UserDetailsService {
    UserDetails loadUserByUsername(String var1) throws UsernameNotFoundException;
}

 里面返回一个UserDetails,来看下UserDetails里面是什么

public interface UserDetails extends Serializable {
    Collection<? extends GrantedAuthority> getAuthorities();

    String getPassword();  密码

    String getUsername(); 用户名

    boolean isAccountNonExpired(); 账号是否被过期

    boolean isAccountNonLocked();账号是否被锁定

    boolean isCredentialsNonExpired(); 证书(密码)是否过期

    boolean isEnabled();账号是否被启用
}

 UserDetails也是个接口,那么他肯定有实现类

里面果然有个User去实现它

 

 看下User是什么东东

 

 属性是与接口对应,有两个构造函数

用户名,密码,授权
    public User(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        this(username, password, true, true, true, true, authorities);
    }

就是那一堆属性构造方法了
    public User(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
        if (username != null && !"".equals(username) && password != null) {
            this.username = username;
            this.password = password;
            this.enabled = enabled;
            this.accountNonExpired = accountNonExpired;
            this.credentialsNonExpired = credentialsNonExpired;
            this.accountNonLocked = accountNonLocked;
            this.authorities = Collections.unmodifiableSet(sortAuthorities(authorities));
        } else {
            throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
        }
    }

 

标签:username,String,spring,boolean,authorities,Security,password,UserDetails
来源: https://www.cnblogs.com/wangbiaohistory/p/16244273.html