Skip to content

Commit 7d1358c

Browse files
committed
Ref: 인증/인가 인프라 개선
1 parent 51d828e commit 7d1358c

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

src/main/java/com/back/global/security/SecurityConfig.java

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,49 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3737
// 인가 규칙 설정
3838
.authorizeHttpRequests(
3939
auth -> auth
40-
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // CORS Preflight 요청 허용
41-
.requestMatchers("/api/auth/**", "/oauth2/**", "/login/oauth2/**").permitAll()
42-
.requestMatchers("api/ws/**", "/ws/**").permitAll()
40+
// CORS Preflight
41+
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
42+
43+
// 개발 및 모니터링용
44+
.requestMatchers(
45+
"/",
46+
"/swagger-ui/**",
47+
"/v3/api-docs/**"
48+
).permitAll() // Swagger
49+
.requestMatchers("/h2-console/**").permitAll() // H2 콘솔
50+
.requestMatchers("/actuator/health").permitAll() // Health check
51+
52+
// 인증/인가
53+
.requestMatchers(
54+
"/api/auth/**",
55+
"/oauth2/**",
56+
"/login/oauth2/**"
57+
).permitAll()
58+
59+
// WebSocket
60+
.requestMatchers(
61+
"api/ws/**",
62+
"/ws/**"
63+
).permitAll()
64+
65+
// 스터디룸 관련
66+
.requestMatchers("/api/rooms/*/messages/**").permitAll() // 방 내 채팅 메시지
67+
.requestMatchers(HttpMethod.GET,
68+
"/api/rooms", // 전체 목록 조회
69+
"/api/rooms/all", // 전체 방 목록
70+
"/api/rooms/public", // 공개 방 목록
71+
"/api/rooms/popular", // 인기 방 목록
72+
"/api/rooms/*" // 방 상세 조회
73+
).permitAll()
74+
//.requestMatchers("/api/rooms/RoomChatApiControllerTest").permitAll() // 테스트용
75+
76+
// 커뮤니티 관련
4377
.requestMatchers(HttpMethod.GET, "/api/posts/**").permitAll()
44-
.requestMatchers("/api/rooms/*/messages/**").permitAll() //스터디 룸 내에 잡혀있어 있는 채팅 관련 전체 허용
45-
// 방 목록 조회 API 비로그인 허용
46-
.requestMatchers(HttpMethod.GET, "/api/rooms").permitAll()
47-
.requestMatchers(HttpMethod.GET, "/api/rooms/all").permitAll()
48-
.requestMatchers(HttpMethod.GET, "/api/rooms/public").permitAll()
49-
.requestMatchers(HttpMethod.GET, "/api/rooms/popular").permitAll()
50-
.requestMatchers(HttpMethod.GET, "/api/rooms/*").permitAll() // 방 상세 조회
51-
//.requestMatchers("/api/rooms/RoomChatApiControllerTest").permitAll() // 테스트용 임시 허용
52-
.requestMatchers("/","/swagger-ui/**", "/v3/api-docs/**").permitAll() // Swagger 허용
53-
.requestMatchers("/h2-console/**").permitAll() // H2 Console 허용
54-
.requestMatchers("/actuator/health").permitAll() // 헬스 체크 허용
55-
.requestMatchers("/file/**").permitAll() // 파일 관련 요청 모두 허용(테스트 완료 후, 요청제한 예정)
78+
79+
// 파일 관련 (테스트용, 추후 요청 제한 예정)
80+
.requestMatchers("/file/**").permitAll()
81+
82+
// 그 외 모든 요청은 인증 필요
5683
.anyRequest().authenticated()
5784
)
5885

src/main/java/com/back/global/security/oauth/OAuth2LoginSuccessHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class OAuth2LoginSuccessHandler implements AuthenticationSuccessHandler {
4343

4444
@Value("${frontend.base-url}")
4545
private String FRONTEND_BASE_URL;
46+
4647
@Override
4748
public void onAuthenticationSuccess(HttpServletRequest request,
4849
HttpServletResponse response,
@@ -54,7 +55,6 @@ public void onAuthenticationSuccess(HttpServletRequest request,
5455
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
5556

5657
// 토큰 생성
57-
String accessToken = jwtTokenProvider.createAccessToken(user.getId(), user.getUsername(), user.getRole().name());
5858
String refreshToken = jwtTokenProvider.createRefreshToken(user.getId());
5959

6060
// DB에 Refresh Token 저장

0 commit comments

Comments
 (0)