ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

如何将Spring Security从ldap更改为ldap starttls

2019-12-02 00:29:30  阅读:273  来源: 互联网

标签:ldap spring-security spring-ldap spring


如何将Spring安全性从ldap更改为ldap starttls.

我正在使用Spring Security和LDAP在Springs中编写一个项目.我一切正常,然后管理员用starttls将其更改为ldap.有人可以告诉我如何更新我的xml文件以使我的项目再次工作.

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

    <http
        auto-config="true"
        use-expressions="true" >

        <intercept-url
            access="hasRole('ROLE_MEMBER_INQUIRY')"
            pattern="/requests/**" />

    </http>

    <authentication-manager >

        <ldap-authentication-provider
            user-search-base="ou=webusers"
            user-search-filter="(uid={0})" >

            <password-compare >

                <password-encoder ref="passwordEncoder" >
                </password-encoder>
            </password-compare>
        </ldap-authentication-provider>
    </authentication-manager>

    <beans:bean
        id="passwordEncoder"
        class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" >
    </beans:bean>

    <beans:bean
        id="contextSource"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource" >

        <beans:constructor-arg value="ldap://10.52.208.228:389/dc=xxxxx,dc=dev" />

        <beans:property
            name="userDn"
            value="cn=Manager,dc=xxxxx,dc=dev" />

        <beans:property
            name="password"
            value="secret" />
    </beans:bean>

    <beans:bean
        id="ldapAuthProvider"
        class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" >

        <beans:constructor-arg >

            <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator" >

                <beans:constructor-arg ref="contextSource" />

                <beans:property name="userDnPatterns" >

                    <beans:list >

                        <beans:value >

uid={0},ou=webusers

                        </beans:value>
                    </beans:list>
                </beans:property>
            </beans:bean>
        </beans:constructor-arg>

        <beans:constructor-arg >

            <beans:bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator" >

                <beans:constructor-arg ref="contextSource" />

                <beans:constructor-arg value="ou=groups" />

                <beans:property
                    name="groupRoleAttribute"
                    value="ou" />
            </beans:bean>
        </beans:constructor-arg>
    </beans:bean>

    <ldap-server url="ldap://10.52.208.228:389/dc=xxxxx,dc=dev" />

    <beans:bean
        id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >

        <beans:property
            name="location"
            value="classpath:jdbc.properties" />
    </beans:bean>

    <beans:bean
        id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource" >

        <beans:property
            name="driverClassName"
            value="${database.driver}" />

        <beans:property
            name="url"
            value="${database.url}" />

        <beans:property
            name="username"
            value="${database.user}" />

        <beans:property
            name="password"
            value="${database.password}" />

        <beans:property
            name="initialSize"
            value="5" />

        <beans:property
            name="maxActive"
            value="10" />
    </beans:bean>

</beans:beans>

解决方法:

您需要在配置中向ContextSource提供DirContextAuthenticationStrategy实现.

看到:
http://static.springsource.org/spring-ldap/site/reference/html/configuration.html

标签:ldap,spring-security,spring-ldap,spring
来源: https://codeday.me/bug/20191201/2084620.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有