Skip to content

Commit abb50f5

Browse files
committed
fix: 코드 스멜 제거
- 중복 코드 수정
1 parent f548433 commit abb50f5

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

chat/src/main/java/org/example/soundlinkchat_java/global/auth/JwtProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class JwtProvider {
3131

3232
// 시크릿 키
3333
@Value("${jwt.secret}")
34-
private String SECRET_KEY_STRING;
34+
private String KEY;
3535

3636
// Access 토큰
3737
public String createAccessToken(long userId) {
3838
// 시크릿 키 (HMAC SHA256)
39-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
39+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
4040

4141
Claims claims = Jwts.claims().setSubject(String.valueOf(userId));
4242
Date now = new Date();
@@ -54,7 +54,7 @@ public String createRefreshToken(long userId) {
5454
Date now = new Date();
5555

5656
// 시크릿 키 (HMAC SHA256)
57-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
57+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
5858

5959
String refreshToken = Jwts.builder()
6060
.setClaims(claims)
@@ -75,7 +75,7 @@ public String createRefreshToken(long userId) {
7575
//토큰 검증(변조, 만료, 올바른 형식)
7676
public boolean validateToken(String token) {
7777
// 시크릿 키 (HMAC SHA256)
78-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
78+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
7979

8080
try {
8181
Jwts.parserBuilder()
@@ -120,7 +120,7 @@ public String resolveRefreshToken(HttpServletRequest request) {
120120
// 토큰에서 id 반환
121121
public Long getUserId(String token){
122122
// 시크릿 키 (HMAC SHA256)
123-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
123+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
124124

125125
return Long.parseLong(Jwts.parserBuilder()
126126
.setSigningKey(SECRET_KEY)

chat/src/main/java/org/example/soundlinkchat_java/global/config/RedisConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ public class RedisConfig {
2424
private String host;
2525

2626
@Value("${spring.data.redis.port}")
27-
private int port;
27+
private Integer port;
2828

2929
@Value("${spring.data.redis.password}")
30-
String password;
30+
private String password;
3131

3232
@Bean
3333
public RedisConnectionFactory redisConnectionFactory(){
3434
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
3535
config.setPassword(password);
36+
3637
return new LettuceConnectionFactory(config);
3738
}
3839

default/src/main/java/org/dfbf/soundlink/global/auth/JwtProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class JwtProvider {
3131

3232
// 시크릿 키
3333
@Value("${jwt.secret}")
34-
private String SECRET_KEY_STRING;
34+
private String KEY;
3535

3636
// Access 토큰
3737
public String createAccessToken(long userId) {
3838
// 시크릿 키 (HMAC SHA256)
39-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
39+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
4040

4141
Claims claims = Jwts.claims().setSubject(String.valueOf(userId));
4242
Date now = new Date();
@@ -54,7 +54,7 @@ public String createRefreshToken(long userId) {
5454
Date now = new Date();
5555

5656
// 시크릿 키 (HMAC SHA256)
57-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
57+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
5858

5959
String refreshToken = Jwts.builder()
6060
.setClaims(claims)
@@ -75,7 +75,7 @@ public String createRefreshToken(long userId) {
7575
//토큰 검증(변조, 만료, 올바른 형식)
7676
public boolean validateToken(String token) {
7777
// 시크릿 키 (HMAC SHA256)
78-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
78+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
7979

8080
try {
8181
Jwts.parserBuilder()
@@ -120,7 +120,7 @@ public String resolveRefreshToken(HttpServletRequest request) {
120120
// 토큰에서 id 반환
121121
public Long getUserId(String token){
122122
// 시크릿 키 (HMAC SHA256)
123-
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(SECRET_KEY_STRING.getBytes());
123+
SecretKey SECRET_KEY = Keys.hmacShaKeyFor(KEY.getBytes());
124124

125125
return Long.parseLong(Jwts.parserBuilder()
126126
.setSigningKey(SECRET_KEY)

default/src/main/java/org/dfbf/soundlink/global/config/RedisConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ public class RedisConfig {
2424
private String host;
2525

2626
@Value("${spring.data.redis.port}")
27-
private int port;
27+
private Integer port;
2828

2929
@Value("${spring.data.redis.password}")
30-
String password;
30+
private String password;
3131

3232
@Bean
3333
public RedisConnectionFactory redisConnectionFactory(){
3434
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
3535
config.setPassword(password);
36+
3637
return new LettuceConnectionFactory(config);
3738
}
3839

0 commit comments

Comments
 (0)