【问题标题】:create-session stateless usage when scalling horizontally水平缩放时创建会话无状态使用
【发布时间】:2017-02-11 23:12:27
【问题描述】:

我想创建一个 RESTful API,我需要它是无状态的,因为我可能会启动 N 次应用程序。

我还添加了带有 jdbc 实现的 OAuth2,用户应该登录一次,所有查询都应该是无状态的。

在我的 Spring Boot 应用程序中添加以下内容会导致它现在尝试进行两次身份验证的登录崩溃。

    http
        .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

在服务器端我有这些日志:

AuditEvent [timestamp=Tue Oct 04 05:04:52 ICT 2016, principal=dka, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null}]
AuditEvent [timestamp=Tue Oct 04 05:04:52 ICT 2016, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null, type=org.springframework.security.access.AccessDeniedException, message=Access is denied}]
  • 这是否也涉及我的 OAuth 身份验证或仅涉及 WebSecurity 部分?
  • 有没有一种好的方法来配置我的会话以扩展它并保持服务无状态?

【问题讨论】:

    标签: spring rest spring-security spring-boot stateless


    【解决方案1】:

    看起来您的第二个请求不包含任何授权标头,或者 Spring Security 没有对其进行评估。

    根据OAuth Bearer Type Documentation,您的客户端需要提交标头:Authorization: Bearer YOUR_TOKEN,而令牌是您的访问令牌响应之一(请参阅Example Access Token Response

    如果这不能解决您的问题,请考虑添加一些配置日志和代码。

    【讨论】:

      猜你喜欢
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多