Tôi đang cố gắng để thực hiện xác thực tùy chỉnh stateless với Xuân An bằng cách làm theo này articlean ninh mùa xuân không gọi bộ lọc xác thực tùy chỉnh của tôi khi chạy thử nghiệm JUnit
Vấn đề tôi đang phải đối mặt là bộ lọc tùy chỉnh của tôi không được gọi bởi khuôn khổ, ngay cả khi SecurityConfig tôi trông gần giống như trong các liên kết trước đó (một chút đơn giản):
@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("appAuthenticationProvider")
private AuthenticationProvider authenticationProvider;
@Autowired
@Qualifier("appAuthenticationFilter")
private AppAuthenticationFilter appAuthenticationFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable().
sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests().anyRequest().authenticated()
.and()
.anonymous().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedEntryPoint());
http.addFilterBefore(appAuthenticationFilter, BasicAuthenticationFilter.class);
}
@Bean
public AuthenticationEntryPoint unauthorizedEntryPoint() {
return (request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
tôi không gửi mã cho authenticationProvider và appAuthenticationFilter như cũ là làm việc tốt (tôi có thể đăng nhập bằng cách sử dụng/đăng nhập điểm cuối) và sau này chỉ thực hiện GenericFilterBean và thậm chí không được gọi.
Mọi trợ giúp sẽ được đánh giá cao!