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

matrix.business.oauth2.dto.DefaultUserDetailDto Maven / Gradle / Ivy

package matrix.business.oauth2.dto;

import matrix.boot.common.utils.StringUtil;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author wangcheng
 * 2021/8/31
 **/
public class DefaultUserDetailDto implements UserDetails {

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private transient String password;

    /**
     * 用户权限数据,多个用逗号(,)分隔,角色标识必须为ROLE_开头
     */
    private String authorities;

    /**
     * 账号是否失效
     */
    private boolean accountExpired;

    /**
     * 账号是否锁定
     */
    private boolean accountLocked;

    /**
     * 密码是否失效
     */
    private boolean credentialsExpired;

    /**
     * 是否禁用
     */
    private boolean disabled;

    /**
     * 附件信息
     */
    private Map extInfo;

    @Override
    public Collection getAuthorities() {
        Set result = new HashSet<>();
        if (!StringUtil.isEmpty(authorities)) {
            for (String authority : authorities.split(",")) {
                result.add((GrantedAuthority) () -> authority);
            }
        }
        return result;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return !this.accountExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !this.accountLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return !this.credentialsExpired;
    }

    @Override
    public boolean isEnabled() {
        return !this.disabled;
    }

    public DefaultUserDetailDto setUsername(String username) {
        this.username = username;
        return this;
    }

    public DefaultUserDetailDto setPassword(String password) {
        this.password = password;
        return this;
    }

    public DefaultUserDetailDto setAuthorities(String authorities) {
        this.authorities = authorities;
        return this;
    }

    public boolean isAccountExpired() {
        return accountExpired;
    }

    public DefaultUserDetailDto setAccountExpired(boolean accountExpired) {
        this.accountExpired = accountExpired;
        return this;
    }

    public boolean isAccountLocked() {
        return accountLocked;
    }

    public DefaultUserDetailDto setAccountLocked(boolean accountLocked) {
        this.accountLocked = accountLocked;
        return this;
    }

    public boolean isCredentialsExpired() {
        return credentialsExpired;
    }

    public DefaultUserDetailDto setCredentialsExpired(boolean credentialsExpired) {
        this.credentialsExpired = credentialsExpired;
        return this;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public DefaultUserDetailDto setDisabled(boolean disabled) {
        this.disabled = disabled;
        return this;
    }

    public Map getExtInfo() {
        return extInfo;
    }

    public void setExtInfo(Map extInfo) {
        this.extInfo = extInfo;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy