Search in sources :

Example 1 with HazelcastSessionSerializer

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;
}
Also used : lombok.val(lombok.val) SerializerConfig(com.hazelcast.config.SerializerConfig) IndexConfig(com.hazelcast.config.IndexConfig) Duration(java.time.Duration) MapConfig(com.hazelcast.config.MapConfig) HazelcastSessionSerializer(org.springframework.session.hazelcast.HazelcastSessionSerializer) AttributeConfig(com.hazelcast.config.AttributeConfig) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Aggregations

AttributeConfig (com.hazelcast.config.AttributeConfig)1 IndexConfig (com.hazelcast.config.IndexConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 Duration (java.time.Duration)1 lombok.val (lombok.val)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 HazelcastSessionSerializer (org.springframework.session.hazelcast.HazelcastSessionSerializer)1