我有一个Spring Boot应用程序,其中登录页面将位于index(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());
}
在您的配置中发出
WebSecurityConfig1
并且WebSecurityConfig2
都配置为匹配每个网址。.ienew AntPathRequestMatcher("/**")
@Order(1)
将始终满足所有要求。解
因此,首先,您需要确定要将用户重定向到哪个URL,以及将用户重定向到第二登录页面。
例如,您可以说带有的网址/user
转到,loginPage("/loginIndex")
而其他所有内容都转到loginPage("/login")
。您可以通过在WebSecurityConfig1 new AntPathRequestMatcher("/**")
中用(new AntPathRequestMatcher("/user*")
)代替来实现
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句