Search in sources :

Example 1 with Batch

use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.

the class DistributableSingleSignOnManager method createSingleSignOn.

@Override
public SingleSignOn createSingleSignOn(Account account, String mechanism) {
    String id = this.manager.createIdentifier();
    Batcher<Batch> batcher = this.manager.getBatcher();
    // Batch will be closed when SSO is closed
    @SuppressWarnings("resource") Batch batch = batcher.createBatch();
    try {
        AuthenticatedSession session = new AuthenticatedSession(account, mechanism);
        SSO<AuthenticatedSession, String, String, Void> sso = this.manager.createSSO(id, session);
        if (log.isTraceEnabled()) {
            log.tracef("Creating SSO ID %s for Principal %s and Roles %s", id, account.getPrincipal().getName(), account.getRoles().toString());
        }
        return new DistributableSingleSignOn(sso, this.registry, batcher, batcher.suspendBatch());
    } catch (RuntimeException | Error e) {
        batch.discard();
        batch.close();
        throw e;
    }
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Batch(org.wildfly.clustering.ee.Batch)

Example 2 with Batch

use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.

the class SSOManagerBuilder method start.

@Override
public void start(StartContext context) throws StartException {
    SSOManagerFactory<A, D, S, Batch> factory = this.factory.getValue();
    Module module = Module.forClass(this.getClass());
    this.context = new SimpleMarshallingContextFactory().createMarshallingContext(new SimpleMarshallingConfigurationRepository(MarshallingVersion.class, MarshallingVersion.CURRENT, module), null);
    this.manager = factory.createSSOManager(this);
    this.manager.start();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SimpleMarshallingConfigurationRepository(org.wildfly.clustering.marshalling.jboss.SimpleMarshallingConfigurationRepository) SimpleMarshallingContextFactory(org.wildfly.clustering.marshalling.jboss.SimpleMarshallingContextFactory) Module(org.jboss.modules.Module)

Example 3 with Batch

use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.

the class SessionListenerBuilder method sessionIdChanged.

@Override
public void sessionIdChanged(Session session, String oldSessionId) {
    SSOManager<AuthenticatedSession, String, String, Void, Batch> manager = this.manager.getValue();
    try (Batch batch = manager.getBatcher().createBatch()) {
        Sessions<String, String> sessions = manager.findSessionsContaining(oldSessionId);
        if (sessions != null) {
            String deployment = sessions.getDeployments().stream().filter(key -> sessions.getSession(key) != null).findFirst().get();
            sessions.removeSession(deployment);
            sessions.addSession(deployment, session.getId());
        }
    }
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Batch(org.wildfly.clustering.ee.Batch)

Example 4 with Batch

use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.

the class DistributableSession method changeSessionId.

@Override
public String changeSessionId(HttpServerExchange exchange, SessionConfig config) {
    Session<LocalSessionContext> oldSession = this.entry.getKey();
    validate(oldSession);
    SessionManager<LocalSessionContext, Batch> manager = this.manager.getSessionManager();
    String id = manager.createIdentifier();
    try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
        Session<LocalSessionContext> newSession = manager.createSession(id);
        for (String name : oldSession.getAttributes().getAttributeNames()) {
            newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name));
        }
        newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval());
        newSession.getMetaData().setLastAccessedTime(oldSession.getMetaData().getLastAccessedTime());
        newSession.getLocalContext().setAuthenticatedSession(oldSession.getLocalContext().getAuthenticatedSession());
        config.setSessionId(exchange, id);
        this.entry = new SimpleImmutableEntry<>(newSession, config);
        oldSession.invalidate();
    }
    // Invoke listeners outside of the context of the batch associated with this session
    this.manager.getSessionListeners().sessionIdChanged(this, oldSession.getId());
    return id;
}
Also used : Batch(org.wildfly.clustering.ee.Batch) BatchContext(org.wildfly.clustering.ee.BatchContext)

Example 5 with Batch

use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.

the class DistributableSessionManager method createSession.

@Override
public io.undertow.server.session.Session createSession(HttpServerExchange exchange, SessionConfig config) {
    if (config == null) {
        throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
    }
    String requestedId = config.findSessionId(exchange);
    String id = (requestedId == null) ? this.manager.createIdentifier() : requestedId;
    Runnable closeTask = this.getSessionCloseTask();
    boolean close = true;
    try {
        Batcher<Batch> batcher = this.manager.getBatcher();
        // Batch will be closed by Session.close();
        Batch batch = batcher.createBatch();
        try {
            Session<LocalSessionContext> session = this.manager.createSession(id);
            if (session == null) {
                throw UndertowClusteringLogger.ROOT_LOGGER.sessionAlreadyExists(id);
            }
            if (requestedId == null) {
                config.setSessionId(exchange, id);
            }
            io.undertow.server.session.Session result = new DistributableSession(this, session, config, batcher.suspendBatch(), closeTask);
            this.listeners.sessionCreated(result, exchange);
            if (this.statistics != null) {
                this.statistics.record(result);
            }
            close = false;
            return result;
        } catch (RuntimeException | Error e) {
            batch.discard();
            throw e;
        } finally {
            if (close) {
                batch.close();
            }
        }
    } finally {
        if (close) {
            closeTask.run();
        }
    }
}
Also used : Batch(org.wildfly.clustering.ee.Batch)

Aggregations

Batch (org.wildfly.clustering.ee.Batch)45 Test (org.junit.Test)28 BatchContext (org.wildfly.clustering.ee.BatchContext)19 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)11 HttpServerExchange (io.undertow.server.HttpServerExchange)10 SessionListeners (io.undertow.server.session.SessionListeners)10 SessionListener (io.undertow.server.session.SessionListener)9 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)8 SessionConfig (io.undertow.server.session.SessionConfig)6 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)5 Instant (java.time.Instant)4 Node (org.wildfly.clustering.group.Node)4 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)4 Account (io.undertow.security.idm.Account)3 SingleSignOn (io.undertow.security.impl.SingleSignOn)3 AbstractMap (java.util.AbstractMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3