11package com .back .global .security ;
22
3+ import com .back .global .rsData .RsData ;
4+ import com .fasterxml .jackson .databind .ObjectMapper ;
35import org .springframework .beans .factory .annotation .Value ;
46import org .springframework .context .annotation .Bean ;
57import org .springframework .context .annotation .Configuration ;
@@ -76,18 +78,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
7678 .requestMatchers (GET , "/" ).permitAll ()
7779 .requestMatchers (GET , "/actuator/**" ).permitAll ()
7880
79- .requestMatchers (GET , "/cocktails/**" ).permitAll ()
81+ .requestMatchers (GET , "/posts" ).permitAll ()
82+ .requestMatchers (GET , "/posts/{postId}" ).permitAll ()
83+ .requestMatchers (GET , "/posts/{postId}/comments" ).permitAll ()
84+ .requestMatchers (GET , "/posts/{postId}/comments/{commentId}" ).permitAll ()
85+ .requestMatchers (GET , "/cocktails/{cocktailId}/comments" ).permitAll ()
86+ .requestMatchers (GET , "/cocktails/{cocktailId}/comments/{cocktailCommentId}" ).permitAll ()
87+ .requestMatchers (GET , "/category" ).permitAll ()
8088
81- .requestMatchers (GET , "/posts" ).permitAll ()
82- .requestMatchers (GET , "/posts/{postId}" ).permitAll ()
83- .requestMatchers (GET , "/posts/{postId}/comments" ).permitAll ()
84- .requestMatchers (GET , "/posts/{postId}/comments/{commentId}" ).permitAll ()
85- .requestMatchers (GET , "/cocktails/{cocktailId}/comments" ).permitAll ()
86- .requestMatchers (GET , "/cocktails/{cocktailId}/comments/{cocktailCommentId}" ).permitAll ()
87- .requestMatchers (GET , "/category" ).permitAll ()
88-
89- // 나머지 모든 API는 인증 필요
90- .anyRequest ().authenticated ()
89+ // 나머지 모든 API는 인증 필요
90+ .anyRequest ().authenticated ()
9191
9292
9393// 회원 or 인증된 사용자만 가능
@@ -110,12 +110,19 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
110110 .authenticationEntryPoint ((request , response , authException ) -> {
111111 response .setContentType ("application/json;charset=UTF-8" );
112112 response .setStatus (401 );
113- response .getWriter ().write ("{\" code\" :401,\" message\" :\" 로그인 후 이용해주세요.\" }" );
113+
114+ RsData <Void > rsData = RsData .of (401 , "로그인 후 이용해주세요." );
115+
116+ ObjectMapper mapper = new ObjectMapper ();
117+ response .getWriter ().write (mapper .writeValueAsString (rsData ));
114118 })
115119 .accessDeniedHandler ((request , response , accessDeniedException ) -> {
116120 response .setContentType ("application/json;charset=UTF-8" );
117121 response .setStatus (403 );
118- response .getWriter ().write ("{\" code\" :403,\" message\" :\" 권한이 없습니다.\" }" );
122+ RsData <Void > rsData = RsData .of (403 , "권한이 없습니다." );
123+
124+ ObjectMapper mapper = new ObjectMapper ();
125+ response .getWriter ().write (mapper .writeValueAsString (rsData ));
119126 })
120127 )
121128 .headers (headers -> headers .frameOptions (HeadersConfigurer .FrameOptionsConfig ::sameOrigin ));
0 commit comments