当前位置: 首页 > 知识库问答 >
问题:

LDAP身份验证-Spring Security-LdapAuthenticationProvider

巫煌
2023-03-14

我很难让LDAP安全配置与xml配置一起工作。

org.springframework.beans.factory.BeanCreationException: Error creating bean               with name 'securityConfig': Injection of autowired dependencies failed; nested     exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.ldap.authentication.LdapAuthenticationProvider sgcbmw.security.SecurityConfig.ldapAuthenticationProvider; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.ldap.authentication.LdapAuthenticationProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)
<bean id="contextSource"class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap:/ldapserver"/>
        <property name="userDn" value="user"/>
        <property name="password" value="pass"/>
    </bean>

    <bean id="ldapAuthProvider"
          class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
        <constructor-arg>
            <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
                <constructor-arg ref="contextSource"/>
                <property name="userSearch">
                <bean id="userSearch"
                      class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
                    <constructor-arg index="0" value=""/>
                    <constructor-arg index="1" value="(&amp;(objectClass=user)(sAMAccountName={0}))"/>
                    <constructor-arg index="2" ref="contextSource" />
                </bean>
                </property>
                <property name="userDnPatterns">
                    <list><value>uid={0},ou=people</value></list>
                </property>
            </bean>
        </constructor-arg>
        <constructor-arg>
            <bean  class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
                <constructor-arg ref="contextSource"/>
                <constructor-arg value="ou=groups"/>
                <property name="groupRoleAttribute" value="memberOf"/>
            </bean>
        </constructor-arg>
    </bean>
    <security:authentication-manager>
        <security:authentication-provider ref="ldapAuthProvider" />
    </security:authentication-manager>
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private LdapAuthenticationProvider ldapAuthenticationProvider;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(ldapAuthenticationProvider);
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf().disable()
            .authorizeRequests()
            .anyRequest().fullyAuthenticated()
            .and()
            .formLogin();
}
}

共有1个答案

轩辕鸿
2023-03-14

是什么解决了我的问题:

为了安全起见,我创建了一个上下文xml配置,并将以下内容添加到web.xml中:

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/business-config.xml classpath:spring/spring-security-config.xml</param-value>
</context-param>

最后,我在spring-security-config.xml上配置beans,并在WebSecurityConfigurerAdapter类上自动调整它们。将其从XML中删除:

<security:authentication-manager>
    <security:authentication-provider ref="ldapAuthProvider" />
</security:authentication-manager>

多谢帮忙。

 类似资料:
  • 我使用Presto Cli测试ldap,下面是以下命令: 它不要求密码,我能够连接到Presto集群,并能够运行查询。为什么LDAP身份验证对此没有任何帮助?

  • 问题内容: 我试图让我的自定义Java应用程序使用我们的Active Directory服务器进行身份验证,但由于某种原因我无法使其正常工作。谁能看到为什么呢?这是我的方法如下: 结果: 问题答案: 你尝试过这种方式吗? 也更换 与

  • 我需要连接到LDAP服务器,但出现以下错误: javax。命名。AuthenticationException:[LDAP:错误代码49-80090308:LDAPPER:DSID-0C09034,注释:AcceptSecurityContext错误,数据525,向量 用户名和密码正确,我尝试设置相同的用户并传入另一个用编写的应用程序。NET,它在那里工作,但在Java中,我收到了错误消息。 我的

  • PS:我知道我可以使用一个额外的基于sAMAccountName的LDAP查询来获得用户的完整LDAP帐户,但是这将需要一个不必要的第二个LDAP查询,并且还需要将LDAP配置从Weblogic复制到我的应用程序中。

  • 问题内容: 这是我的情况: 一个Web应用程序对许多应用程序执行某种SSO 登录的用户,而不是单击链接,该应用就会向正确的应用发布包含用户信息(名称,pwd [无用],角色)的帖子 我正在其中一个应用程序上实现SpringSecurity以从其功能中受益(会话中的权限,其类提供的方法等) 因此,我需要开发一个 自定义过滤器 -我猜想-能够从请求中检索用户信息,通过自定义 DetailsUserSe

  • 我正在尝试为我的Spring MVC应用程序集成LDAP身份验证。如果我将contextSource设置为虚拟用户DN和相应的密码,则用户可以成功登录。我想做的是能够在不使用虚拟用户的情况下绑定ldap连接。 下面是工作原理的代码- 现在我已经尝试删除硬编码的userDn和密码(更新init())- 应用程序启动正常,但我遇到了一个例外——“必须在连接上成功绑定”。 Stacktrace- [UP