authenticationEntryPoint 에서 sendRedirect말고 formLogin을 다시 띄워주는 방법
766
작성한 질문수 18
제목과 일치합니다.
response.sendredirect하지않고 security에서 제공하는 formLogin을 띄워주려면 어떻게 코드를 작성 해야 하나요?
답변 2
0
시큐리티에서 제공하는 폼로그인은
response.sendRedirect("/login"); 으로 해도 됩니다.
만약 formLogin.loginPage() 설정을 따로 하지 않으셨다면 기본적으로는 시큐리티에서 제공하는 로그인 화면으로 이동하게 됩니다.
formLogin.loginPage() 를 설정하셨다면 시큐리티의 로그인 화면으로 갈 수 있는 방법은 없습니다.
혹시 커스텀 로그인 페이지를 설정하지 않았는데도 시큐리티 로그인 화면으로 이동하지 않는가요?
0
안녕하세요, 인프런 AI 인턴이에요.
authenticationEntryPoint에서 sendRedirect 대신에 formLogin을 다시 띄워주려면 아래와 같이 코드를 작성할 수 있어요.
public class CustomAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
public CustomAuthenticationEntryPoint(String loginFormUrl) {
super(loginFormUrl);
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
// formLogin을 다시 띄워주기 위해 로그인 페이지 URL로 redirect
response.sendRedirect(getLoginFormUrl());
}
}
위의 코드에서 CustomAuthenticationEntryPoint는 LoginUrlAuthenticationEntryPoint를 상속받아서 만들었습니다. LoginUrlAuthenticationEntryPoint는 sendRedirect를 사용하여 로그인 페이지 URL로 redirect 하게 되어있는데요, CustomAuthenticationEntryPoint에서는 오버라이딩을 통해 sendRedirect 대신에 formLogin을 다시 띄워주기 위해 로그인 페이지 URL로 redirect 해주도록 수정하였습니다.
이렇게 수정하면 authenticationEntryPoint에서 sendRedirect를 사용하지 않고도 formLogin을 다시 띄워줄 수 있어요.
더 자세한 내용이나 코드 구현 방법에 대해서는 Spring Security 공식 문서나 관련 자료를 참고하시면 도움이 될 것입니다.
도움이 되셨길 바랍니다. 추가로 궁금한 내용이 있으면 언제든지 물어보세요. 좋은 하루 되세요!
0
http.exceptionHandling()
.authenticationEntryPoint(new AuthenticationEntryPoint() {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.sendRedirect("/login");
}
});위 코드 기준에서 아래와같이 적용하면 되나요?
http.exceptionHandling()
.authenticationEntryPoint(new CustomAuthenticationEntryPoint () {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.sendRedirect(getLoginFormUrl);
}
});
시큐리티 공부 버전 질문
0
176
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
187
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
177
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
251
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
236
1
파라미터값이 넘어가지 않습니다 ....
0
374
1
security filterChain 설정 질문이 있습니다.
0
332
1
소스 부분 질문 드립니다.
0
210
2
섹션4 7번 강의 문제가 있는거 같네요.
0
345
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
306
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
557
2
error , exception 이 잘 안됩니다.
0
284
2
thymeleaf tag 질문합니다.
0
198
2
버전업하면서 deprecated된 것들이 너무많아요
0
478
1
spring security 패치 관련
0
437
1
모바일을 사용할때 토큰말고 세션
0
847
2
DB 연동한 인가 부분에 대한 질문입니다!
0
265
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
308
1
Config 파일 생성 시 질문이 있습니다.
0
228
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
432
2
403 에러 뜹니다.
0
813
2
login_proc의 존재에 대한 간략한 설명입니다
0
277
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
286
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
191
1





