Version:
Tomcat:8.5.6
memcached-session-manager:1.9.7
The following jars need to be added under the lib of tomcat:
memcached-session-manager-1.9.7.jar
memcached-session-manager-tc8-1.9.7.jar
spymemcached-2.12.1.jar
msm-kryo-serializer-2.0.0.jar
kryo-serializers-0.11.jar
kryo-1.04.jar
minlog-1.2.jar
reflectasm-1.07.jar
asm-4.0.jar
The configuration in tomcat's conf/server.xml file is as follows:
<Context path="/" docBase="/opt/demo" debug="0" privileged="true" reloadable="true" > <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.1.20:12001" sticky="false" sessionBackupAsync="false" lockingMode="auto" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" customConverter="de.javakaffee.web.msm.serializer.kryo.SpringSecurityUserRegistration" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" /> </Context>
Use ycustomConverter="de.javakaffee.web.msm.serializer.kryo.SpringSecurityUserRegistration" when serializing spring-securit
pom.xml needs to be added under the demo project
<dependency> <groupId>de.javakaffee.msm</groupId> <artifactId>msm-kryo-serializer</artifactId> <version>2.0.0</version> </dependency>
The custom User class under the demo project needs to implement the serialization interface (implements Serializable)
under the demo project
LoginUser userDetails = new LoginUser(user.getUserName(), user.getUserPassword().toLowerCase(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, obtainGrantedAuthorities(roles));
private Set<GrantedAuthority> obtainGrantedAuthorities(List<String> roleList) { Set<GrantedAuthority> authSet = new HashSet<>(); if (roleList != null) { for (int i = 0; i < roleList.size(); i++) { String roleName = roleList.get(i); authSet.add(new ComparableGrantedAuthority(roleName)); } } return authSet; }
@Override public int compareTo(ComparableGrantedAuthority o) { return getAuthority().compareTo(o.getAuthority()); }
These areas also need to be adjusted.
demo:https://github.com/tombigun/spring-security-demo