首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring boot + spring security + hazelcast会话复制无法正常工作

Spring boot + spring security + hazelcast会话复制无法正常工作
EN

Stack Overflow用户
提问于 2017-08-22 21:03:31
回答 1查看 2.7K关注 0票数 1

我正在尝试将spring安全引入angularjs app。后端使用spring框架。对于后端安全性,我使用了这里解释的方法。

https://samerabdelkafi.wordpress.com/2016/01/25/secure-angularjs-application-with-spring-security/

这在单个应用程序实例中工作得很好。

问题是应用程序是集群的,因此必须复制会话。

我尝试使用hazelcast进行会话复制,如下所述:

https://dzone.com/articles/spring-boot-hazelcast-for-session-replication

当我介绍hazelcast时,第一次身份验证是成功的。之后,第一个请求也是成功的。但在那之后似乎

org.springframework.security.web.context.HttpSessionSecurityContextRepository找不到会话...

正如我所说的,在我为sesion复制配置了com.hazelcast.web.WebFilter之后,这种情况开始发生,如下所示:

代码语言:javascript
复制
  @Bean
public WebFilter webFilter(HazelcastInstance hazelcastInstance) {

    Properties properties = new Properties();
    properties.put("instance-name", hazelcastInstance.getName());
    properties.put("sticky-session", "true");

    return new WebFilter(properties);
}

相关日志如下:

2017-08-22 15:17:31,593 : DEBUGHttpSessionSecurityContextRepository当前不存在HttpSession

2017-08-22 15:17:31,593 : DEBUGHttpSessionSecurityContextRepository HttpSession中没有可用的SecurityContext : null。将创建一个新的。

我确信客户端在成功登录后会发送相同的cookie

我想不出其中的原因。任何指导都是值得感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-27 19:29:54

我可以通过使用spring session来实现这一点。

https://docs.spring.io/spring-session/docs/current/reference/html5/guides/java-hazelcast.html

会话在轮询负载均衡器后的两个实例之间成功复制。非常感谢spring session开发人员……

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45818469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档