SSOStubPersonAttributeDao.java
3.53 KB
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
package weaver.authentication.dao;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.jasig.services.persondir.IPersonAttributes;
import org.jasig.services.persondir.support.AttributeNamedPersonImpl;
import org.jasig.services.persondir.support.StubPersonAttributeDao;
import org.springframework.util.LinkedCaseInsensitiveMap;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by crazyDream on 2018/9/17.
*/
public class SSOStubPersonAttributeDao extends StubPersonAttributeDao {
@NotNull
private SSOUserDaoJdbc ssoUserDaoJdbc;
@NotNull
private String userNameAttribute;
public void setSsoUserDaoJdbc(SSOUserDaoJdbc ssoUserDaoJdbc) {
this.ssoUserDaoJdbc = ssoUserDaoJdbc;
}
public void setUserNameAttribute(String userNameAttribute) {this.userNameAttribute = userNameAttribute;}
@Override
public IPersonAttributes getPerson(String uid) {
Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
try {
Map<String,Object> user = ssoUserDaoJdbc.getSSOUserByUsernameMap(uid);
List<Object> relatedAccount = (List<Object>)ssoUserDaoJdbc.getRelatedAccountByUsername(uid);
//用户密码正确且用户未锁定,封装返回参数
attributes.put("id", Collections.singletonList(user.get("id")));
attributes.put("loginid",Collections.singletonList(user.get("loginid")));
attributes.put("lastname", Collections.singletonList(user.get("lastname")));
attributes.put("sex", Collections.singletonList(user.get("sex")));
attributes.put("birthday", Collections.singletonList(user.get("birthday")));
attributes.put("systemlanguage", Collections.singletonList(user.get("systemlanguage")));
attributes.put("telephone", Collections.singletonList(user.get("telephone")));
attributes.put("mobile", Collections.singletonList(user.get("mobile")));
attributes.put("email", Collections.singletonList(user.get("email")));
attributes.put("departmentid", Collections.singletonList(user.get("departmentid")));
attributes.put("subcompanyid", Collections.singletonList(user.get("subcompanyid1")));
attributes.put("managerid", Collections.singletonList(user.get("managerid")));
attributes.put("assistantid", Collections.singletonList(user.get("assistantid")));
attributes.put("workcode", Collections.singletonList(user.get("workcode")));
attributes.put("status", Collections.singletonList(user.get("status")));
attributes.put("countryid", Collections.singletonList(user.get("countryid")));
attributes.put("password", Collections.singletonList(user.get("password")));
//用户关联账号信息,转化一下
if (relatedAccount!=null&&relatedAccount.size()>0) {
JSONArray jsonArray = new JSONArray();
for (Object o : relatedAccount) {
LinkedCaseInsensitiveMap linkedCaseInsensitiveMap = (LinkedCaseInsensitiveMap) o;
jsonArray.add(JSONObject.fromObject(linkedCaseInsensitiveMap));
}
attributes.put("relatedAccount", Collections.<Object>singletonList(jsonArray.toString()));
}
} catch (Exception e) {
e.printStackTrace();
}
return new AttributeNamedPersonImpl(this.userNameAttribute,attributes);
}
}