2017-06-03 50 views
0

我使用Spring引導+春季會議數據rediss

我的情況是用戶A已經登錄和用戶A創建JSESSIONID,現在他發出將被髮送到某些機器和令牌代表他工作幾分鐘即可生效。
問題是,如果不小心一些客戶端通過兩個Cookie和令牌,然後我要優先考慮TOKEN而不是JSESSIONID是否有可能在春季會議
我無法使Cookie會話無效,因爲它會註銷不需要的UserA。

所以,我想告訴春天使用現有的會議或創建一個新的基於一些條件,並希望給予優先TOKEN。並創建一個全新的會話而不會使Cookie會話失效。要修改的SecurityContext只對當前請求

回答

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篩選器鏈中。

+0

我能夠通過提供自己的HttpSessionSecurityContextRepository實現,然後設置http.securityContext()。securityContextRepository(new CustomHttpSessionSecurityContextRepository())來實現此目的。 因此,我正在實現我自己的SaveContextOnUpdateOrErrorResponseWrapper,其中我沒有保存上下文,因此它在會話中沒有更改。 –