【发布时间】:2016-09-02 01:45:46
【问题描述】:
这是我唯一的配置类:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled=true, jsr250Enabled=true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userSearchBase("cn=users,cn=accounts")
.userSearchFilter("uid={0}")
.contextSource()
.url("ldap://1.2.3.4/dc=dev");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO: fix frontend
http.csrf().disable();
}
}
我没有其他配置类或注释。我的application.properties 只是设置了server.port 和一些日志记录级别。如果我注释掉 ldap 代码并使用,例如,inMemoryAuthentication,那么一切正常。
我已经尝试了所有在网上找到的使用.ldapAuthentication() 的示例,包括这里的一些相关问题,它们都导致了这个错误。怎么了?
我相信所有相关的依赖都来自这些行:
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-web'
堆栈跟踪的一小部分:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
...
Caused by: org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:44)
...
【问题讨论】:
-
你添加
compile "org.springframework.security:spring-security-ldap"依赖了吗? -
不,这就是问题所在。谢谢!我最终发现它构建了两次,第一次因为
NoClassDefFound org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry$RequestMatchers异常而失败。
标签: java spring spring-security spring-boot spring-security-ldap