security需要一个user的实体类实现UserDetails接口,该实体类最后与系统中用户的实体类分开,代码如下:
public class SecurityUser implements UserDetails{ private static final long serialVersionUID = 1L; private String password; private String name; List<GrantedAuthority> authorities; public User(string name,string password) { this.id = id; this.password = password; this.name = name; this.age = age; } public void setAuthorities(List<GrantedAuthority> authorities) { this.authorities = authorities; } @Override public Collection<GrantedAuthority> getAuthorities() { return this.authorities; } @Override //获取校验用户名 public String getUsername() { return String.valueOf(this.id); } @Override //获取校验用密码 public String getPassword() { return password; } @Override //账户是否未过期 public boolean isAccountNonExpired() { // TODO Auto-generated method stub return true; } @Override //账户是否未锁定 public boolean isAccountNonLocked() { // TODO Auto-generated method stub return true; } @Override //帐户密码是否未过期,一般有的密码要求性高的系统会使用到,比较每隔一段时间就要求用户重置密码 public boolean isCredentialsNonExpired() { // TODO Auto-generated method stub return true; } @Override //账户是否可用 public boolean isEnabled() { // TODO Auto-generated method stub return true; } }springboot+security整合1 (2)
内容版权声明:除非注明,否则皆为本站原创文章。