|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 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.
|
|
36 | 36 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
37 | 37 | import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
|
38 | 38 | import org.springframework.context.annotation.Bean;
|
| 39 | +import org.springframework.context.annotation.Configuration; |
39 | 40 | import org.springframework.context.annotation.Role;
|
40 | 41 | import org.springframework.security.oauth2.jwt.JwtDecoder;
|
41 | 42 | import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
|
49 | 50 | * @since 3.1.0
|
50 | 51 | */
|
51 | 52 | @AutoConfiguration(after = UserDetailsServiceAutoConfiguration.class)
|
52 |
| -@ConditionalOnClass(OAuth2Authorization.class) |
| 53 | +@ConditionalOnClass({ OAuth2Authorization.class, JWKSource.class }) |
53 | 54 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
54 | 55 | public class OAuth2AuthorizationServerJwtAutoConfiguration {
|
55 | 56 |
|
56 |
| - @Bean |
57 |
| - @ConditionalOnClass(JwtDecoder.class) |
58 |
| - @ConditionalOnMissingBean |
59 |
| - JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) { |
60 |
| - return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource); |
61 |
| - } |
62 |
| - |
63 | 57 | @Bean
|
64 | 58 | @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
65 | 59 | @ConditionalOnMissingBean
|
@@ -92,4 +86,16 @@ private static KeyPair generateRsaKey() {
|
92 | 86 | return keyPair;
|
93 | 87 | }
|
94 | 88 |
|
| 89 | + @Configuration(proxyBeanMethods = false) |
| 90 | + @ConditionalOnClass(JwtDecoder.class) |
| 91 | + static class JwtDecoderConfiguration { |
| 92 | + |
| 93 | + @Bean |
| 94 | + @ConditionalOnMissingBean |
| 95 | + JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) { |
| 96 | + return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource); |
| 97 | + } |
| 98 | + |
| 99 | + } |
| 100 | + |
95 | 101 | }
|
0 commit comments