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

上下文源的LDAP - AD用户名和密码配置

巢烨
2023-03-14

我正在使用Spring Security使用LDAP协议对Active Directory进行身份验证。以下代码在身份验证和设置LDAP模板(springSecurity.xml)中也运行良好:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:beans="http://www.springframework.org/schema/beans" 
            xmlns:ldap="http://www.springframework.org/schema/ldap"
            xsi:schemaLocation="
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd 
            http://www.springframework.org/schema/ldap 
            http://www.springframework.org/schema/ldap/spring-ldap.xsd">

    <http use-expressions="true">

        <intercept-url pattern="/login" access="permitAll" />
        <intercept-url pattern="/authenticated" access="isAuthenticated()" />

        <form-login login-page="/login" default-target-url="/authenticated"
            authentication-failure-url="/login?error=true" />
        <logout />


    </http>

    <beans:bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <beans:property name="location">
            <beans:value>classpath:/ldap.properties</beans:value>
        </beans:property>
        <beans:property name="SystemPropertiesMode">
            <beans:value>2</beans:value> <!-- OVERRIDE is 2 -->
        </beans:property>
    </beans:bean>

    <beans:bean id="adAuthenticationProvider"
        class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
        <beans:constructor-arg value="${sample.ldap.domain}" />
        <beans:constructor-arg value="${sample.ldap.url}" />
        <beans:property name="useAuthenticationRequestCredentials"
            value="true" />
        <beans:property name="convertSubErrorCodesToExceptions"
            value="true" />
    </beans:bean>


    <authentication-manager>
        <authentication-provider ref="adAuthenticationProvider" />
    </authentication-manager>

<!--  Ldap after authentication -->

    <context:property-placeholder location="classpath:/ldap.properties"
        system-properties-mode="OVERRIDE" />
    <context:annotation-config />

    <ldap:context-source id="contextSource" 
                        password="${sample.ldap.password}"
                        url="${sample.ldap.url}" 
                        username="${sample.ldap.userDn}" 
                        base="${sample.ldap.base}"
                        referral="follow" />

    <ldap:ldap-template id="ldapTemplate"
        context-source-ref="contextSource" />

    <ldap:repositories base-package="com.domain" />

    <beans:bean class="com.service.UserService">
        <beans:property name="directoryType" value="${sample.ldap.directory.type}" />
    </beans:bean>

    <!-- Required to make sure BaseLdapName is populated in UserService -->
    <beans:bean
        class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />

</beans:beans>

从login.jsp获取j_username和j_password时,身份验证工作正常。为了设置ldap模板,我使用了属性文件中定义的用户名和密码属性,但是我希望使用spring security中的相同用户名和密码。请指导我如何将LDAP:context-source id = " context source "中的用户名和密码属性绑定到Spring Security凭证。

代码有点乱,欢迎任何改进的输入。

共有1个答案

邢飞昂
2023-03-14

如参考文档的“配置”一章中所述,通过在 ContextSource 的配置元素中指定自定义身份验证-源-引用,可以对 ContextSource 使用 Spring 安全性身份验证。在你的情况下,你会使用Spring Security AuthenticationicationSource,随Spring Security一起提供。

<ldap:context-source id="contextSource" 
                    url="${sample.ldap.url}" 
                    base="${sample.ldap.base}"
                    referral="follow" 
                    authentication-source-ref="authenticationSource"/>

<bean id="authenticationSource"
     class="org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource" />
 类似资料:
  • 用户名和密码的来源 在章节中,用户详细信息保存在用户文件中。 FreeRADIUS使用此文件的内容以在身份验证过程中验证凭据。 FreeRADIUS通常是企业基础设施的一部分,而企业已经在其他地方创建了已有用户。 本章将介绍如何使用现有的用户存储。 在本章中,我们将: 查看用户商店选项 使用Linux系统用户作为FreeRADIUS的用户存储 使用MySQL作为FreeRADIUS的用户存储 使用

  • 我有麻烦管理詹金斯的秘密密码。我希望密码不显示在日志上,但我尝试了两种方法没有成功: 第一次尝试 我尝试使用全局凭据(不受限制)设置用户和pwd,如下所示: 我执行了: 但我可以在日志中看到,用户的写入是正确的,但pwd的写入方式与它的路径相同: 在我的自动测试中,也是通过输入完整路径而不是变量的值。 第二次尝试 我试着用这样的密文: 但控制台日志上显示的是原样的密码。 有人能帮我吗? 先谢谢你。

  • 问题内容: 我们正忙于为客户开发Java Web服务。有两种可能的选择: 将加密的用户名/密码存储在Web服务客户端上。从配置读取。客户端上的文件,解密并发送。 将加密的用户名/密码存储在Web服务器上。从配置读取。Web服务器上的文件,解密并在Web服务中使用。 Web服务使用用户名/密码来访问第三方应用程序。 客户端已经具有提供此功能的类,但是此方法涉及以明文方式发送用户名/密码(尽管在内联网

  • LDAP (Light-weight Directory Access Protocol) 是企业广泛部署的用户信息管理服务器,微软的活动目录服务器(Active Directory)完全兼容 LDAP。这个文档假定您已经了解了 LDAP 相关的知识和术语。 Seafile 是如何管理 LDAP 用户的 Seafile 中的用户分为两类: 保存在 Seafile 内部数据库中的用户。这些用户关联了

  • 你可以配置 Navicat Monitor 通过外部托管的 LDAP 服务器对用户进行身份验证或使用 Microsoft Active Directory(AD)凭据对用户进行身份验证。若要配置 LDAP 或 AD 设置,请前往“配置”->“LDAP 或 AD 设置”。 LDAP 设置 若要使用 LDAP 验证,请配置以下信息: LDAP 服务器主机名 输入你的 LDAP 服务器的主机名、IP 地

  • 我正在使用cloudera VM,我想连接到beeline,但当我离开时,它询问用户名和密码,它没有连接。谁能告诉我用户名和密码。 !连接JDBC:hive2://localhost:10000/连接到JDBC:hive2://localhost:10000/输入JDBC:hive2://localhost:10000/输入JDBC:hive2://localhost:10000/输入密码:错误: