1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
28
28
import org .springframework .security .authentication .AuthenticationDetailsSource ;
29
29
import org .springframework .security .authentication .AuthenticationManager ;
30
+ import org .springframework .security .config .Customizer ;
30
31
import org .springframework .security .config .annotation .web .HttpSecurityBuilder ;
31
32
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
32
33
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
@@ -148,6 +149,24 @@ public AttributeExchangeConfigurer attributeExchange(String identifierPattern) {
148
149
return attributeExchangeConfigurer ;
149
150
}
150
151
152
+ /**
153
+ * Sets up OpenID attribute exchange for OpenIDs matching the specified pattern.
154
+ * The default pattern is ".*", it can be specified using
155
+ * {@link AttributeExchangeConfigurer#identifierPattern(String)}
156
+ *
157
+ * @param attributeExchangeCustomizer the {@link Customizer} to provide more options for
158
+ * the {@link AttributeExchangeConfigurer}
159
+ * @return a {@link OpenIDLoginConfigurer} for further customizations
160
+ * @throws Exception
161
+ */
162
+ public OpenIDLoginConfigurer <H > attributeExchange (Customizer <AttributeExchangeConfigurer > attributeExchangeCustomizer )
163
+ throws Exception {
164
+ AttributeExchangeConfigurer attributeExchangeConfigurer = new AttributeExchangeConfigurer (".*" );
165
+ attributeExchangeCustomizer .customize (attributeExchangeConfigurer );
166
+ this .attributeExchangeConfigurers .add (attributeExchangeConfigurer );
167
+ return this ;
168
+ }
169
+
151
170
/**
152
171
* Allows specifying the {@link OpenIDConsumer} to be used. The default is using an
153
172
* {@link OpenID4JavaConsumer}.
@@ -373,7 +392,7 @@ private void initDefaultLoginFilter(H http) {
373
392
* @author Rob Winch
374
393
*/
375
394
public final class AttributeExchangeConfigurer {
376
- private final String identifier ;
395
+ private String identifier ;
377
396
private List <OpenIDAttribute > attributes = new ArrayList <>();
378
397
private List <AttributeConfigurer > attributeConfigurers = new ArrayList <>();
379
398
@@ -395,6 +414,19 @@ public OpenIDLoginConfigurer<H> and() {
395
414
return OpenIDLoginConfigurer .this ;
396
415
}
397
416
417
+ /**
418
+ * Sets the regular expression for matching on OpenID's (i.e.
419
+ * "https://www.google.com/.*", ".*yahoo.com.*", etc)
420
+ *
421
+ * @param identifierPattern the regular expression for matching on OpenID's
422
+ * @return the {@link AttributeExchangeConfigurer} for further customization of
423
+ * attribute exchange
424
+ */
425
+ public AttributeExchangeConfigurer identifierPattern (String identifierPattern ) {
426
+ this .identifier = identifierPattern ;
427
+ return this ;
428
+ }
429
+
398
430
/**
399
431
* Adds an {@link OpenIDAttribute} to be obtained for the configured OpenID
400
432
* pattern.
@@ -419,6 +451,22 @@ public AttributeConfigurer attribute(String name) {
419
451
return attributeConfigurer ;
420
452
}
421
453
454
+ /**
455
+ * Adds an {@link OpenIDAttribute} named "default-attribute".
456
+ * The name can by updated using {@link AttributeConfigurer#name(String)}.
457
+ *
458
+ * @param attributeCustomizer the {@link Customizer} to provide more options for
459
+ * the {@link AttributeConfigurer}
460
+ * @return a {@link AttributeExchangeConfigurer} for further customizations
461
+ * @throws Exception
462
+ */
463
+ public AttributeExchangeConfigurer attribute (Customizer <AttributeConfigurer > attributeCustomizer ) throws Exception {
464
+ AttributeConfigurer attributeConfigurer = new AttributeConfigurer ();
465
+ attributeCustomizer .customize (attributeConfigurer );
466
+ this .attributeConfigurers .add (attributeConfigurer );
467
+ return this ;
468
+ }
469
+
422
470
/**
423
471
* Gets the {@link OpenIDAttribute}'s for the configured OpenID pattern
424
472
* @return
@@ -443,6 +491,16 @@ public final class AttributeConfigurer {
443
491
private boolean required = false ;
444
492
private String type ;
445
493
494
+ /**
495
+ * Creates a new instance named "default-attribute".
496
+ * The name can by updated using {@link #name(String)}.
497
+ *
498
+ * @see AttributeExchangeConfigurer#attribute(String)
499
+ */
500
+ private AttributeConfigurer () {
501
+ this .name = "default-attribute" ;
502
+ }
503
+
446
504
/**
447
505
* Creates a new instance
448
506
* @param name the name of the attribute
@@ -486,6 +544,16 @@ public AttributeConfigurer type(String type) {
486
544
return this ;
487
545
}
488
546
547
+ /**
548
+ * The OpenID attribute name.
549
+ * @param name
550
+ * @return the {@link AttributeConfigurer} for further customizations
551
+ */
552
+ public AttributeConfigurer name (String name ) {
553
+ this .name = name ;
554
+ return this ;
555
+ }
556
+
489
557
/**
490
558
* Gets the {@link AttributeExchangeConfigurer} for further customization of
491
559
* the attributes
0 commit comments