1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.spring.boot.autoconfigure.security.authentication;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.stream.Collectors;
25 import java.util.stream.Stream;
26 import lombok.Data;
27 import org.springframework.boot.context.properties.ConfigurationProperties;
28
29
30
31
32
33
34 @ConfigurationProperties(prefix = "bremersee.authentication")
35 @Data
36 public class AuthenticationProperties {
37
38
39
40
41 private RememberMeProperties rememberMe = new RememberMeProperties();
42
43
44
45
46 private JwtConverterProperties jwtConverter = new JwtConverterProperties();
47
48
49
50
51 private LdaptiveProperties ldaptive = new LdaptiveProperties();
52
53
54
55
56 public AuthenticationProperties() {
57 super();
58 }
59
60
61
62
63
64
65 @Data
66 public static class RememberMeProperties {
67
68
69
70
71 private String key;
72
73
74
75
76 private Boolean alwaysRemember;
77
78
79
80
81 private String cookieName;
82
83
84
85
86 private String cookieDomain;
87
88
89
90
91 private Boolean useSecureCookie;
92
93
94
95
96 private String parameterName;
97
98
99
100
101 private Integer tokenValiditySeconds;
102
103
104
105
106 public RememberMeProperties() {
107 super();
108 }
109 }
110
111
112
113
114 @Data
115 public static class JwtConverterProperties {
116
117
118
119
120 private String nameJsonPath = "$.sub";
121
122
123
124
125 private String firstNameJsonPath = "$.given_name";
126
127
128
129
130 private String lastNameJsonPath = "$.family_name";
131
132
133
134
135 private String emailJsonPath = "$.email";
136
137
138
139
140 private String rolesJsonPath = "$.scope";
141
142
143
144
145
146 private boolean rolesValueList = false;
147
148
149
150
151 private String rolesValueSeparator = " ";
152
153
154
155
156 private List<String> defaultRoles = new ArrayList<>();
157
158
159
160
161 private List<RoleMapping> roleMapping = new ArrayList<>();
162
163
164
165
166 private String rolePrefix = "SCOPE_";
167
168
169
170
171 private CaseTransformation roleCaseTransformation;
172
173
174
175
176 private List<StringReplacement> roleStringReplacements;
177
178
179
180
181 public JwtConverterProperties() {
182 super();
183 }
184
185
186
187
188
189
190 public Map<String, String> toRoleMappings() {
191 return Stream.ofNullable(getRoleMapping())
192 .flatMap(Collection::stream)
193 .collect(Collectors.toMap(
194 RoleMapping::getSource,
195 RoleMapping::getTarget,
196 (first, second) -> first,
197 LinkedHashMap::new));
198 }
199
200
201
202
203
204
205 public Map<String, String> toRoleStringReplacements() {
206 return Stream.ofNullable(getRoleStringReplacements())
207 .flatMap(Collection::stream)
208 .collect(Collectors.toMap(
209 StringReplacement::getRegex,
210 StringReplacement::getReplacement,
211 (first, second) -> first,
212 LinkedHashMap::new));
213 }
214
215 }
216
217
218
219
220 @Data
221 public static class LdaptiveProperties {
222
223
224
225
226 private Template template = Template.ACTIVE_DIRECTORY;
227
228
229
230
231 private UsernameToBindDnConverterProperty usernameToBindDnConverter;
232
233
234
235
236 private String userBaseDn;
237
238
239
240
241 private List<String> refusedUsernames;
242
243
244
245
246
247 private String userObjectClass;
248
249
250
251
252
253 private String usernameAttribute;
254
255
256
257
258
259 private String userRdnAttribute;
260
261
262
263
264
265
266
267
268 private String passwordAttribute;
269
270
271
272
273
274 private String passwordLastSetAttribute;
275
276
277
278
279
280 private String userFindOneFilter;
281
282
283
284
285 private SearchScope userFindOneSearchScope;
286
287
288
289
290 protected String firstNameAttribute;
291
292
293
294
295 protected String lastNameAttribute;
296
297
298
299
300 private String emailAttribute;
301
302
303
304
305 private AccountControlEvaluatorProperty accountControlEvaluator;
306
307
308
309
310 private GroupFetchStrategy groupFetchStrategy;
311
312
313
314
315 private String memberAttribute;
316
317
318
319
320
321 private String groupBaseDn;
322
323
324
325
326
327 private SearchScope groupSearchScope;
328
329
330
331
332
333 private String groupObjectClass;
334
335
336
337
338
339 private String groupIdAttribute;
340
341
342
343
344
345 private String groupMemberAttribute;
346
347
348
349
350
351 private String groupMemberFormat;
352
353
354
355
356 private List<RoleMapping> roleMapping;
357
358
359
360
361 private List<String> defaultRoles;
362
363
364
365
366 private String rolePrefix;
367
368
369
370
371 private CaseTransformation roleCaseTransformation;
372
373
374
375
376 private List<StringReplacement> roleStringReplacements;
377
378
379
380
381 public LdaptiveProperties() {
382 super();
383 }
384
385
386
387
388 public enum SearchScope {
389
390
391
392
393 OBJECT,
394
395
396
397
398 ONELEVEL,
399
400
401
402
403 SUBTREE,
404
405
406
407
408 SUBORDINATE
409 }
410
411
412
413
414 public enum UsernameToBindDnConverterProperty {
415
416
417
418
419 BY_USER_RDN_ATTRIBUTE,
420
421
422
423
424 BY_DOMAIN_EMAIL
425 }
426
427
428
429
430 public enum AccountControlEvaluatorProperty {
431
432
433
434
435 NONE,
436
437
438
439
440 ACTIVE_DIRECTORY
441 }
442
443
444
445
446 public enum GroupFetchStrategy {
447
448
449
450
451 NONE,
452
453
454
455
456 USER_CONTAINS_GROUPS,
457
458
459
460
461 GROUP_CONTAINS_USERS
462 }
463
464
465
466
467
468
469 public enum Template {
470
471
472
473
474 ACTIVE_DIRECTORY,
475
476
477
478
479 OPEN_LDAP,
480
481
482
483
484 USER_CONTAINS_GROUPS,
485
486
487
488
489 GROUP_CONTAINS_USERS
490 }
491 }
492
493
494
495
496 @Data
497 public static class RoleMapping {
498
499 private String source;
500
501 private String target;
502
503
504
505
506 public RoleMapping() {
507 super();
508 }
509 }
510
511
512
513
514 public enum CaseTransformation {
515
516
517
518
519 NONE,
520
521
522
523
524 TO_UPPER_CASE,
525
526
527
528
529 TO_LOWER_CASE
530 }
531
532
533
534
535 @Data
536 public static class StringReplacement {
537
538
539
540
541
542 private String regex;
543
544
545
546
547 private String replacement;
548
549
550
551
552 public StringReplacement() {
553 super();
554 }
555 }
556
557 }