1717import org .springframework .web .cors .CorsConfigurationSource ;
1818import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
1919import org .springframework .session .data .redis .config .annotation .web .http .EnableRedisHttpSession ;
20+ import org .springframework .http .HttpStatus ;
2021
2122import java .io .IOException ;
2223import java .util .List ;
@@ -32,13 +33,8 @@ public class SecurityConfig {
3233
3334 @ Bean
3435 public AuthenticationSuccessHandler oauth2AuthenticationSuccessHandler () {
35- return new AuthenticationSuccessHandler () {
36- @ Override
37- public void onAuthenticationSuccess (HttpServletRequest request , HttpServletResponse response ,
38- Authentication authentication ) throws IOException , ServletException {
39- // Vite 프론트엔드로 리다이렉트
40- response .sendRedirect (front_url );
41- }
36+ return (request , response , authentication ) -> {
37+ response .sendRedirect (front_url );
4238 };
4339 }
4440
@@ -47,18 +43,7 @@ public CorsConfigurationSource corsConfigurationSource() {
4743 CorsConfiguration configuration = new CorsConfiguration ();
4844 configuration .setAllowedOrigins (List .of (front_url ));
4945 configuration .setAllowedMethods (List .of ("GET" , "POST" , "PUT" , "DELETE" , "PATCH" , "OPTIONS" ));
50- configuration .setAllowedHeaders (List .of (
51- "Authorization" ,
52- "Cache-Control" ,
53- "Content-Type" ,
54- "Origin" ,
55- "Accept" ,
56- "Referer" ,
57- "User-Agent" ,
58- "Access-Control-Allow-Origin" ,
59- "*"
60- ));
61- configuration .setExposedHeaders (List .of ("Authorization" , "Content-Type" ));
46+ configuration .setAllowedHeaders (List .of ("*" )); // 모든 헤더 허용으로 단순화
6247 configuration .setAllowCredentials (true );
6348 configuration .setMaxAge (3600L );
6449
@@ -94,12 +79,24 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
9479 )
9580 .successHandler (oauth2AuthenticationSuccessHandler ())
9681 )
82+ .sessionManagement (session -> session
83+ .sessionCreationPolicy (SessionCreationPolicy .IF_REQUIRED )
84+ .maximumSessions (1 )
85+ .expiredUrl (front_url + "/login" )
86+ )
9787 .logout (logout -> logout
98- .logoutSuccessUrl (front_url + "/login" )
88+ .logoutUrl ("/api/auth/logout" )
89+ .logoutSuccessHandler ((request , response , authentication ) -> {
90+ response .setStatus (HttpStatus .OK .value ());
91+ response .setContentType ("application/json;charset=UTF-8" );
92+ response .getWriter ().write ("{\" message\" :\" Logout successful\" ,\" status\" :\" success\" }" );
93+ })
9994 .invalidateHttpSession (true )
100- .deleteCookies ("JSESSIONID" )
95+ .clearAuthentication (true )
96+ .deleteCookies ("JSESSIONID" , "SESSION" ) // Redis 세션 쿠키 이름 수정
97+ .permitAll ()
10198 );
10299
103100 return http .build ();
104101 }
105- }
102+ }
0 commit comments