shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.iplatform.base;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.iplatform.model.po.S_user_core;
import com.walker.web.DataStatus;
import com.walker.web.LoginType;
import com.walker.web.UserType;
import com.walker.web.principal.AbstractUserPrincipal;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 平台默认的用户凭证对象,主要用于登录认证、权限拦截判断使用。
 * 业务模块不会使用该对象。
 * @author 时克英
 * @date 2022-10-31
 */
public class DefaultUserPrincipal extends AbstractUserPrincipal<S_user_core> {
 
    private long lastLoginTime = 0;
    private LoginType lastLoginType = LoginType.UserPassword;
 
    private List<String> roleIdList = new ArrayList<>(4);
 
    // 2022-12-21 用户菜单对应的数据权限
    // key = menuId, value = dept_org(如:本单位)
    private Map<String, String> dataScopeMap = new HashMap<>();
 
    public DefaultUserPrincipal(){}
 
    public DefaultUserPrincipal(S_user_core user_core){
        if(user_core == null){
            throw new IllegalArgumentException("user info is required!");
        }
        this.setUserInfo(user_core);
        this.setId(String.valueOf(user_core.getId()));
        this.setUserName(user_core.getUser_name());
        this.setPassword(user_core.getPassword());
    }
 
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return this.getUserInfo().getStatus() == DataStatus.CONST_NORMAL;
    }
 
    @JsonIgnore
    @Override
    public boolean isTokenExpired(String token) {
        // 这里暂未实现,集成后腰修改
        return false;
    }
 
    @JsonIgnore
    @Override
    public boolean isAccountLocked() {
        // 这里暂未实现,集成后腰修改
        return false;
    }
 
    @JsonIgnore
    @Override
    public boolean validateMd5Password(String encryption) {
        return false;
    }
 
    @Override
    public long getLastLoginTime() {
        return this.lastLoginTime;
    }
 
    @Override
    public LoginType getLastLoginType() {
        return this.lastLoginType;
    }
 
    public void setLastLoginTime(long loginTime){
        this.lastLoginTime = loginTime;
    }
 
    public void setLastLoginType(LoginType loginType){
        this.lastLoginType = loginType;
    }
 
    /**
     * 返回该用户拥有的角色ID集合。
     * @return
     */
    public List<String> getRoleIdList() {
        return roleIdList;
    }
 
    public void setRoleIdList(List<String> roleIdList) {
        this.roleIdList = roleIdList;
    }
 
    @JsonIgnore
    @Override
    public boolean isSupervisor() {
        return this.getUserInfo().getUser_type().intValue() == UserType.TYPE_SUPER;
    }
 
    /**
     * 添加一条数据权限
     * @param menuId 菜单ID,对应一个功能
     * @param dataScopeValue 数据权限标识
     * @date 2022-12-21
     */
    @JsonIgnore
    public void addDataScope(String menuId, String dataScopeValue){
        this.dataScopeMap.put(menuId, dataScopeValue);
    }
    public void setDataScopeMap(Map<String, String> dataScopeMap){
        this.dataScopeMap = dataScopeMap;
    }
 
    /**
     * 根据菜单ID,查询是否具有特定的数据权限。
     * @param menuId
     * @return
     * @date 2022-12-21
     */
    @JsonIgnore
    @Override
    public String getDataScope(String menuId){
        return this.dataScopeMap.get(menuId);
    }
 
    public Map<String, String> getDataScopeMap(){
        return this.dataScopeMap;
    }
 
    /**
     * 该方法测试redis序列化使用,暂时不用。
     * @param user_core
     * @date 2022-11-15
     */
    @Deprecated
    public void setup(S_user_core user_core){
        this.setUserInfo(user_core);
        this.setId(String.valueOf(user_core.getId()));
        this.setUserName(user_core.getUser_name());
        this.setPassword(user_core.getPassword());
    }
}