【发布时间】:2014-12-11 03:37:09
【问题描述】:
我在使用 Spring Boot 1.1.7 保护静态资源时遇到问题。我创建了一个带有自定义 AuthenticationProvider 的 SecurityConfiguration。
SecurityConfiguration 和 AuthenticationProvider bean 正在加载,但我的自定义“身份验证”方法从未被触发。我已经查看了大部分教程,但无法使用自定义身份验证限制对任何 url 的访问。
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
final static Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
private @Autowired CustomAuthenticationProvider provider;
/**
* Configure global.
*
* @param auth the auth
* @throws Exception the exception
*/
// @Autowired
// public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth.authenticationProvider(this.provider);
// }
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
log.warn("Configure AuthMgrBuilder");
auth.authenticationProvider(this.provider);
}
/* (non-Javadoc)
* @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
log.warn("Configure http");
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.csrf().disable();
}
}
【问题讨论】:
标签: java spring spring-security spring-boot