【问题标题】:spring security remember me authenticationspring security 记住我的身份验证
【发布时间】:2013-04-03 12:01:47
【问题描述】:

我有在客户端保存 cookie 的机制。但是当我尝试使用 spring security 实现 remember-me 时,我遇到了这个教程:

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html#remember-me-persistent-token

但是这里的一切都是抽象的,没有给出例子.. 有人可以告诉我如何在需要实现持久性 cookie 的应用程序中使用本教程中提到的接口...请告诉我需要在我的 security.xml 文件中定义什么?

我正在根据 RESTful 服务对我的用户进行身份验证..

【问题讨论】:

    标签: java authentication spring-security remember-me


    【解决方案1】:

    官方文档不是抽象的。用 Spring Security 开启 remember-me 很简单(我想 Spring Security 已经配置好了,用户存储在 DB 中):

    1 在conf中开启remeber-me:

    <http>
        ...
        <remember-me data-source-ref="yourDataSource"/>
    </http>
    

    2 在数据库中创建对应的表:

    create table persistent_logins (username varchar(64) not null, series varchar(64) primary key, token varchar(64) not null, last_used timestamp not null)
    

    3 在您的登录表单中添加相应的复选框:

    <input id="rememeberMe" type="checkbox" name="_spring_security_remember_me">
    

    在 REST 的情况下,您需要根据您的身份验证场景调整第三步。

    【讨论】:

    • 我是 Spring Security 的新手.. 所以我不知道如何配置它.. 意味着我应该在配置中包含所有内容,就像你说我应该使用 .. 但是我应该在其中包含什么.. 以及 security.xml 中的所有内容
    • 最好改正题主的问题。从这一点开始阅读文档:static.springsource.org/spring-security/site/docs/3.0.x/…。我不能说更多,因为一切都取决于你的项目中有什么。如果您看起来不清楚,那么只需发布另一个更精确的问题。祝你好运。
    • 感谢您的建议。我想要做的是实现这个链接中提到的算法:jaspan.com/improved_persistent_login_cookie_best_practice 为此我有一个加密的密码和支持它的数据库模式......现在我想配置自动登录功能。以及使用 Spring Security 对 REST 服务的身份验证功能。。正如我所阅读的各种文章中提到的,Spring Security 具有这两个功能的接口,我们只需要实现它们
    • 在 Spring Security 中,您可以自定义散列算法和数据库模式。所以也许你可以重用他的记住我的实现。
    猜你喜欢
    • 2014-06-09
    • 2013-03-29
    • 1970-01-01
    • 2012-12-14
    • 2011-01-22
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    相关资源
    最近更新 更多