【问题标题】:LDAP: Error creating springSecurityFilterChain: AlreadyBuiltException: This object has already been builtLDAP:创建 springSecurityFilterChain 时出错:AlreadyBuiltException:此对象已构建
【发布时间】: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


【解决方案1】:

添加compile org.springframework.security:spring-security-ldap会按照阿里的建议解决。

【讨论】:

    猜你喜欢
    • 2019-10-11
    • 1970-01-01
    • 2015-04-21
    • 2018-05-31
    • 2020-06-05
    • 2015-01-20
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多