Skip to content

Commit 0c94b3b

Browse files
committed
asymmetric keys to do the signing process
1 parent a5a8792 commit 0c94b3b

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

src/main/java/com/rest/oauth2/config/Oauth2AuthorizationConfig.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.beans.factory.annotation.Value;
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.core.io.ClassPathResource;
9+
import org.springframework.core.io.FileSystemResource;
1010
import org.springframework.security.crypto.password.PasswordEncoder;
1111
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
1212
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
@@ -33,8 +33,8 @@ public class Oauth2AuthorizationConfig extends AuthorizationServerConfigurerAdap
3333
private final DataSource dataSource;
3434
private final CustomUserDetailService userDetailService;
3535

36-
// @Value("${security.oauth2.jwt.signkey}")
37-
// private String signKey;
36+
@Value("${security.oauth2.jwt.signkey}")
37+
private String signKey;
3838

3939
@Override
4040
public void configure(AuthorizationServerSecurityConfigurer security) {
@@ -69,7 +69,7 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E
6969
}
7070

7171
/**
72-
* jwt converter를 등록
72+
* jwt converter - signKey 공유 방식
7373
*/
7474
// @Bean
7575
// public JwtAccessTokenConverter jwtAccessTokenConverter() {
@@ -78,11 +78,14 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E
7878
// return converter;
7979
// }
8080

81+
/**
82+
* jwt converter - 비대칭 키 sign
83+
*/
8184
@Bean
8285
public JwtAccessTokenConverter jwtAccessTokenConverter() {
83-
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "mySecretKey".toCharArray());
86+
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new FileSystemResource("src/main/resources/oauth2jwt.jks"), "oauth2jwtpass".toCharArray());
8487
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
85-
converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
88+
converter.setKeyPair(keyStoreKeyFactory.getKeyPair("oauth2jwt"));
8689
return converter;
8790
}
8891
}

src/main/resources/application.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,4 @@ spring:
1919
security:
2020
oauth2:
2121
jwt:
22-
signkey: 123@#$
23-
# authorization:
24-
# jwt:
25-
# key-alias: oauth2jwt
26-
# key-store: classpath:/oauth2jwt.jks
27-
# key-password: oauth2jwtpass
28-
# key-store-password: oauth2jwtpass
22+
signkey: 123@#$

src/main/resources/jwt.jks

-2.1 KB
Binary file not shown.

src/main/resources/oauth2jwt.jks

2.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)