Skip to content

Commit a24737d

Browse files
authored
[Refactor] 운영 준비성 개선: 인증 흐름 정리 및 테스트 코드 격리 (#233)
* refactor: JWT 인증 흐름에 맞게 보안 설정 정리 * refactor: 테스트 전용 코드 실행 프로필 제한 * refactor: 레거시 선착순 처리 경로 제거
1 parent b895e44 commit a24737d

10 files changed

Lines changed: 40 additions & 175 deletions

File tree

src/main/java/com/threestar/trainus/domain/lesson/issue/LegacyLessonAdmissionScheduler.java

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/main/java/com/threestar/trainus/domain/lesson/issue/LegacyLessonApplyConsumer.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/main/java/com/threestar/trainus/domain/lesson/issue/LessonAdmissionScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import lombok.RequiredArgsConstructor;
1818
import lombok.extern.slf4j.Slf4j;
1919

20-
@Profile("consumer & !legacy")
20+
@Profile("consumer")
2121
@Slf4j
2222
@Component
2323
@RequiredArgsConstructor

src/main/java/com/threestar/trainus/domain/lesson/issue/LessonApplyConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.concurrent.ConcurrentLinkedQueue;
1919
import java.util.stream.Collectors;
2020

21-
@Profile("consumer & !legacy")
21+
@Profile("consumer")
2222
@Slf4j
2323
@Component
2424
@RequiredArgsConstructor

src/main/java/com/threestar/trainus/domain/lesson/student/controller/StudentLessonController.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
import com.threestar.trainus.domain.lesson.teacher.entity.Category;
2525
import com.threestar.trainus.global.annotation.LoginUser;
2626
import com.threestar.trainus.global.dto.PageRequestDto;
27-
import com.threestar.trainus.global.exception.domain.ErrorCode;
28-
import com.threestar.trainus.global.exception.handler.BusinessException;
2927
import com.threestar.trainus.global.unit.BaseResponse;
3028
import com.threestar.trainus.global.unit.PagedResponse;
3129

3230
import io.swagger.v3.oas.annotations.Operation;
3331
import io.swagger.v3.oas.annotations.tags.Tag;
34-
import jakarta.servlet.http.HttpSession;
3532
import jakarta.validation.Valid;
3633
import jakarta.validation.constraints.Max;
3734
import jakarta.validation.constraints.Min;
@@ -137,13 +134,8 @@ public ResponseEntity<PagedResponse<MyLessonApplicationListWrapperDto>> getMyLes
137134
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
138135
@Max(value = 100, message = "limit는 100 이하여야 합니다.") int limit,
139136
@RequestParam(defaultValue = "ALL") String status,
140-
HttpSession session
137+
@LoginUser Long userId
141138
) {
142-
Long userId = (Long)session.getAttribute("LOGIN_USER");
143-
if (userId == null) {
144-
throw new BusinessException(ErrorCode.AUTHENTICATION_REQUIRED);
145-
}
146-
147139
MyLessonApplicationListResponseDto serviceResponse = studentLessonService.getMyLessonApplications(userId, page,
148140
limit, status);
149141
MyLessonApplicationListWrapperDto response = new MyLessonApplicationListWrapperDto(

src/main/java/com/threestar/trainus/domain/test/controller/TestConcurrencyController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.http.HttpStatus;
55
import org.springframework.http.MediaType;
66
import org.springframework.http.ResponseEntity;
7+
import org.springframework.context.annotation.Profile;
78
import org.springframework.web.bind.annotation.PathVariable;
89
import org.springframework.web.bind.annotation.PostMapping;
910
import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,6 +28,7 @@
2728
import lombok.RequiredArgsConstructor;
2829

2930
@Tag(name = "동시성 테스트 API", description = "선착순 기능 테스트를 위한 API")
31+
@Profile({"local", "test"})
3032
@RestController
3133
@RequestMapping("/test")
3234
@RequiredArgsConstructor

src/main/java/com/threestar/trainus/global/config/MockDataInitializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Set;
99

1010
import org.springframework.boot.CommandLineRunner;
11+
import org.springframework.context.annotation.Profile;
1112
import org.springframework.security.crypto.password.PasswordEncoder;
1213
import org.springframework.stereotype.Component;
1314
import org.springframework.transaction.annotation.Transactional;
@@ -26,7 +27,6 @@
2627
import com.threestar.trainus.domain.metadata.entity.ProfileMetadata;
2728
import com.threestar.trainus.domain.metadata.mapper.ProfileMetadataMapper;
2829
import com.threestar.trainus.domain.metadata.repository.ProfileMetadataRepository;
29-
import com.threestar.trainus.domain.profile.entity.Profile;
3030
import com.threestar.trainus.domain.profile.mapper.ProfileMapper;
3131
import com.threestar.trainus.domain.profile.repository.ProfileRepository;
3232
import com.threestar.trainus.domain.review.entity.Review;
@@ -40,7 +40,7 @@
4040

4141
@Slf4j
4242
@Component
43-
@org.springframework.context.annotation.Profile("dev") // dev 프로필에서만 실행
43+
@Profile({"local", "test"})
4444
@RequiredArgsConstructor
4545
public class MockDataInitializer implements CommandLineRunner {
4646

@@ -111,7 +111,7 @@ private List<User> createInstructors() {
111111
User savedInstructor = userRepository.save(instructor);
112112

113113
// Profile 생성
114-
Profile profile = ProfileMapper.toDefaultEntity(savedInstructor);
114+
var profile = ProfileMapper.toDefaultEntity(savedInstructor);
115115
profile.updateProfileImage("https://example.com/instructor" + (i + 1) + ".jpg");
116116
profile.updateProfileIntro(instructorNames[i] + "입니다. 최고의 레슨을 제공합니다!");
117117
profileRepository.save(profile);
@@ -138,7 +138,7 @@ private List<User> createInstructors() {
138138
User savedAdmin = userRepository.save(admin);
139139

140140
// 관리자 Profile 생성
141-
Profile adminProfile = ProfileMapper.toDefaultEntity(savedAdmin);
141+
var adminProfile = ProfileMapper.toDefaultEntity(savedAdmin);
142142
adminProfile.updateProfileImage("https://example.com/admin.jpg");
143143
profileRepository.save(adminProfile);
144144

@@ -165,7 +165,7 @@ private List<User> createStudents() {
165165
User savedStudent = userRepository.save(student);
166166

167167
// Profile 생성
168-
Profile profile = ProfileMapper.toDefaultEntity(savedStudent);
168+
var profile = ProfileMapper.toDefaultEntity(savedStudent);
169169
profile.updateProfileImage("https://example.com/student" + (i + 1) + ".jpg");
170170
profileRepository.save(profile);
171171

src/main/java/com/threestar/trainus/global/config/SwaggerConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ public class SwaggerConfig {
1414
@Bean
1515
public OpenAPI openApi() {
1616
return new OpenAPI()
17-
.addSecurityItem(new SecurityRequirement().addList("session"))
17+
.addSecurityItem(new SecurityRequirement().addList("bearerAuth"))
1818
.components(new Components()
19-
.addSecuritySchemes("session", new SecurityScheme()
20-
.type(SecurityScheme.Type.APIKEY)
21-
.in(SecurityScheme.In.COOKIE)
22-
.name("JSESSIONID")
19+
.addSecuritySchemes("bearerAuth", new SecurityScheme()
20+
.type(SecurityScheme.Type.HTTP)
21+
.scheme("bearer")
22+
.bearerFormat("JWT")
2323
)
2424
)
2525
.info(apiInfo());
2626
}
2727

2828
private Info apiInfo() {
2929
return new Info()
30-
.title("FitMate API 문서") // API의 제목
30+
.title("TrainUs API 문서") // API의 제목
3131
.description("운동 메이트 매칭 플랫폼의 API 명세서") // API에 대한 설명
3232
.version("1.0.0"); // API의 버전
3333
}

src/main/java/com/threestar/trainus/global/config/security/SecurityConfig.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.springframework.context.annotation.Bean;
66
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.http.HttpMethod;
78
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
89
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
910
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -29,10 +30,26 @@ public PasswordEncoder passwordEncoder() {
2930
@Bean
3031
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3132
http.authorizeHttpRequests(
32-
auth -> auth.requestMatchers("/api/v1/users/**", "/api/lessons/test-auth", "/swagger-ui/**",
33-
"/v3/api-docs/**", "/api/v1/profiles/**", "/api/v1/lessons/**", "api/v1/coupons/**",
34-
"/api/v1/comments/**", "/api/v1/reviews/**", "/api/v1/admin/**", "/api/v1/rankings/**",
35-
"/api/v1/payments/**", "/test/**", "/health", "/actuator/**")
33+
auth -> auth.requestMatchers(
34+
"/api/v1/users/signup",
35+
"/api/v1/users/login",
36+
"/api/v1/users/verify/**",
37+
"/swagger-ui/**",
38+
"/v3/api-docs/**",
39+
"/health",
40+
"/actuator/**")
41+
.permitAll()
42+
.requestMatchers(HttpMethod.GET,
43+
"/api/v1/profiles/*",
44+
"/api/v1/profiles/*/created-lessons",
45+
"/api/v1/lessons",
46+
"/api/v1/lessons/search/nearby",
47+
"/api/v1/lessons/*",
48+
"/api/v1/lessons/summary/*",
49+
"/api/v1/lessons/apply/status/*",
50+
"/api/v1/comments/**",
51+
"/api/v1/reviews/**",
52+
"/api/v1/rankings/**")
3653
.permitAll()
3754
.requestMatchers("/api/v1/admin/**")
3855
.hasRole("ADMIN")

src/main/java/com/threestar/trainus/global/controller/S3TestController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.http.MediaType;
44
import org.springframework.http.ResponseEntity;
5+
import org.springframework.context.annotation.Profile;
56
import org.springframework.web.bind.annotation.PostMapping;
67
import org.springframework.web.bind.annotation.RequestMapping;
78
import org.springframework.web.bind.annotation.RequestParam;
@@ -15,6 +16,7 @@
1516
import lombok.RequiredArgsConstructor;
1617

1718
@Tag(name = "S3 테스트 컨트롤러", description = "S3 업로더 테스트용 컨트롤러입니다.")
19+
@Profile({"local", "test"})
1820
@RestController
1921
@RequestMapping("/api/v1/test/s3")
2022
@RequiredArgsConstructor
@@ -38,4 +40,4 @@ public ResponseEntity<String> upload(
3840
return ResponseEntity.badRequest().body("업로드 실패: " + e.getMessage());
3941
}
4042
}
41-
}
43+
}

0 commit comments

Comments
 (0)