use of org.springframework.session.hazelcast.HazelcastSessionSerializer in project cas by apereo.
the class HazelcastSessionConfiguration method hazelcastInstance.
/**
* Hazelcast instance that is used by the spring session
* repository to broadcast session events. The name
* of this bean must be left untouched.
*
* @param casProperties the cas properties
* @param hazelcastSessionProperties the hazelcast session properties
* @param sessionProperties the session properties
* @param serverProperties the server properties
* @return the hazelcast instance
*/
@Bean(destroyMethod = "shutdown")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public HazelcastInstance hazelcastInstance(final CasConfigurationProperties casProperties, final HazelcastSessionProperties hazelcastSessionProperties, final SessionProperties sessionProperties, final ServerProperties serverProperties) {
val hz = casProperties.getWebflow().getSession().getHazelcast();
val config = HazelcastConfigurationFactory.build(hz);
val serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
config.getSerializationConfig().addSerializerConfig(serializerConfig);
val duration = (Duration) ObjectUtils.defaultIfNull(sessionProperties.getTimeout(), serverProperties.getServlet().getSession().getTimeout());
val hazelcastInstance = HazelcastInstanceFactory.getOrCreateHazelcastInstance(config);
val mapConfig = HazelcastConfigurationFactory.buildMapConfig(hz, hazelcastSessionProperties.getMapName(), duration.toSeconds());
if (mapConfig instanceof MapConfig) {
val finalConfig = (MapConfig) mapConfig;
val attributeConfig = new AttributeConfig();
attributeConfig.setName(Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
attributeConfig.setExtractorClassName(HazelcastSessionPrincipalNameExtractor.class.getName());
finalConfig.addAttributeConfig(attributeConfig);
val indexConfig = new IndexConfig();
indexConfig.addAttribute(Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
finalConfig.addIndexConfig(indexConfig);
}
HazelcastConfigurationFactory.setConfigMap(mapConfig, hazelcastInstance.getConfig());
return hazelcastInstance;
}
Aggregations