url의 토큰 id를 사용하여 나머지 서비스를 인증해야한다. 나는 이것으로 가이드를 사용하여 이것을 설정하기 위해 자바 설정을 사용하려고한다. post. 내 문제는 공급자에서 인증이 실패 할 때 throw되는 "BadCredentialsException"을 처리하는 방법을 모르겠다는 것입니다. 여기에 내 보안 구성이 있습니다 :자바 설정을 통한 스프링 보안 : 커스텀 제공자로부터 BadCredentialsException을 처리하는 방법
public static class SecurityConfigForRS extends
WebSecurityConfigurerAdapter {
@Autowired
TokenAuthenticationProvider tokenAuthenticationProvider;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.authenticationProvider(tokenAuthenticationProvider);
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean()
throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.regexMatcher("^/rest.*")
.addFilterBefore(
new TokenAuthenticationFilter(
authenticationManagerBean()),
AbstractPreAuthenticatedProcessingFilter.class)
.and().csrf().disable();
}
}
다른 구현은 건너 뜁니다. 도움이된다면 나중에 게시 할 것입니다.
토큰이 없거나 유효하지 않은 경우 TokenAuthernticationProvider
은 BadCredentialsException
을 던집니다. 나는 이것을 받아 들여 401-Unauthorized
을 돌려 보내야합니다. 이것을 할 수 있습니까?