Skip to content

Commit 4b7a62d

Browse files
authored
Merge branch 'main' into chore#320
2 parents e22da9d + adc72fd commit 4b7a62d

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/main/java/com/back/domain/user/controller/UserAuthController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public RsData<Void> logout(HttpServletRequest request, HttpServletResponse respo
5757
@ApiResponses(value = {
5858
@ApiResponse(responseCode = "200", description = "사용자 정보 조회"),
5959
})
60+
6061
@GetMapping("/me")
6162
public RsData<UserMeResDto> getCurrentUser() {
6263
UserMeResDto userInfo = userAuthService.getCurrentUser();

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.back.global.security;
22

3+
import com.back.global.rsData.RsData;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
35
import org.springframework.beans.factory.annotation.Value;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
@@ -62,33 +64,34 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
6264
.addFilterBefore(customAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
6365
.authorizeHttpRequests(auth -> auth
6466

65-
// OAuth, GET POST 둘 다 사용
66-
.requestMatchers("/oauth2/**").permitAll()
67-
.requestMatchers("/login/oauth2/**").permitAll()
67+
// OAuth, GET POST 둘 다 사용
68+
.requestMatchers("/oauth2/**").permitAll()
69+
.requestMatchers("/login/oauth2/**").permitAll()
6870

69-
//르프레시 갱신 및 칵테일 검색
70-
.requestMatchers(POST, "/user/auth/refresh").permitAll()
71-
.requestMatchers(POST, "/cocktails/search").permitAll()
71+
//르프레시 갱신 및 칵테일 검색
72+
.requestMatchers(POST, "/user/auth/refresh").permitAll()
73+
.requestMatchers(POST, "/cocktails/search").permitAll()
7274

73-
// share은 인증 필요
74-
.requestMatchers(GET, "/cocktails/{id}/share").authenticated()
75+
// share은 인증 필요
76+
.requestMatchers(GET, "/cocktails/{id}/share").authenticated()
7577

76-
// 권한 불필요 - 조회 API
77-
.requestMatchers(GET, "/").permitAll()
78-
.requestMatchers(GET, "/actuator/**").permitAll()
78+
// 권한 불필요 - 조회 API
79+
.requestMatchers(GET, "/").permitAll()
80+
.requestMatchers(GET, "/actuator/**").permitAll()
7981

80-
.requestMatchers(GET, "/cocktails/**").permitAll()
82+
.requestMatchers(GET, "/cocktails/**").permitAll()
8183

82-
.requestMatchers(GET, "/posts").permitAll()
83-
.requestMatchers(GET, "/posts/{postId}").permitAll()
84-
.requestMatchers(GET, "/posts/{postId}/comments").permitAll()
85-
.requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll()
86-
.requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll()
87-
.requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll()
88-
.requestMatchers(GET, "/category").permitAll()
84+
.requestMatchers(GET, "/posts").permitAll()
85+
.requestMatchers(GET, "/posts/{postId}").permitAll()
86+
.requestMatchers(GET, "/posts/{postId}/comments").permitAll()
87+
.requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll()
88+
.requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll()
89+
.requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll()
90+
.requestMatchers(GET, "/category").permitAll()
91+
92+
// 나머지 모든 API는 인증 필요
93+
.anyRequest().authenticated()
8994

90-
// 나머지 모든 API는 인증 필요
91-
.anyRequest().authenticated()
9295

9396
// 회원 or 인증된 사용자만 가능
9497
// .requestMatchers("/admin/**").hasRole("ADMIN")
@@ -110,12 +113,19 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
110113
.authenticationEntryPoint((request, response, authException) -> {
111114
response.setContentType("application/json;charset=UTF-8");
112115
response.setStatus(401);
113-
response.getWriter().write("{\"code\":401,\"message\":\"로그인 후 이용해주세요.\"}");
116+
117+
RsData<Void> rsData = RsData.of(401, "로그인 후 이용해주세요.");
118+
119+
ObjectMapper mapper = new ObjectMapper();
120+
response.getWriter().write(mapper.writeValueAsString(rsData));
114121
})
115122
.accessDeniedHandler((request, response, accessDeniedException) -> {
116123
response.setContentType("application/json;charset=UTF-8");
117124
response.setStatus(403);
118-
response.getWriter().write("{\"code\":403,\"message\":\"권한이 없습니다.\"}");
125+
RsData<Void> rsData = RsData.of(403, "권한이 없습니다.");
126+
127+
ObjectMapper mapper = new ObjectMapper();
128+
response.getWriter().write(mapper.writeValueAsString(rsData));
119129
})
120130
)
121131
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin));

0 commit comments

Comments
 (0)