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

com.flyfish.oauth.domain.raw.SSOUserInfo Maven / Gradle / Ivy

package com.flyfish.oauth.domain.raw;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.flyfish.oauth.common.OAuthContext;
import com.flyfish.oauth.configuration.OAuth2SsoProperties;
import com.flyfish.oauth.domain.enums.UserStatus;
import com.flyfish.oauth.domain.enums.UserType;
import com.flyfish.oauth.domain.to.ClientAuthority;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * 公共用户数据,来自资源服务器
 *
 * @author wangyu
 */
@Getter
@Setter
public class SSOUserInfo extends Domain {

    /**
     * id
     */
    private String id;

    /**
     * 编码
     */
    private String code;

    /**
     * 名称
     */
    private String name;

    /**
     * 用户类型
     */
    private UserType userType;

    /**
     * 用户状态
     */
    private UserStatus userStatus;

    /**
     * 电话号码
     */
    private String phone;

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

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

    /**
     * 是否启用
     */
    private Boolean enable;

    /**
     * 有效期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date expireDate;

    /**
     * 关联的本地用户
     */
    private List linkedUsers;

    /**
     * 所属部门
     */
    private List organizations;

    /**
     * 权限
     */
    private List authorities;

    /**
     * 通过clientId获取当前本地用户
     */
    public LocalUser localUser() {
        OAuth2SsoProperties properties = OAuthContext.getProperties();
        if (null != properties) {
            String clientId = properties.getClientId();
            // 筛选
            if (CollectionUtils.isNotEmpty(linkedUsers)) {
                for (LocalUser user : linkedUsers) {
                    if (clientId.equals(user.getClientId())) {
                        return user;
                    }
                }
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy