使用存储在redis

时间:2016-04-13 20:31:55

标签: spring session spring-security spring-boot spring-session

我需要在两个spring应用程序之间共享会话。其中一个是在3.2版弹簧和弹簧安全3.1.6中编写的非常大的应用程序。第二个是基于弹簧靴1.3.3。会话应该通过redis服务器共享。用户只能直接与旧应用程序通信。只有旧的应用程序才能访问新的。

目标是访问用户名,并能够根据旧应用程序存储在redis中的信息验证新应用中的用户权限。

我试图通过春季会议实现这一目标。我设法使用非常简单的配置将会话数据存储在旧应用程序中的redis中。在pom.xml中,我将依赖项添加到spring-session-data-redis

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
    <version>1.1.1.RELEASE</version>
    <type>pom</type>
</dependency>

在spring配置中我添加了两个bean:

  • org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration
  • org.springframework.data.redis.connection.jedis.JedisConnectionFactory

在web.xml中还有一个过滤器:

<filter>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

但是在配置新应用程序以通过向配置类添加两个注释来使用spring会话之后:

  • @EnableWebSecurity
  • @EnableRedisHttpSession

添加HeaderHttpSessionStrategy bean,当我尝试使用x-auth-token标头中的活动会话ID访问新应用程序时,我得到异常:

 java.io.InvalidClassException: org.springframework.security.core.context.SecurityContextImpl; local class incompatible: stream classdesc serialVersionUID = 310, local class serialVersionUID = 400

我不需要旧应用会话中的所有信息,只需要用户名和用户角色来验证某些访问凭据。我试图谷歌关于自定义会话序列化,并尝试仅序列化部分会话,并以这种方式独立于spring-security版本。不幸的是,我的想法失败了。我还尝试在新应用程序中配置旧的spring-security版本,但它也失败了......

有没有简单的方法来实现我的目标?

0 个答案:

没有答案