• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

Ajax Custom DSLs - customConfigurerAjax(HttpSecurity http) 에서 loginProcessingUrl(/api/login) 처리할 때 null

23.07.27 10:14 작성 23.07.27 13:18 수정 조회수 384

0

customConfigurerAjax(HttpSecurity http) 에서 loginProcessingUrl("/api/login") 처리할 때

private void customConfigurerAjax(HttpSecurity http) throws Exception {
    http
            .apply(new AjaxLoginConfigurer<>())
            .successHandlerAjax(ajaxAuthenticationSuccessHandler())
            .failureHandlerAjax(ajaxAuthenticationFailureHandler())
            .setAuthenticationManager(authenticationManager(authenticationConfiguration))
            .loginProcessingUrl("/api/login")
    ;
}

AbstractAuthenticationFilerConfigurer 클래스의 loginProcessingUrl을 호출하던데 여기서 authFilter 가 null 이어서 예외가 발생하는데

public T loginProcessingUrl(String loginProcessingUrl) {
    this.loginProcessingUrl = loginProcessingUrl;
    this.authFilter.setRequiresAuthenticationRequestMatcher(createLoginProcessingUrlMatcher(loginProcessingUrl));
    return getSelf();
}

어떻게 해결해야할지 모르겠습니다. ㅠㅠ

https://github.com/pdh9311/core-spring-security

추가로 ajax security 시작한 이후로 localhost:8080 으로 접속하니까 화면이 안나오고 401 에러가 발생하는데 어디가 문제인지 모르겠습니다. ㅠㅠ

답변 2

·

답변을 작성해보세요.

1

근데 AjaxLoginConfigurer 에서 getAuthenticationFilter() 를 참조하고 있는데 AjaxLoginProcessingFilter 은 어디에서 생성해 주고 있는가요?

cozyrust님의 프로필

cozyrust

질문자

2023.07.27

AjaxSecurityConfig.java에서 강사님이 Custom DSLs 적용하면서 주석 처리하길래 그냥 주석 처리 해버렸습니다.

혹시 AjaxLoginProcessingFilter를 Bean으로 등록하면 AjaxLoginConfigurer에서 알아서 가져다 쓰려나 하고 이전에 주석처리했던 것을 다시 돌려놓고 @Bean 어노테이션을 붙였는데 안되긴 하더라고요.

지금 제대로 이해가 되지 않는 상태로 일단 한번 작성해보면서 들어보고 있어서 헷갈리는 부분이 많습니다.

아 밑에 화면이 나오긴 한다고 한거는 지금 보니 Custom DSLs을 적용하기 전으로 돌아가서 해보니 저렇게 해야했다 인데, 다른 질문들 찾아보니 AjaxSecurityConfig에서도 "/" 를 permitAll 로 설정해주지 않아서 그랬던 같긴합니다.

deprecated 안된 방식으로 수정하면서 강의를 들으려다보니까 강의와 코드가 조금 다른 부분 있어서 어렵네요....

강의에서 제공하는 소스를 보면

public final class AjaxLoginConfigurer<H extends HttpSecurityBuilder<H>> extends

AbstractAuthenticationFilterConfigurer<H, AjaxLoginConfigurer<H>, AjaxLoginProcessingFilter> {

private AuthenticationSuccessHandler successHandler;

private AuthenticationFailureHandler failureHandler;

private AuthenticationManager authenticationManager;

public AjaxLoginConfigurer() {

super(new AjaxLoginProcessingFilter(), null);

}

AjaxLoginConfigurer 생성자에서 AjaxLoginProcessingFilter 를 생성하고 있습니다.

cozyrust 님께서 공유해 주신 소스를 보면 AjaxLoginProcessingFilter 를 생성하는 저 부분이 없는데 추가해 주시면 될 것 같습니다.

0

cozyrust님의 프로필

cozyrust

질문자

2023.07.27

@Order(0) - formSecurityFilterChain

@Order(1) - ajaxSecurityFilterChain

으로 변경해주니 화면이 나오긴 하네요...