`

spring-mvc+spring-security+tomcat8用memcached-session-manager实现集群部署

 
阅读更多

版本:

Tomcat:8.5.6

memcached-session-manager:1.9.7

 

在tomcat的lib下需要增加以下jar:

 

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

 

 

在tomcat的conf/server.xml文件配置如下:

  <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>

 

 

在spring-securit的序列化时要用ycustomConverter="de.javakaffee.web.msm.serializer.kryo.SpringSecurityUserRegistration"

 

 

在demo工程下pom.xml需要增加

 

<dependency>
    <groupId>de.javakaffee.msm</groupId>
    <artifactId>msm-kryo-serializer</artifactId>
    <version>2.0.0</version>
</dependency>

 

demo工程下自定义的User类等需要实现序列化接口(implements Serializable)

 

demo工程下的

        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());
	}

 这几个地方也需要调整。

 

demo:https://github.com/tombigun/spring-security-demo

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics