90 lines
2.0 KiB
Java
90 lines
2.0 KiB
Java
package com.zhangmeng.fiction.server.dto;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import com.zhangmeng.fiction.server.entity.Permission;
|
|
import com.zhangmeng.fiction.server.entity.User;
|
|
import lombok.Data;
|
|
import lombok.EqualsAndHashCode;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @author zhangmeng
|
|
* @version 1.0
|
|
* @date 2020年11月13日15:37:45
|
|
*/
|
|
@Data
|
|
@EqualsAndHashCode(callSuper = false)
|
|
public class LoginUser extends User implements UserDetails {
|
|
|
|
private List<Permission> permissions;
|
|
|
|
private String token;
|
|
|
|
/**
|
|
* 登陆时间戳(毫秒)
|
|
*/
|
|
private Long loginTime;
|
|
/**
|
|
* 过期时间戳
|
|
*/
|
|
private Long expireTime;
|
|
|
|
@Override
|
|
@JsonIgnore
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
return permissions.parallelStream().filter(permission -> !StringUtils.isEmpty(permission.getTitle()))
|
|
.map(permission -> new SimpleGrantedAuthority(permission.getTitle())).collect(Collectors.toSet());
|
|
}
|
|
|
|
/**
|
|
* 账户是否未过期
|
|
*
|
|
* @return boolean
|
|
*/
|
|
@Override
|
|
@JsonIgnore
|
|
public boolean isAccountNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 账户是否未锁定
|
|
*
|
|
* @return boolean
|
|
*/
|
|
@Override
|
|
@JsonIgnore
|
|
public boolean isAccountNonLocked() {
|
|
return getStatus() != Status.LOCKED;
|
|
}
|
|
|
|
/**
|
|
* 密码是否未过期
|
|
*
|
|
* @return boolean
|
|
*/
|
|
@Override
|
|
@JsonIgnore
|
|
public boolean isCredentialsNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 账户是否激活
|
|
*
|
|
* @return boolean
|
|
*/
|
|
@Override
|
|
@JsonIgnore
|
|
public boolean isEnabled() {
|
|
return true;
|
|
}
|
|
}
|