All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.common.LoginUserVo.ftl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package ${packageName}.common.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/***
 * 登录用户身份权限
 *
 * @author Co.
 * @date: 2022/10/14 19:42
 * @return
 */
@Data
public class LoginUserVo implements UserDetails {

    private static final long serialVersionUID = 1L;

    /**
     * 用户唯一标识
     */
    private String token;

    /**
     * 权限列表
     */
    private List permissions;

    /**
     * 用户信息
     */
    private Map user;

    public LoginUserVo() {
    }

    public LoginUserVo(Map user, List permissions) {
        this.user = user;
        this.permissions = permissions;
    }

    @Override
    @JsonIgnore
    public Collection getAuthorities() {
        List authorities = new ArrayList<>(permissions.size());
        for (Map permission : permissions) {
            authorities.add(new SimpleGrantedAuthority(permission.get("path").toString()));
        }
        return authorities;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用 ,禁用的用户不能身份验证
     */
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy