【发布时间】:2018-06-09 10:09:08
【问题描述】:
我试图配置一个 spring 安全性以与 Rest 一起使用,所以我创建了这个文件:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().
csrf().disable().
authorizeRequests()
.antMatchers("/home").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginProcessingUrl("/login").failureForwardUrl("/login?erro")
.and().logout().logoutUrl("/logout")
.and().httpBasic().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider
= new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(encoder());
return authProvider;
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder(11);
}
}
但是当我尝试使用错误的密码和用户名访问 /login 时,尝试重定向到默认表单登录。
如何禁用此默认表单?
tks
【问题讨论】:
标签: spring-boot spring-security