|
28 | 28 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
29 | 29 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
30 | 30 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
| 31 | +import org.springframework.context.annotation.Bean; |
31 | 32 | import org.springframework.context.annotation.Configuration;
|
32 | 33 | import org.springframework.context.annotation.Import;
|
33 | 34 | import org.springframework.core.io.ClassPathResource;
|
| 35 | +import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; |
34 | 36 | import org.springframework.security.oauth2.provider.token.TokenStore;
|
35 | 37 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
36 | 38 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
|
@@ -120,11 +122,54 @@ public void configureWhenKeyStoreIsProvidedButNoPasswordThenThrowsException() {
|
120 | 122 | .run(context -> assertThat(context).getFailure().isInstanceOf(UnsatisfiedDependencyException.class));
|
121 | 123 | }
|
122 | 124 |
|
| 125 | + @Test |
| 126 | + public void configureWhenPrivateKeyIsProvidedWithCustomJwtAccessTokenConverterThenDefaultBackoff() |
| 127 | + throws Exception { |
| 128 | + Path privateKeyPath = new ClassPathResource("key.private", this.getClass()).getFile().toPath(); |
| 129 | + String privateKey = Files.readAllLines(privateKeyPath).stream().collect(Collectors.joining("\n")); |
| 130 | + |
| 131 | + this.contextRunner.withUserConfiguration(JwtAccessTokenConverterConfiguration.class) |
| 132 | + .withPropertyValues("security.oauth2.authorization.jwt.key-value=" + privateKey).run(context -> { |
| 133 | + JwtAccessTokenConverter converter = context.getBean(JwtAccessTokenConverter.class); |
| 134 | + assertThat(converter.getAccessTokenConverter()).isInstanceOf(CustomAccessTokenConverter.class); |
| 135 | + }); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void configureWhenKeyStoreIsProvidedWithKeyPasswordAndCustomJwtAccessTokenConverterThenDefaultBackoff() { |
| 140 | + this.contextRunner.withUserConfiguration(JwtAccessTokenConverterConfiguration.class) |
| 141 | + .withPropertyValues("security.oauth2.authorization.jwt.key-store=classpath:" |
| 142 | + + "org/springframework/boot/autoconfigure/security/oauth2/authserver/keyhaspassword.jks", |
| 143 | + "security.oauth2.authorization.jwt.key-store-password=changeme", |
| 144 | + "security.oauth2.authorization.jwt.key-alias=jwt", |
| 145 | + "security.oauth2.authorization.jwt.key-password=password") |
| 146 | + .run(context -> { |
| 147 | + JwtAccessTokenConverter converter = context.getBean(JwtAccessTokenConverter.class); |
| 148 | + assertThat(converter.getAccessTokenConverter()).isInstanceOf(CustomAccessTokenConverter.class); |
| 149 | + }); |
| 150 | + } |
| 151 | + |
123 | 152 | @Configuration
|
124 | 153 | @Import({ AuthorizationServerTokenServicesConfiguration.class })
|
125 | 154 | @EnableConfigurationProperties(AuthorizationServerProperties.class)
|
126 | 155 | protected static class AuthorizationServerConfiguration {
|
127 | 156 |
|
128 | 157 | }
|
129 | 158 |
|
| 159 | + @Configuration |
| 160 | + protected static class JwtAccessTokenConverterConfiguration { |
| 161 | + |
| 162 | + @Bean |
| 163 | + JwtAccessTokenConverter accessTokenConverter() { |
| 164 | + JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); |
| 165 | + converter.setAccessTokenConverter(new CustomAccessTokenConverter()); |
| 166 | + return converter; |
| 167 | + } |
| 168 | + |
| 169 | + } |
| 170 | + |
| 171 | + protected static class CustomAccessTokenConverter extends DefaultAccessTokenConverter { |
| 172 | + |
| 173 | + } |
| 174 | + |
130 | 175 | }
|
0 commit comments