У меня следующая конфигурация весенней загрузки 2.0, но я все еще получаю базовый экран авторизации авторизации. Я не хочу отключать всю весеннюю безопасность, как предлагает почти каждый пост в Интернете. Я только хочу остановить страницу входа в форму и базовую авторизацию, чтобы я мог использовать свою собственную.
Я видел все предложения с allowAll и exclude = {SecurityAutoConfiguration.class} и несколько других, которые я больше не могу вспомнить. Это не то, что я хочу. Я хочу использовать Spring Security, но я хочу, чтобы мой конфиг не Spring Boots. Да, я знаю, что многие скажут, что это дубликат, но я не согласен, потому что все остальные ответы - полностью отключить Spring Security, а не просто остановить глупую страницу входа.
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class CustomSecurity extends WebSecurityConfigurerAdapter {
private final RememberMeServices rememberMeService;
private final AuthenticationProvider customAuthProvider;
@Value("${server.session.cookie.secure:true}")
private boolean useSecureCookie;
@Inject
public CustomSecurity(RememberMeServices rememberMeService, AuthenticationProvider customAuthProvider) {
super(true);
this.rememberMeService = rememberMeService;
this.bouncerAuthProvider = bouncerAuthProvider;
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/**").antMatchers("/webjars/**").antMatchers("/swagger-resources/**")
.antMatchers("/swagger-ui.html");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable().formLogin().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).headers().frameOptions().disable();
http.authenticationProvider(customAuthProvider).authorizeRequests().antMatchers("/health").permitAll()
.anyRequest().authenticated();
http.rememberMe().rememberMeServices(rememberMeService).useSecureCookie(useSecureCookie);
http.exceptionHandling().authenticationEntryPoint(new ForbiddenEntryPoint());
}
}