86 lines
2.2 KiB
Java
86 lines
2.2 KiB
Java
package com.cnbm.admin.entity;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
import lombok.Data;
|
|
import lombok.NoArgsConstructor;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @Author weihongyang
|
|
* @Date 2022/6/8 1:56 PM
|
|
* @Version 1.0
|
|
*/
|
|
@Data
|
|
@NoArgsConstructor
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
public class LoginUser implements UserDetails{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private SysUserEntity sysUserEntity;
|
|
|
|
private List<String> permissions;
|
|
|
|
public LoginUser(SysUserEntity sysUserEntity, List<String> permissions) {
|
|
this.sysUserEntity = sysUserEntity;
|
|
this.permissions = permissions;
|
|
}
|
|
|
|
@JsonIgnore
|
|
private List<SimpleGrantedAuthority> authorities;
|
|
@Override
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
if(authorities!=null){
|
|
return authorities;
|
|
}
|
|
//把permissions中String类型的权限信息封装成SimpleGrantedAuthority对象
|
|
// authorities = new ArrayList<>();
|
|
// for (String permission : permissions) {
|
|
// SimpleGrantedAuthority authority = new SimpleGrantedAuthority(permission);
|
|
// authorities.add(authority);
|
|
// }
|
|
authorities = permissions.stream()
|
|
.map(SimpleGrantedAuthority::new)
|
|
.collect(Collectors.toList());
|
|
return authorities;
|
|
}
|
|
|
|
@Override
|
|
public String getPassword() {
|
|
return sysUserEntity.getPassword();
|
|
}
|
|
|
|
@Override
|
|
public String getUsername() {
|
|
return sysUserEntity.getUsername();
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonLocked() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCredentialsNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled() {
|
|
return true;
|
|
}
|
|
}
|
|
|