LDAP Spring 安全登录处理 URL 302 错误

Posted

技术标签:

【中文标题】LDAP Spring 安全登录处理 URL 302 错误【英文标题】:LDAP Spring security login-processing-url 302 error 【发布时间】:2014-12-25 09:35:18 【问题描述】:

我有一个连接到 LDAP 服务器的 Web 应用程序,一切正常,直到现在在 LDAP 中创建一个新分支并处理 url 我得到“错误 302 临时移动”。我从来没有这样过,我在 .properties 中有 LDAP 服务器的配置。

奇怪的是,我在配置方面工作得很好,但是现在你创建了一个新的分支进行测试,我得到了这个错误。

如果我能帮上忙的话,这就是导致这种情况发生的原因。

这些是我的文件。

有了这个配置就可以了

#Properties LDAP Server
ldap.context.initialContextFactory  = com.sun.jndi.ldap.LdapCtxFactory
ldap.context.providerUrl            = ldap://192.168.0.31:389/dc=store,dc=web,dc=ap
ldap.context.securityAuthentication = simple
ldap.context.securityPrincipal      = cn=admin,dc=web,dc=ap
ldap.context.securityCredentials    = adm5569

使用此配置,我会发送 HTTP 错误 302 已临时移动

#Properties LDAP Server
ldap.context.initialContextFactory  = com.sun.jndi.ldap.LdapCtxFactory
ldap.context.providerUrl            = ldap://192.168.0.31:389/dc=store2,dc=web,dc=ap
ldap.context.securityAuthentication = simple
ldap.context.securityPrincipal      = cn=admin,dc=web,dc=ap
ldap.context.securityCredentials    = adm5569

这是我的 security.xml 文件

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/security 
                    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <http pattern="/webapp/ViewChangePassword" security="none" /> 
    <http pattern="/webapp/LogonForm" security="none" />


    <http auto-config="true">
        <intercept-url pattern="/webapp/Home" access="ROLE_USER" />
        <intercept-url pattern="/webapp/ListStore" access="IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER" />
        <intercept-url pattern="/webapp/CheckStoreJson" access="IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER" />
        <intercept-url pattern="/webapp/ViewChangePassword" access="IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER" />
        <intercept-url pattern="/webapp/ChangePassword" access="IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER" />
        <intercept-url pattern="/webapp/**" access="ROLE_USER" />

    <form-login login-page="/webapp/LogonForm" default-target-url="/webapp/Home" authentication-failure-url="/webapp/LogonForm?code=1" login-processing-url="/webapp/LogOn" />
        <logout logout-url="/webapp/LogOut" logout-success-url="/webapp/LogonForm?code=2" /> 
    </http>

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

    <ldap-server id="ldapServer" url="ldap://$ldap.server.ip:$ldap.server.port/$ldap.server.root"/>


    <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator" id="ldapBindAuthenticator" >
        <beans:constructor-arg ref="ldapServer"/>
        <beans:property name="userSearch" ref="userSearch"/>
    </beans:bean>


    <beans:bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch" >
        <beans:constructor-arg index="0" value="ou=usuarios"/>
        <beans:constructor-arg index="1" value="(uid=0)"/>
        <beans:constructor-arg index="2" ref="ldapServer" />
    </beans:bean>


    <beans:bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator" id="ldapAuthoritiesPopulator" >
        <beans:constructor-arg ref="ldapServer"/>
        <beans:constructor-arg value="$ldap.springrole.rdn"/>
        <beans:property name="groupRoleAttribute" value="$ldap.springrole.attribute"/>
        <beans:property name="rolePrefix" value="$ldap.springrole.prefix"/>
        <beans:property name="groupSearchFilter" value="(objectClass=organizationalRole)"/>
        <beans:property name="searchSubtree" value="true" />
    </beans:bean>


    <beans:bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" >
        <beans:constructor-arg ref="ldapBindAuthenticator"/>
        <beans:constructor-arg ref="ldapAuthoritiesPopulator"/>
        <beans:property name="userDetailsContextMapper" ref="ldapUserDetailsContextMapper"/>
    </beans:bean>


    <beans:bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <beans:constructor-arg ref="ldapServer"/>
    </beans:bean>

    <beans:bean class="cl.bbr.security.UserLdapMapper" id="ldapUserDetailsContextMapper">
        <beans:property name="template"         ref="ldapTemplate"/>
    </beans:bean>

</beans:beans>

编辑 (1) 29-10-2014

302 已暂时移动错误出现在调试控制台谷歌浏览器中,尝试通过登录名登录,将我重定向到登录错误页面和调试控制台谷歌我认为处理安全性身份验证的 URL 被暂时移动。

请帮忙。

【问题讨论】:

“我得到”错误 302 临时移动“是什么意思?你在哪里看到它?是否有与之相关的堆栈跟踪或调试日志输出?你什么时候得到它 - 即什么请求您在制作吗?是否有您被重定向到的 URL?您是说身份验证失败还是其他原因?请编辑您的问题以包含此信息。我猜您的身份验证只是失败了,因此您被重定向到登录错误网址。 启用调试日志并查看实际问题所在的服务器日志内容。仅通过查看浏览器控制台,您将无法理解服务器错误。 302 响应代码只是一个重定向,因此几乎可以肯定,由于 LDAP 更改,您的身份验证失败,并且您只是被发送回登录页面。 【参考方案1】:

我找到了解决方案,我必须授予分支中的用户权限,以读取、修改和删除我要去的分支

【讨论】:

以上是关于LDAP Spring 安全登录处理 URL 302 错误的主要内容,如果未能解决你的问题,请参考以下文章

Ldap 用户授权失败 - 未处理的 Spring 身份验证“访问被拒绝”

Spring 安全性、ssl ldap 和无证书

Spring 安全 ldap 连接管理

如何在 Spring Security 中更改登录 URL

具有Spring安全性的LDAP身份验证

使用基于 memberOf 属性的 ldap 进行 Spring 安全认证