2017-01-06 5 views
5

私のアプリケーションでは、Spring SecurityとSpring Session(v1.3.1)を使用しています。RedisセッションリポジトリでSpringSessionBackedSessionRegistryを使用する

私はセッションレジストリとしてSpringSessionBackedSessionRegistryを、セッションレポジトリとしてはRedisを使用したいと思います。次のように

SpringSessionBackedSessionRegistryのコンストラクタは次のとおりです。

SpringSessionBackedSessionRegistry(FindByIndexNameSessionRepository<ExpiringSession> sessionRepository) 

Redisのリポジトリ、RedisOperationsSessionRepository道具:

FindByIndexNameSessionRepository<org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession> 

どのように、そして、私はRedisOperationsSessionRepositoryのインスタンスを与えられSpringSessionBackedSessionRegistryのインスタンスを構築することができますか?

なぜSpringSessionBackedSessionRegistryないのコンストラクタです:

SpringSessionBackedSessionRegistry(FindByIndexNameSessionRepository<? extends ExpiringSession> sessionRepository) 

答えて

3

あなたはSpringSessionBackedSessionRegistryは、コンストラクタの引数としてFindByIndexNameSessionRepository<? extends ExpiringSession> sessionRepositoryとるべき正しいです。

私は問題を解決するためにPRを開いていますが、それはhereと追跡できます。

を設定するには、構成内でraw FindByIndexNameSessionRepositoryを使用します。ここに例があります:

@Configuration 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private FindByIndexNameSessionRepository sessionRepository; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
       .anyRequest().authenticated() 
       .and() 
      .formLogin() 
       .and() 
      .sessionManagement() 
       .maximumSessions(1) 
       .sessionRegistry(sessionRegistry()); 
    } 

    @Bean 
    @SuppressWarnings("unchecked") 
    public SpringSessionBackedSessionRegistry sessionRegistry() { 
     return new SpringSessionBackedSessionRegistry(this.sessionRepository); 
    } 

} 
関連する問題