• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

여기서 왜 401 ERROR 가 발생하는지 잘 모르겠습니다.

22.02.05 22:52 작성 조회수 526

0

안녕하세요. 강의 매우 잘 듣고 있습니다.

다름이 아니라 질문이 있는데요.

 

시큐리티 설정은 이렇게 해주고, ajax.http 실행시켜주면

 

HTTP/1.1 401 

X-Content-Type-Options: nosniff

X-XSS-Protection: 1; mode=block

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: 0

X-Frame-Options: DENY

Content-Length: 0

Date: Sat, 05 Feb 2022 13:50:25 GMT

Keep-Alive: timeout=60

Connection: keep-alive

 

<Response body is empty>

 

Response code: 401; Time: 4ms; Content length: 0 bytes

 

401 에러가 발생하는데 어디쪽을 확인하면 좋을까요..?

 

AjaxSecurityConfig

@Order(0)
@Configuration
public class AjaxSecurityConfig extends WebSecurityConfigurerAdapter {


@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(ajaxAuthenticationProvider());
}

@Bean
public AuthenticationProvider ajaxAuthenticationProvider() {
return new AjaxAuthenticationProvider();
}

@Bean
public AuthenticationSuccessHandler ajaxAuthenticationSuccessHandler() {
return new AjaxAuthenticationSuccessHandler();
}

@Bean
public AuthenticationFailureHandler ajaxAuthenticationFailureHandler() {
return new AjaxAuthenticationFailureHandler();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/**")
.authorizeRequests()
.antMatchers("/api/messages").hasRole("MANAGER")
.anyRequest().authenticated()
.and()
.addFilterBefore(ajaxLoginProcessingFilter(), UsernamePasswordAuthenticationFilter.class)
;

http
.exceptionHandling()
.authenticationEntryPoint(new AjaxLoginAuthenticationEntryPoint())
.accessDeniedHandler(ajaxAccessDeniedHandler())
;

http.csrf().disable();
}
@Bean
public AccessDeniedHandler ajaxAccessDeniedHandler() {
return new AjaxAccessDeniedHandler();
}

@Bean
public AjaxLoginProcessingFilter ajaxLoginProcessingFilter() throws Exception {
AjaxLoginProcessingFilter filter = new AjaxLoginProcessingFilter();
filter.setAuthenticationManager(authenticationManagerBean());
filter.setAuthenticationSuccessHandler(ajaxAuthenticationSuccessHandler());
filter.setAuthenticationFailureHandler(ajaxAuthenticationFailureHandler());
return filter;
}
}

답변 2

·

답변을 작성해보세요.

0

Discuss Angel님의 프로필

Discuss Angel

2023.05.10

저와같은 경험을하는 다른분들을 위해, 저는 httpie를 사용합니다 pie에서는 매 요청마다 세션이 초기화됩니다.

사용하는 어플리케이션 옵션을 확인해보세요.

0

실행 전체 소스 공유 부탁드립니다

조재연님의 프로필

조재연

질문자

2022.02.06

https://github.com/jaeyeonme/spring-security

 

여기에 올려두었습니다! 이 다음 것도 계속 진행하긴했습니다.