Search in sources :

Example 1 with SessionIdMapperUpdater

use of org.keycloak.adapters.spi.SessionIdMapperUpdater in project keycloak by keycloak.

the class KeycloakConfigurationServletListener method invokeAddTokenStoreUpdaterMethod.

private SessionIdMapperUpdater invokeAddTokenStoreUpdaterMethod(String idMapperSessionUpdaterClass, ServletContext servletContext, SessionIdMapperUpdater previousIdMapperUpdater) {
    try {
        Class<?> clazz = servletContext.getClassLoader().loadClass(idMapperSessionUpdaterClass);
        Method addTokenStoreUpdatersMethod = clazz.getMethod("addTokenStoreUpdaters", ServletContext.class, SessionIdMapper.class, SessionIdMapperUpdater.class);
        if (!Modifier.isStatic(addTokenStoreUpdatersMethod.getModifiers()) || !Modifier.isPublic(addTokenStoreUpdatersMethod.getModifiers()) || !SessionIdMapperUpdater.class.isAssignableFrom(addTokenStoreUpdatersMethod.getReturnType())) {
            log.errorv("addTokenStoreUpdaters method in class {0} has to be public static. Ignoring class.", idMapperSessionUpdaterClass);
            return previousIdMapperUpdater;
        }
        log.debugv("Initializing sessionIdMapperUpdater class {0}", idMapperSessionUpdaterClass);
        return (SessionIdMapperUpdater) addTokenStoreUpdatersMethod.invoke(null, servletContext, idMapper, previousIdMapperUpdater);
    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
        log.warnv(ex, "Cannot use sessionIdMapperUpdater class {0}", idMapperSessionUpdaterClass);
        return previousIdMapperUpdater;
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        log.warnv(ex, "Cannot use {0}.addTokenStoreUpdaters(DeploymentInfo, SessionIdMapper) method", idMapperSessionUpdaterClass);
        return previousIdMapperUpdater;
    }
}
Also used : SessionIdMapperUpdater(org.keycloak.adapters.spi.SessionIdMapperUpdater) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SessionIdMapperUpdater

use of org.keycloak.adapters.spi.SessionIdMapperUpdater in project keycloak by keycloak.

the class KeycloakConfigurationServletListener method addTokenStoreUpdaters.

public void addTokenStoreUpdaters(ServletContext servletContext) {
    SessionIdMapperUpdater updater = this.idMapperUpdater;
    try {
        String idMapperSessionUpdaterClasses = servletContext.getInitParameter("keycloak.sessionIdMapperUpdater.classes");
        if (idMapperSessionUpdaterClasses == null) {
            return;
        }
        // This takes care of HTTP sessions manipulated locally
        servletContext.addListener(new IdMapperUpdaterSessionListener(idMapper));
        updater = SessionIdMapperUpdater.DIRECT;
        for (String clazz : idMapperSessionUpdaterClasses.split("\\s*,\\s*")) {
            if (!clazz.isEmpty()) {
                if (Objects.equals("org.keycloak.adapters.saml.wildfly.infinispan.InfinispanSessionCacheIdMapperUpdater", clazz)) {
                    // exchange wildfly/undertow for elytron one
                    clazz = InfinispanSessionCacheIdMapperUpdater.class.getName();
                }
                updater = invokeAddTokenStoreUpdaterMethod(clazz, servletContext, updater);
                if (updater instanceof AutoCloseable) {
                    toClose.add((AutoCloseable) updater);
                }
            }
        }
    } finally {
        setIdMapperUpdater(updater);
    }
}
Also used : SessionIdMapperUpdater(org.keycloak.adapters.spi.SessionIdMapperUpdater) InfinispanSessionCacheIdMapperUpdater(org.keycloak.adapters.saml.elytron.infinispan.InfinispanSessionCacheIdMapperUpdater)

Example 3 with SessionIdMapperUpdater

use of org.keycloak.adapters.spi.SessionIdMapperUpdater in project keycloak by keycloak.

the class KeycloakHttpServerAuthenticationMechanism method getSessionIdMapperUpdater.

private SessionIdMapperUpdater getSessionIdMapperUpdater(HttpServerRequest request) {
    HttpScope scope = request.getScope(Scope.APPLICATION);
    SessionIdMapperUpdater res = scope == null ? null : (SessionIdMapperUpdater) scope.getAttachment(KeycloakConfigurationServletListener.ADAPTER_SESSION_ID_MAPPER_UPDATER_ATTRIBUTE_ELYTRON);
    return res == null ? this.idMapperUpdater : res;
}
Also used : HttpScope(org.wildfly.security.http.HttpScope) SessionIdMapperUpdater(org.keycloak.adapters.spi.SessionIdMapperUpdater)

Aggregations

SessionIdMapperUpdater (org.keycloak.adapters.spi.SessionIdMapperUpdater)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InfinispanSessionCacheIdMapperUpdater (org.keycloak.adapters.saml.elytron.infinispan.InfinispanSessionCacheIdMapperUpdater)1 HttpScope (org.wildfly.security.http.HttpScope)1