일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- spring mongoTemplate
- kotiln const
- mongodb lookup
- java 파티
- spring mongoTemplate switch
- ipfs singletone
- 자바 1676
- java 1509
- java 팩토리얼 개수
- 익명 객체 @transactional
- spring mongodb
- Spring ipfs
- go
- 백준 특정한 최단 경로
- kotiln functional interface
- 백준 연결요소 자바
- 자바 백준 팩토리얼 개수
- 안정해시
- spring mongodb switch
- ipfs bean
- nodejs rabbitmq
- java 백준 1509
- 전략 패턴이란
- 백준 2252 줄세우기
- 백준 1504 java
- kotiln const val
- Java Call By Refernce
- rabbitmq 싱글톤
- javav 1676
- java 1238
Archives
- Today
- Total
공부 흔적남기기
SpringSecurity 로그인 실패시 Http 400보내는 방법 본문
728x90
반응형
SpringSecurity에서 .formlogin을 이용하여 로그인을 할때 실패시 .failureUrl을 사용하면 Controller에서 redirect된 Url을 못잡는 문제가 발생하였다. 어떤 이유인지는 정확히 모르겠지만 잡히지 않는 문제가 생겨 .failHandler를 사용하는 방식으로 해결하였다.
.failHandler는 AuthFailureHandler 객체를 매개변수로 입력받는데
우리는 AuthFailureHandler 구현체를 만들어fail 로직을 만들어주면된다.
로직은 간단하다.
@Component
public class AuthFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
response.sendError(400);
}
}
Security를 설정하는 class에서 DI로 객체를 받은후
.failureHandler(/*AuthFailureHandler 객체*/)
이런식으로 적어주면 끝이다!
이번 기회를 통해 문제가 계속해서 해결이 되지않으면 새로운 방식을 도입해보자는 유연한 생각해보자는 경험을 얻게되어 좋았다.
728x90
반응형
'web study > Spring' 카테고리의 다른 글
SpringBoot Redis를 활용한 Socket 통신(WebSocket, Stomp) (0) | 2022.03.09 |
---|---|
Spring MVC Kakao소셜 로그인 방법과 과정 (0) | 2022.02.16 |
Spring MVC (0) | 2022.02.06 |
DispatcherServlet의 간단한 과정 (0) | 2022.01.30 |
IOC/DI란 무엇일까 (0) | 2022.01.30 |