작성
·
736
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
0
https://github.com/jaeyeonme/spring-security
여기에 올려두었습니다! 이 다음 것도 계속 진행하긴했습니다.