Skip to content
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d0cc181
feat: 인증 필터 구현 (#7)
sangyunpark99 Apr 10, 2025
aec8db8
feat: ErrorCode 구현 (#7)
sangyunpark99 Apr 10, 2025
19f5115
chore: application.properties 파일 삭제 (#7)
sangyunpark99 Apr 11, 2025
4e8351a
test: 인증 필터 테스트 구현 (#7)
sangyunpark99 Apr 11, 2025
d3907d3
fix: build가 안되는 오류 해결 (#7)
sangyunpark99 Apr 11, 2025
64dbab8
feat: 토큰 유효성 검증시 사용되는 TokenValidator 클래스 구현 (#7)
sangyunpark99 Apr 11, 2025
af6101c
test: TokenValidator 테스트 구현 (#7)
sangyunpark99 Apr 11, 2025
5f3fd83
feat: 토큰 검증을 무시하는 URL을 나타내기 위한 WhiteListVo 구현 (#7)
sangyunpark99 Apr 11, 2025
0cae902
feat: 토큰 블랙리스트 검증과 토큰 유효성 검증에 필요한 AuthenticationService 구현 (#7)
sangyunpark99 Apr 11, 2025
31cd48e
refactor: 토큰 검증 로직을 AuthenticationService로 위임 (#7)
sangyunpark99 Apr 11, 2025
3a70c8d
test: TokenValidator 사용을 AuthenticationService로 변경 (#7)
sangyunpark99 Apr 11, 2025
8acac61
feat: Reactive Redis 기반의 토큰 블랙리스트 저장소 추가 (#7)
sangyunpark99 Apr 11, 2025
2fd438e
chore: TokenValidator 패키지 위치 변경 (#7)
sangyunpark99 Apr 11, 2025
1d1190a
fix: develop 브랜치 병합시 발생하는 충돌 해결 (#7)
sangyunpark99 Apr 14, 2025
40da730
chore: user 모듈 application.yml 파일 추가 (#7)
sangyunpark99 Apr 14, 2025
cea27d2
feat: gateway 모듈 초기 세팅 (#7)
sangyunpark99 Apr 14, 2025
58185f4
refactor: 인증 책임을 gateway로 이전하여 Auth 서버의 Spring Security 제거 (#7)
sangyunpark99 Apr 14, 2025
d773a1e
chore: auth 서버 application.yml파일 추가 (#7)
sangyunpark99 Apr 14, 2025
7eeabfd
chore: gateway 서버 application.yml파일 추가 (#7)
sangyunpark99 Apr 14, 2025
072c508
refactor: 인증 로직 리펙토링 및 TokenValidator 제거 (#7)
sangyunpark99 Apr 14, 2025
cffa04c
feat: 공통 에러 응답 유틸 클래스 구현 (#7)
sangyunpark99 Apr 14, 2025
cdd4056
test: 공통 에러 응답 유틸 클래스 테스트 구현 (#7)
sangyunpark99 Apr 14, 2025
7396c86
feat: 요청에 사용자 정보를 포함하는 RequestMutationUtils 클래스 구현 (#7)
sangyunpark99 Apr 14, 2025
dba84e1
test: 요청에 사용자 정보를 포함하는 RequestMutationUtils 클래스 테스트 구현 (#7)
sangyunpark99 Apr 14, 2025
7976a59
refactor: auth 모듈 사용하지 않는 메서드 getUserStatus 제거 (#7)
sangyunpark99 Apr 14, 2025
5dcb136
feat: gateway 모듈 토큰 파싱 작업 하는 TokenProvider클래스 구현 (#7)
sangyunpark99 Apr 14, 2025
b230d5f
feat: URL 경로 기반 검사 로직을 UrlMatcher로 분리 (#7)
sangyunpark99 Apr 14, 2025
f03fdd8
test: UrlMatcher클래스 테스트 코드 구현 (#7)
sangyunpark99 Apr 14, 2025
9f1babb
feat: User 유형을 나타내는 UserType enum 구현 (#7)
sangyunpark99 Apr 14, 2025
2080f04
feat: 화이트리스트 경로 매칭을 위한 WhitelistMatcher 클래스 추가 (#7)
sangyunpark99 Apr 14, 2025
1096abe
test: WhitelistMatcher 테스트 코드 추가 (#7)
sangyunpark99 Apr 14, 2025
76c17f5
feat: 인증 필터 리펙토링 및 관리자 인가, 로그아웃 처리 로직 추가 (#7)
sangyunpark99 Apr 14, 2025
a95797d
feat: AuthenticationFilterTest에서 인가 테스트 코드 추가 (#7)
sangyunpark99 Apr 14, 2025
04c1652
refactor: 로그아웃 토큰 Redis 키에 blacklist_token prefix 적용 (#7)
sangyunpark99 Apr 15, 2025
58a4dea
refactor: 인증 로직 개선 및 CachedUser 기반 인증 처리로 변경 (#7)
sangyunpark99 Apr 15, 2025
271e78f
test: AuthenticationFilter 테스트를 CachedUser 기반으로 리팩토링 (#7)
sangyunpark99 Apr 15, 2025
7f84e7e
refactor: 인증 서비스 캐싱 및 블랙리스트 로직 수정 (#7)
sangyunpark99 Apr 15, 2025
a9b6096
test: AuthenticationService 단위 테스트 작성 (#7)
sangyunpark99 Apr 15, 2025
92f3d8d
chore: redis 테스트 환경에 필요한 의존성 추가 (#7)
sangyunpark99 Apr 15, 2025
7664c40
feat: 인증 사용자 정보를 담는 CachedUser 레코드 추가 (#7)
sangyunpark99 Apr 15, 2025
4ab3227
refactor: 블랙리스트 토큰 Redis 키 구조 개선 및 네임스페이스 prefix 적용 (#7)
sangyunpark99 Apr 15, 2025
bd8cb53
feat: gateway에 Redis 기반 토큰 캐시 및 블랙리스트 저장소 구현 (#7)
sangyunpark99 Apr 15, 2025
a93a741
feat: RedisTokenRepository 테스트 코드 구현 (#7)
sangyunpark99 Apr 15, 2025
faf7070
refactor: CachedUser로 헤더에 첨부할 값 가져오기 (#7)
sangyunpark99 Apr 15, 2025
4413f4f
test: CachedUser사용으로 인한 테스트 코드 수정 (#7)
sangyunpark99 Apr 15, 2025
7acc55f
refactor: 사용하지 않는 TokenBlackListRepository 제거 (#7)
sangyunpark99 Apr 15, 2025
8a7c7e7
refactor: static 제거 (#7)
sangyunpark99 Apr 19, 2025
5364022
test: static 메서드 제거 (#7)
sangyunpark99 Apr 19, 2025
8cbe740
feat: 로그아웃시 redis에 저장된 리프레시 토큰 삭제 (#7)
sangyunpark99 Apr 19, 2025
3276a0c
test: 아스키코드 허용 어노테이션 추가 (#7)
sangyunpark99 Apr 19, 2025
8622f00
chore: apache StringUtil 의존성 추가 (#7)
sangyunpark99 Apr 19, 2025
a1740e6
refactor: 메서드 static 제거 (#7)
sangyunpark99 Apr 19, 2025
cdd3808
test: static 제거 (#7)
sangyunpark99 Apr 19, 2025
cebb3b5
refactor: 필드 변수 static 제거 (#7)
sangyunpark99 Apr 19, 2025
49bc813
refactor: 필드 변수 static 제거 (#7)
sangyunpark99 Apr 19, 2025
8a8fad5
feat: refresh 토큰 제거 로직 추가 (#7)
sangyunpark99 Apr 19, 2025
05eca3e
test: 블랙리스트 확인시 사용하는 prefix추가 (#7)
sangyunpark99 Apr 19, 2025
c0a00da
test: 아스키 코드 허용 어노테이션 추가 (#7)
sangyunpark99 Apr 19, 2025
fae6fc8
test: 인증 및 리프레시 토큰 삭제 테스트 코드 구현 (#7)
sangyunpark99 Apr 19, 2025
8905464
refactor: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
6fb625e
test: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
f33f8ae
feat: null 반환 → 빈 문자열 반환 (#7)
sangyunpark99 Apr 19, 2025
a61a22a
refactor: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
f77913c
test: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
78516b7
feat: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
63886ae
test: static 키워드 제거 (#7)
sangyunpark99 Apr 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand All @@ -36,7 +34,6 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.sangyunpark.auth.exception.BusinessException;
import com.sangyunpark.auth.infrastructure.repository.RedisTokenRepository;
import com.sangyunpark.auth.jwt.TokenProvider;
import com.sangyunpark.auth.jwt.UserPrincipal;
import com.sangyunpark.auth.presentation.dto.request.LoginRequestDto;
import com.sangyunpark.auth.presentation.dto.response.TokenResponseDto;
import lombok.RequiredArgsConstructor;
Expand All @@ -33,11 +32,10 @@ public TokenResponseDto login(final LoginRequestDto loginRequestDto) {
return new TokenResponseDto(token);
}

public TokenResponseDto reissue(final String refreshToken, final UserPrincipal userPrincipal) {
final String email = userPrincipal.getEmail();
public TokenResponseDto reissue(final String refreshToken, final String email, final String userType, final String userStatus) {
tokenProvider.validateToken(refreshToken);
validateStoredRefreshToken(email, refreshToken);
Token newToken = generateAndStoreToken(email, userPrincipal.getUserType(), userPrincipal.getUserStatus());
Token newToken = generateAndStoreToken(email, UserType.valueOf(userType), UserStatus.valueOf(userStatus));
return new TokenResponseDto(newToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    return new TokenResponseDto(this.generateAndStoreToken(email, UserType.valueOf(userType), UserStatus.valueOf(userStatus)));

}

Expand Down
32 changes: 0 additions & 32 deletions auth/src/main/java/com/sangyunpark/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
package com.sangyunpark.auth.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sangyunpark.auth.global.filter.JwtAuthenticationFilter;
import com.sangyunpark.auth.global.security.JwtAccessDeniedHandler;
import com.sangyunpark.auth.jwt.TokenProvider;
import com.sangyunpark.auth.jwt.TokenValidator;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@RequiredArgsConstructor
public class SecurityConfig {

private final TokenProvider tokenProvider;
private final TokenValidator tokenValidator;
private final ObjectMapper objectMapper;
private final JwtAccessDeniedHandler accessDeniedHandler;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/v1/auth/login", "/api/v1/auth/reissue").permitAll()
.requestMatchers("/api/v1/admin/**").hasAuthority("ADMIN")
.anyRequest().authenticated()
)
.exceptionHandling(handler ->
handler.accessDeniedHandler(accessDeniedHandler))
.addFilterBefore(new JwtAuthenticationFilter(tokenProvider, tokenValidator, objectMapper), UsernamePasswordAuthenticationFilter.class)
.build();
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.sangyunpark.auth.exception.BusinessException;
import com.sangyunpark.auth.presentation.dto.response.ErrorResponse;
import feign.FeignException;
import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@Repository
public class RedisTokenRepository {

private static final String BLACK_LIST_KEY = "black_list:";

private final StringRedisTemplate redisTemplate;
private final long refreshTokenExpireTime;

Expand All @@ -35,10 +37,10 @@ public boolean exists(final String email) {
}

public void saveLogOutToken(final String accessToken, final long remainingTime) {
redisTemplate.opsForValue().set(accessToken, "logout", remainingTime, TimeUnit.MILLISECONDS);
redisTemplate.opsForValue().set(BLACK_LIST_KEY + accessToken,"", remainingTime, TimeUnit.MILLISECONDS);
}

public boolean isLogOutToken(final String accessToken) {
return Boolean.TRUE.equals(redisTemplate.hasKey(accessToken));
return Boolean.TRUE.equals(redisTemplate.hasKey(BLACK_LIST_KEY + accessToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public String getUserType(final String token) {
return parseClaims(token).get(USER_TYPE, String.class);
}

public String getUserStatus(final String token) {
return parseClaims(token).get(USER_STATUS, String.class);
}

public long getRemainingExpiration(final String accessToken) {
Date expiration = parseClaims(accessToken).getExpiration();
return expiration.getTime() - System.currentTimeMillis();
Expand Down
17 changes: 0 additions & 17 deletions auth/src/main/java/com/sangyunpark/auth/jwt/TokenValidator.java

This file was deleted.

48 changes: 0 additions & 48 deletions auth/src/main/java/com/sangyunpark/auth/jwt/UserPrincipal.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.sangyunpark.auth.presentation;

import com.sangyunpark.auth.application.AuthService;
import com.sangyunpark.auth.jwt.UserPrincipal;
import com.sangyunpark.auth.presentation.dto.request.LoginRequestDto;
import com.sangyunpark.auth.presentation.dto.response.TokenResponseDto;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -15,6 +13,9 @@
public class AuthController {

private static final String HEADER_REFRESH_TOKEN = "X-Refresh-Token";
private static final String HEADER_USER_EMAIL = "X-User-Email";
private static final String HEADER_USER_TYPE = "X-User-Type";
private static final String HEADER_USER_STATUS = "X-User-Status";
private static final String HEADER_AUTHORIZATION = "Authorization";

private final AuthService authService;
Expand All @@ -25,8 +26,13 @@ public TokenResponseDto login(@Valid @RequestBody LoginRequestDto loginRequestDt
}

@PostMapping("/reissue")
public TokenResponseDto reissue(@RequestHeader(HEADER_REFRESH_TOKEN) final String refreshToken, @AuthenticationPrincipal UserPrincipal userPrincipal) {
return authService.reissue(refreshToken, userPrincipal);
public TokenResponseDto reissue(
@RequestHeader(HEADER_REFRESH_TOKEN) final String refreshToken,
@RequestHeader(HEADER_USER_EMAIL) final String email,
@RequestHeader(HEADER_USER_TYPE) final String userType,
@RequestHeader(HEADER_USER_STATUS) final String userStatus
) {
return authService.reissue(refreshToken, email, userType, userStatus);
}

@PostMapping("/logout")
Expand Down
5 changes: 5 additions & 0 deletions auth/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ spring:
username: root
password:

data:
redis:
host: localhost
port: 6379

jpa:
hibernate:
ddl-auto: update
Expand Down
Loading
Loading