【问题标题】:Spring Session Spring Security Rest API and RedisSpring Session Spring Security Rest API 和 Redis
【发布时间】:2016-07-08 04:20:02
【问题描述】:

我是使用 Spring Session 和 Spring Security 的新手。希望能得到帮助。我想在 REST API 上使用 Spring Session 和 Spring Security,并使用 Redis 来存储会话信息。我遵循了来自http://docs.spring.io/spring-session/docs/current/reference/html5/guides/rest.html 的示例,但我使用 xml 而不是 Java 类,并且我使用的是 Spring 3.2.4。

当我使用带有用户名:密码的curl时没有问题,x-auth-token保存在Redis中,并且在标题中获得200 ok。 但是,当我使用没有用户名和密码的 curl 时遇到问题。获取401未授权但header中返回x-auth-token,也保存在redis中
< HTTP/1.1 401 Unauthorized * Server Apache-Coyote/1.1 is not blacklisted < Server: Apache-Coyote/1.1 < x-auth-token: 71554566-17d3-44ca-94b8-009d090c61a1 < Content-Type: text/html;charset=utf-8 < Content-Language: en < Content-Length: 1018 < Date: Mon, 21 Mar 2016 14:40:18 GMT

【问题讨论】:

    标签: spring spring-session


    【解决方案1】:

    我猜这是因为之前的请求被保存了。您可以使用NullRequestCache 解决此问题。在 XML 中,您可以利用 &lt;request-cache&gt;。配置类似于:

    <http ...>
    
        <request-cache ref="requestCache"/>
    </http>
    
    <b:bean id="requestCache" class="org.springframework.security.web.savedrequest.NullRequestCache"/>
    

    【讨论】:

    • 谢谢,它有效。这个问题已经困扰我好几天了。
    猜你喜欢
    • 2015-06-11
    • 2014-08-31
    • 2016-03-03
    • 2015-09-07
    • 2015-09-01
    • 2018-02-09
    • 2016-11-07
    • 2015-04-19
    • 2019-10-15
    相关资源
    最近更新 更多