15
15
*/
16
16
package sample ;
17
17
18
- import java .security .KeyFactory ;
19
18
import java .security .interfaces .RSAPublicKey ;
20
- import java .security .spec .X509EncodedKeySpec ;
21
- import java .util .Base64 ;
22
19
20
+ import org .springframework .beans .factory .annotation .Value ;
23
21
import org .springframework .context .annotation .Bean ;
24
22
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
25
23
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
33
31
@ EnableWebSecurity
34
32
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
35
33
34
+ @ Value ("${spring.security.oauth2.resourceserver.jwt.key-value}" )
35
+ RSAPublicKey key ;
36
+
36
37
@ Override
37
38
protected void configure (HttpSecurity http ) throws Exception {
38
39
// @formatter:off
@@ -49,16 +50,6 @@ protected void configure(HttpSecurity http) throws Exception {
49
50
50
51
@ Bean
51
52
JwtDecoder jwtDecoder () throws Exception {
52
- return NimbusJwtDecoder .withPublicKey (key ()).build ();
53
- }
54
-
55
- private RSAPublicKey key () throws Exception {
56
- String encoded = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd" +
57
- "UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs" +
58
- "HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D" +
59
- "o2kQ+X5xK9cipRgEKwIDAQAB" ;
60
- byte [] bytes = Base64 .getDecoder ().decode (encoded .getBytes ());
61
- return (RSAPublicKey ) KeyFactory .getInstance ("RSA" )
62
- .generatePublic (new X509EncodedKeySpec (bytes ));
53
+ return NimbusJwtDecoder .withPublicKey (this .key ).build ();
63
54
}
64
55
}
0 commit comments