Skip to content

Commit 64a1ad5

Browse files
committed
Merge branch '5.8.x' into 6.0.x
2 parents 44c4a4a + 5ffebaf commit 64a1ad5

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/SupplierJwtDecoder.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.function.Supplier;
2020

21+
import org.springframework.util.function.SingletonSupplier;
22+
2123
/**
2224
* A {@link JwtDecoder} that lazily initializes another {@link JwtDecoder}
2325
*
@@ -26,32 +28,25 @@
2628
*/
2729
public final class SupplierJwtDecoder implements JwtDecoder {
2830

29-
private final Supplier<JwtDecoder> jwtDecoderSupplier;
30-
31-
private volatile JwtDecoder delegate;
31+
private final Supplier<JwtDecoder> delegate;
3232

3333
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+
});
3542
}
3643

3744
/**
3845
* {@inheritDoc}
3946
*/
4047
@Override
4148
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);
5550
}
5651

5752
private JwtDecoderInitializationException wrapException(Exception ex) {

0 commit comments

Comments
 (0)