从 2.0.0.M4 开始,我的SecurityConfiguration
扩展实现WebSecurityConfigurerAdapter
被完全忽略了。结果,我的应用程序现在无法启动,因为没有AuthenticationProvider
.这篇博文中的信息不是很有帮助。我错过了有关如何设置自 2.0.0.M4 以来的安全配置的其他信息(以完整示例的形式),包括AuthorizationManager
、UserDetailsService
和PasswordEncoder
。使用 2.0.0.M3 一切正常。
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
protected void configure(final HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests().antMatchers("/", "/sign-in").permitAll().and()
.authorizeRequests().anyRequest().authenticated().and()
.logout().logoutUrl("/sign-out").logoutSuccessUrl("/");
}
@Override
public void configure(final AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder
.userDetailsService(this.userDetailsService)
.passwordEncoder(this.passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}