1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.security.core.userdetails;
18
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 import lombok.AccessLevel;
24 import lombok.Getter;
25 import lombok.ToString;
26 import org.bremersee.data.ldaptive.LdaptiveEntryMapper;
27 import org.ldaptive.SearchScope;
28 import org.springframework.security.core.userdetails.UserDetails;
29 import org.springframework.util.StringUtils;
30
31
32
33
34
35
36 @ToString
37 public abstract class AbstractUserDetailsService {
38
39 @Getter(value = AccessLevel.PROTECTED)
40 private final String userBaseDn;
41
42 @Getter(value = AccessLevel.PROTECTED)
43 private final String userFindOneFilter;
44
45 @Getter(value = AccessLevel.PROTECTED)
46 private final SearchScope userFindOneSearchScope;
47
48 @Getter(value = AccessLevel.PROTECTED)
49 private final String userAccountControlAttributeName;
50
51 @Getter(value = AccessLevel.PROTECTED)
52 private final List<String> authorities;
53
54 @Getter(value = AccessLevel.PROTECTED)
55 private final String authorityAttributeName;
56
57 @Getter(value = AccessLevel.PROTECTED)
58 private final boolean authorityDn;
59
60 @Getter(value = AccessLevel.PROTECTED)
61 private final Map<String, String> authorityMap;
62
63 @Getter(value = AccessLevel.PROTECTED)
64 private final String authorityPrefix;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 public AbstractUserDetailsService(
80 String userBaseDn,
81 String userFindOneFilter,
82 SearchScope userFindOneSearchScope,
83 String userAccountControlAttributeName,
84 List<String> authorities,
85 String authorityAttributeName,
86 boolean authorityDn,
87 Map<String, String> authorityMap,
88 String authorityPrefix) {
89
90 this.userBaseDn = userBaseDn;
91 this.userFindOneFilter = userFindOneFilter;
92 this.userFindOneSearchScope = userFindOneSearchScope != null ? userFindOneSearchScope : SearchScope.ONELEVEL;
93 this.userAccountControlAttributeName = userAccountControlAttributeName;
94 this.authorities = authorities;
95 this.authorityAttributeName = authorityAttributeName;
96 this.authorityDn = authorityDn;
97 this.authorityMap = authorityMap;
98 this.authorityPrefix = authorityPrefix;
99 }
100
101
102
103
104
105
106 protected Set<String> returnAttributes() {
107 Set<String> attributes = new HashSet<>();
108 if (StringUtils.hasText(userAccountControlAttributeName)) {
109 attributes.add(userAccountControlAttributeName);
110 }
111 if (StringUtils.hasText(authorityAttributeName)) {
112 attributes.add(authorityAttributeName);
113 }
114 return attributes;
115 }
116
117
118
119
120
121
122
123 protected LdaptiveEntryMapper<UserDetails> getUserDetailsLdapMapper(String userName) {
124 return new UserDetailsLdapMapper(
125 userName,
126 userAccountControlAttributeName,
127 authorities,
128 authorityAttributeName,
129 authorityDn,
130 authorityMap,
131 authorityPrefix);
132 }
133
134 }