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.List;
20 import java.util.Map;
21 import lombok.AccessLevel;
22 import lombok.Getter;
23 import lombok.ToString;
24 import lombok.extern.slf4j.Slf4j;
25 import org.bremersee.data.ldaptive.reactive.ReactiveLdaptiveOperations;
26 import org.ldaptive.FilterTemplate;
27 import org.ldaptive.SearchRequest;
28 import org.ldaptive.SearchScope;
29 import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
30 import org.springframework.security.core.userdetails.UserDetails;
31 import reactor.core.publisher.Mono;
32
33
34
35
36
37
38 @ToString(callSuper = true, exclude = {"ldaptiveOperations"})
39 @Slf4j
40 public class ReactiveLdaptiveUserDetailsService extends AbstractUserDetailsService implements
41 ReactiveUserDetailsService {
42
43 @Getter(value = AccessLevel.PROTECTED)
44 private final ReactiveLdaptiveOperations ldaptiveOperations;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public ReactiveLdaptiveUserDetailsService(
61 ReactiveLdaptiveOperations ldaptiveOperations,
62 String userBaseDn,
63 String userFindOneFilter,
64 SearchScope userFindOneSearchScope,
65 String userAccountControlAttributeName,
66 List<String> authorities,
67 String authorityAttributeName,
68 boolean authorityDn,
69 Map<String, String> authorityMap,
70 String authorityPrefix) {
71
72 super(
73 userBaseDn, userFindOneFilter, userFindOneSearchScope, userAccountControlAttributeName, authorities,
74 authorityAttributeName, authorityDn, authorityMap, authorityPrefix);
75 this.ldaptiveOperations = ldaptiveOperations;
76 }
77
78 @Override
79 public Mono<UserDetails> findByUsername(String userName) {
80 return getLdaptiveOperations()
81 .findOne(
82 SearchRequest.builder()
83 .dn(getUserBaseDn())
84 .filter(FilterTemplate.builder()
85 .filter(getUserFindOneFilter())
86 .parameters(userName)
87 .build())
88 .scope(getUserFindOneSearchScope())
89 .returnAttributes(returnAttributes())
90 .sizeLimit(1)
91 .build(),
92 getUserDetailsLdapMapper(userName));
93 }
94
95 }