У меня есть приложение Spring Boot, в котором страница входа будет в индексе (nav), а также на странице входа. Я выполнил конфигурацию аннотации заказа, однако она работает только так, как ожидалось, порядок 1 (проверено путем переключения порядка, и 1 работает только нормально) Для ошибки порядка 2: метод запроса 'POST' не поддерживается, есть идея?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Qualifier("userDetailsServiceImpl")
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Configuration
@Order(1)
public static class WebSecurityConfig1 extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(new AntPathRequestMatcher("/**"))
.authorizeRequests()
.antMatchers("/resources/**", "/registration", "/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/loginIndex")
.usernameParameter("username")
.passwordParameter("password")
.failureUrl("/loginIndex?error")
.loginProcessingUrl("/loginIndex")
.permitAll()
.and()
.logout()
.permitAll();
}
}
@Configuration
@Order(2)
public static class WebSecurityConfig2 extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(new AntPathRequestMatcher("/**"))
.authorizeRequests()
.antMatchers("/resources/**", "/registration","/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("username")
.passwordParameter("password")
.failureUrl("/login?error")
.loginProcessingUrl("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
@Bean
public AuthenticationManager customAuthenticationManager() throws Exception {
return authenticationManager();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}