Skip to content

Commit

Permalink
Merge pull request #119 from swm-nodriversomabus/FIX-LOGOUT-LOGIN
Browse files Browse the repository at this point in the history
fix(BE): Logout Cookie 제거 테스트 완료 - 개발 서버 반영 후 결과 파악 #114
  • Loading branch information
namhyo01 authored Oct 18, 2023
2 parents 7db6790 + 116efdc commit d8e448d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/main/java/com/example/api/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.example.api.auth.handler.MyLogoutSuccessHandler;
import com.example.api.auth.repository.OAuth2AuthorizationRequestBasedOnCookieRepository;
import com.example.api.auth.service.CustomOAuth2UserService;
import com.example.api.auth.utils.CookieUtils;
import jakarta.servlet.http.Cookie;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -76,17 +78,29 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
oauth2.failureHandler(oAuth2LoginFailureHandler);//핸들러
oauth2.successHandler(oAUth2LoginSuccessHandler);
});
httpSecurity.logout(
httpSecurityLogoutConfigurer ->
httpSecurityLogoutConfigurer
.logoutRequestMatcher(new AntPathRequestMatcher("/auth/logout"))
.invalidateHttpSession(true)
.deleteCookies("access_token")
.clearAuthentication(true)
.logoutSuccessHandler(myLogoutSuccessHandler)
.permitAll()

httpSecurity.logout(logout -> logout
.logoutUrl("/logout")
.addLogoutHandler(((request, response, authentication) -> {
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for (Cookie cookie : request.getCookies()) {
String cookieName = cookie.getName();
CookieUtils.addCookie(response, cookieName, null, 0);
}
}
}))
);
// httpSecurity.logout(
// httpSecurityLogoutConfigurer ->
// httpSecurityLogoutConfigurer
// .logoutRequestMatcher(new AntPathRequestMatcher("/auth/logout"))
// .invalidateHttpSession(true)
// .deleteCookies("access_token")
// .clearAuthentication(true)
// .logoutSuccessHandler(myLogoutSuccessHandler)
// .permitAll()
//
// );
// httpSecurity.logout(logout -> logout.logoutSuccessUrl("/"));

return httpSecurity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding("UTF-8");
objectMapper.writeValue(response.getWriter(), StatusResponseDto.addStatus(401));

}
}
}

0 comments on commit d8e448d

Please sign in to comment.