我如何使用“记住我”使用Spring Security和LDAP进行身份验证? [英] How do I use "Remember Me" authentication with Spring Security and LDAP?

查看:131
本文介绍了我如何使用“记住我”使用Spring Security和LDAP进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过LDAP身份验证使用Spring Security的记住我。 LDAP身份验证配置描述此处,我刚做了一些微小的改动。你能解释一下我怎么能在那个配置中添加记住我?或者,也许,你可以给我一个描述如何做的样本。
谢谢。

I want to use a Spring Security's "Remember me" with LDAP authentication. LDAP authentication configuration is described here, I've just made some tiny changes. Could you explain to me how can i add "Remember me" in that configuration? Or, may be, you can give me a sample which describes how to do it. Thank you.

推荐答案

你真的只需要给remember-me属性一个data-source-ref或者token-repository-ref和user-service-ref。我在http元素中看到了一些使用基于选民的access-decision-manager-ref的其他示例,但这似乎使use-expressions =true无效。我唯一不喜欢的是必须两次指定ldap属性。

You really just need to give the remember-me attribute a data-source-ref or a token-repository-ref and a user-service-ref. I saw some other examples that used a voter based access-decision-manager-ref in the http element, but that seemed to void the use-expressions="true." The only thing I don't like about this is having to specify the ldap properties twice.

<beans:import resource="datasource-context.xml"/>

<http use-expressions="true" >
    <intercept-url pattern="/auth/**" access="permitAll" />
    <intercept-url pattern="/admin/**" access="hasRole('MY_ROLE_ADMIN')" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
    <form-login  />
    <logout  />
    <remember-me key="_my_remember_me_key" 
        token-validity-seconds="864000" 
        data-source-ref="dataSource"
        user-service-ref="ldapUserService" />
</http>

<ldap-server id="ldapServerContext" ldif="classpath:users.ldif" root="dc=springframework,dc=org" port="33389" />

<ldap-user-service 
    id="ldapUserService" 
    server-ref="ldapServerContext" 
    user-search-base="ou=people"
    user-search-filter="(uid={0})"
    group-search-base="ou=groups"
    group-role-attribute="cn"
    group-search-filter="(member={0})"
    role-prefix="MY_ROLE_" />

<authentication-manager>
    <ldap-authentication-provider
        server-ref="ldapServerContext"
        user-search-base="ou=people"
        user-search-filter="(uid={0})"
        group-search-base="ou=groups"
        group-role-attribute="cn"
        group-search-filter="(member={0})"
        role-prefix="MY_ROLE_" />
</authentication-manager>

这篇关于我如何使用“记住我”使用Spring Security和LDAP进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆