Java Code Examples for io.undertow.servlet.api.DeploymentInfo#getInitParameters()

The following examples show how to use io.undertow.servlet.api.DeploymentInfo#getInitParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletSamlAuthMech.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void addTokenStoreUpdaters(DeploymentInfo deploymentInfo) {
    deploymentInfo.addSessionListener(new IdMapperUpdaterSessionListener(idMapper));    // This takes care of HTTP sessions manipulated locally
    SessionIdMapperUpdater updater = SessionIdMapperUpdater.EXTERNAL;

    try {
        Map<String, String> initParameters = deploymentInfo.getInitParameters();
        String idMapperSessionUpdaterClasses = initParameters == null
          ? null
          : initParameters.get("keycloak.sessionIdMapperUpdater.classes");
        if (idMapperSessionUpdaterClasses == null) {
            return;
        }

        for (String clazz : idMapperSessionUpdaterClasses.split("\\s*,\\s*")) {
            if (! clazz.isEmpty()) {
                updater = invokeAddTokenStoreUpdaterMethod(clazz, deploymentInfo, updater);
            }
        }
    } finally {
        setIdMapperUpdater(updater);
    }
}
 
Example 2
Source File: InfinispanSessionCacheIdMapperUpdater.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static SessionIdMapperUpdater addTokenStoreUpdaters(DeploymentInfo deploymentInfo, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) {
    Map<String, String> initParameters = deploymentInfo.getInitParameters();
    String containerName = initParameters == null ? null : initParameters.get(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME);
    String cacheName = initParameters == null ? null : initParameters.get(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME);

    if (containerName == null || cacheName == null) {
        LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", deploymentInfo.getDeploymentName());

        return previousIdMapperUpdater;
    }

    String cacheContainerLookup = DEFAULT_CACHE_CONTAINER_JNDI_NAME + "/" + containerName;
    String deploymentSessionCacheName = deploymentInfo.getDeploymentName();

    try {
        EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) new InitialContext().lookup(cacheContainerLookup);

        Configuration ssoCacheConfiguration = cacheManager.getCacheConfiguration(cacheName);
        if (ssoCacheConfiguration == null) {
            Configuration cacheConfiguration = cacheManager.getCacheConfiguration(deploymentSessionCacheName);
            if (cacheConfiguration == null) {
                LOG.debugv("Using default configuration for SSO cache {0}.{1}.", containerName, cacheName);
                ssoCacheConfiguration = cacheManager.getDefaultCacheConfiguration();
            } else {
                LOG.debugv("Using distributed HTTP session cache configuration for SSO cache {0}.{1}, configuration taken from cache {2}",
                  containerName, cacheName, deploymentSessionCacheName);
                ssoCacheConfiguration = cacheConfiguration;
                cacheManager.defineConfiguration(cacheName, ssoCacheConfiguration);
            }
        } else {
            LOG.debugv("Using custom configuration of SSO cache {0}.{1}.", containerName, cacheName);
        }

        CacheMode ssoCacheMode = ssoCacheConfiguration.clustering().cacheMode();
        if (ssoCacheMode != CacheMode.REPL_ASYNC && ssoCacheMode != CacheMode.REPL_SYNC) {
            LOG.warnv("SSO cache mode is {0}, it is recommended to use replicated mode instead.", ssoCacheConfiguration.clustering().cacheModeString());
        }

        Cache<String, String[]> ssoCache = cacheManager.getCache(cacheName, true);
        final SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper);
        ssoCache.addListener(listener);

        addSsoCacheCrossDcListener(ssoCache, listener);

        LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName);

        LOG.debugv("Adding session listener for SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName);
        SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater);
        deploymentInfo.addSessionListener(updater);

        return updater;
    } catch (NamingException ex) {
        LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup);
        return previousIdMapperUpdater;
    }
}