仅为当前请求修改SecurityContext

时间:2017-06-03 05:00:12

标签: java spring session spring-security spring-session

我正在使用Spring Boot +春季会话数据rediss

我的场景是UserA已经登录并且为UserA创建了JSESSIONID,现在他发出了一个令牌,该令牌将被发送到某台机器并且有效几分钟才能代表他工作。
问题是如果一些客户意外通过Cookie和令牌然后我想优先选择 TOKEN 而不是 JSESSIONID 是否可以在春季会话
我无法使cookie会话,因为它将注销不需要的UserA
因此,我想告诉spring,使用现有会话或根据某些条件创建一个新会话,并希望优先选择 TOKEN 。并创建一个全新的会话而不会使Cookie会话失效。

1 个答案:

答案 0 :(得分:1)

阅读官方文件。

从此

@EnableRedisHttpSession 
public class Config {

        @Bean
        public LettuceConnectionFactory connectionFactory() {
                return new LettuceConnectionFactory(); 
        }
}

默认情况下已完成。

The @EnableRedisHttpSession annotation creates a Spring Bean with the name of springSessionRepositoryFilter that implements Filter. The filter is what is in charge of replacing the HttpSession implementation to be backed by Spring Session. In this instance Spring Session is backed by Redis.

We create a RedisConnectionFactory that connects Spring Session to the Redis Server. We configure the connection to connect to localhost on the default port (6379) For more information on configuring Spring Data Redis, refer to the reference documentation.

The DelegatingFilterProxy will look up a Bean by the name of springSessionRepositoryFilter and cast it to a Filter. For every request that DelegatingFilterProxy is invoked, the springSessionRepositoryFilter will be invoked.

所以,你必须做什么,它避免了Spring配置,或者想要修改这个默认行为,以某种方式创建你自己的DelegatingFilterProxy实现并在你的ServletContext过滤器链中设置它。