File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed
oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change 18
18
19
19
import java .util .function .Supplier ;
20
20
21
+ import org .springframework .util .function .SingletonSupplier ;
22
+
21
23
/**
22
24
* A {@link JwtDecoder} that lazily initializes another {@link JwtDecoder}
23
25
*
26
28
*/
27
29
public final class SupplierJwtDecoder implements JwtDecoder {
28
30
29
- private final Supplier <JwtDecoder > jwtDecoderSupplier ;
30
-
31
- private volatile JwtDecoder delegate ;
31
+ private final Supplier <JwtDecoder > delegate ;
32
32
33
33
public SupplierJwtDecoder (Supplier <JwtDecoder > jwtDecoderSupplier ) {
34
- this .jwtDecoderSupplier = jwtDecoderSupplier ;
34
+ this .delegate = SingletonSupplier .of (() -> {
35
+ try {
36
+ return jwtDecoderSupplier .get ();
37
+ }
38
+ catch (Exception ex ) {
39
+ throw wrapException (ex );
40
+ }
41
+ });
35
42
}
36
43
37
44
/**
38
45
* {@inheritDoc}
39
46
*/
40
47
@ Override
41
48
public Jwt decode (String token ) throws JwtException {
42
- if (this .delegate == null ) {
43
- synchronized (this .jwtDecoderSupplier ) {
44
- if (this .delegate == null ) {
45
- try {
46
- this .delegate = this .jwtDecoderSupplier .get ();
47
- }
48
- catch (Exception ex ) {
49
- throw wrapException (ex );
50
- }
51
- }
52
- }
53
- }
54
- return this .delegate .decode (token );
49
+ return this .delegate .get ().decode (token );
55
50
}
56
51
57
52
private JwtDecoderInitializationException wrapException (Exception ex ) {
You can’t perform that action at this time.
0 commit comments