@Bean(destroyMethod = "shutdown")
    @RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public HazelcastInstance hazelcastInstance(final CasConfigurationProperties casProperties,
                                               final HazelcastSessionProperties hazelcastSessionProperties,
                                               final SessionProperties sessionProperties,
                                               final ServerProperties serverProperties) {
        val hz = casProperties.getWebflow().getSession().getServer().getHazelcast();
        val config = HazelcastConfigurationFactory.build(hz);
        val serializerConfig = new SerializerConfig();
        serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
        config.getSerializationConfig().addSerializerConfig(serializerConfig);

        val 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 final MapConfig finalConfig) {
            val attributeConfig = new AttributeConfig();
            attributeConfig.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
            attributeConfig.setExtractorClassName(HazelcastSessionPrincipalNameExtractor.class.getName());
            finalConfig.addAttributeConfig(attributeConfig);
            val indexConfig = new IndexConfig();
            indexConfig.addAttribute(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
            finalConfig.addIndexConfig(indexConfig);
        }
        HazelcastConfigurationFactory.setConfigMap(mapConfig, hazelcastInstance.getConfig());
        return 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
support/cas-server-support-session-hazelcast/src/main/java/org/apereo/cas/config/CasHazelcastSessionAutoConfiguration.java