Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
refactor: 스프링 시큐리티 코드 리팩터링#154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
210ae52ee49cfe7227179e8632fcfeb828fb795eb854141e1e89dc76ff902d2d0e092953299c9c33466baaca84f1d37ff4b607988995ab18505b746a4b0db42019370d9c965b605f24aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.example.solidconnection.auth.service; | ||
| import com.example.solidconnection.auth.domain.TokenType; | ||
| import com.example.solidconnection.config.security.JwtProperties; | ||
| import io.jsonwebtoken.Claims; | ||
| import io.jsonwebtoken.Jwts; | ||
| import io.jsonwebtoken.SignatureAlgorithm; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Component; | ||
| import java.util.Date; | ||
| import java.util.concurrent.TimeUnit; | ||
| import static com.example.solidconnection.util.JwtUtils.parseSubject; | ||
| import static com.example.solidconnection.util.JwtUtils.parseSubjectOrElseThrow; | ||
| @RequiredArgsConstructor | ||
| @Component | ||
| public class TokenProvider { | ||
| private final RedisTemplate<String, String> redisTemplate; | ||
| private final JwtProperties jwtProperties; | ||
| public String generateToken(String email, TokenType tokenType) { | ||
| Claims claims = Jwts.claims().setSubject(email); | ||
| Date now = new Date(); | ||
| Date expiredDate = new Date(now.getTime() + tokenType.getExpireTime()); | ||
| return Jwts.builder() | ||
| .setClaims(claims) | ||
| .setIssuedAt(now) | ||
| .setExpiration(expiredDate) | ||
| .signWith(SignatureAlgorithm.HS512, jwtProperties.secret()) | ||
| .compact(); | ||
| } | ||
| public String saveToken(String token, TokenType tokenType) { | ||
| String subject = parseSubjectOrElseThrow(token, jwtProperties.secret()); | ||
| redisTemplate.opsForValue().set( | ||
| tokenType.addPrefixToSubject(subject), | ||
| token, | ||
| tokenType.getExpireTime(), | ||
| TimeUnit.MILLISECONDS | ||
| ); | ||
| return token; | ||
| } | ||
| public String getEmail(String token) { | ||
| return parseSubject(token, jwtProperties.secret()); | ||
| } | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.example.solidconnection.config.security; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import java.util.List; | ||
| @ConfigurationProperties(prefix = "cors") | ||
| public record CorsProperties(List<String> allowedOrigins) { | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenProvider는 Auth의 책임이니 적절하게 이동한 거 같습니다! 다만 앞으로 애플 등의 인증 방식이 추가될 수 있으므로, 확장성을 위해 인터페이스 도입을 고려하면 좋을 것 같습니다. 현재는 구조를 유지하면서, 새로운 인증 방식 추가 시점에 인터페이스화를 논의해도 좋을 거 같습니다!