Skip to content

Commit

Permalink
[#28] SecurityConfig, TokenProvider 주석 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
chaiminwoo0223 committed Jun 12, 2024
1 parent 22d3611 commit 1cd037b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/main/java/skhu/jijijig/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors(Customizer.withDefaults()) // CORS를 기본 설정으로 활성화합니다.
.csrf(CsrfConfigurer::disable) // CSRF 보호를 비활성화합니다.
.cors(Customizer.withDefaults())
.csrf(CsrfConfigurer::disable)
.sessionManagement(sessionManagement ->
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // 세션을 사용하지 않습니다.
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers(PERMITTED_URLS).permitAll() // 특정 경로에 대한 접근을 모두 허용합니다.
.anyRequest().authenticated()) // 그 외 요청은 인증이 필요합니다.
.addFilterBefore(new JwtFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class); // JWT 필터를 추가합니다.
.requestMatchers(PERMITTED_URLS).permitAll()
.anyRequest().authenticated())
.addFilterBefore(new JwtFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class);
return http.build();
}

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/skhu/jijijig/token/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ public TokenProvider(@Value("${jwt.secret}") String secretKey,
this.tokenRevoker = tokenRevoker;
}

// 사용자 정보를 기반으로 토큰을 생성하고, TokenDTO를 반환합니다.
public TokenDTO createTokens(Member member) {
String accessToken = createToken(member.getId().toString(), member.getRole().name(), accessTokenValidityTime);
String refreshToken = createToken(member.getId().toString(), member.getRole().name(), refreshTokenValidityTime);
return TokenDTO.of(accessToken, refreshToken);
}

// refresh 토큰을 갱신합니다.
public TokenDTO renewToken(String refreshToken) {
if (!validateToken(refreshToken)) {
throw new SecurityException("리프레시 토큰이 유효하지 않습니다.");
Expand All @@ -56,7 +54,6 @@ public TokenDTO renewToken(String refreshToken) {
return TokenDTO.of(newAccessToken, newRefreshToken);
}

// HttpServletRequest에서 토큰을 해석합니다.
public String resolveToken(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
Expand All @@ -65,7 +62,6 @@ public String resolveToken(HttpServletRequest request) {
return null;
}

// 토큰의 유효성을 검증합니다.
public boolean validateToken(String token) {
try {
if (tokenRevoker.isBlackListed(token)) {
Expand All @@ -78,7 +74,6 @@ public boolean validateToken(String token) {
}
}

// 토큰에서 인증 정보를 추출하여, Authentication 객체를 생성합니다.
public Authentication getAuthentication(String accessToken) {
Claims claims = parseJwtToken(accessToken);
Collection<? extends GrantedAuthority> authorities = Arrays.stream(claims.get("auth").toString().split(","))
Expand All @@ -87,7 +82,6 @@ public Authentication getAuthentication(String accessToken) {
return new UsernamePasswordAuthenticationToken(claims.getSubject(), "", authorities);
}

// JWT 토큰을 생성합니다.
private String createToken(String subject, String authClaim, long validityTime) {
Date now = new Date();
Date expiration = new Date(now.getTime() + validityTime);
Expand All @@ -99,7 +93,6 @@ private String createToken(String subject, String authClaim, long validityTime)
.compact();
}

// JWT 토큰을 파싱하여, Claims 객체를 반환합니다.
private Claims parseJwtToken(String token) {
return Jwts.parserBuilder()
.setSigningKey(key)
Expand Down

0 comments on commit 1cd037b

Please sign in to comment.