Search in sources :

Example 6 with BatchContext

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

the class DistributableSession method setMaxInactiveInterval.

@Override
public void setMaxInactiveInterval(int interval) {
    Session<LocalSessionContext> session = this.entry.getKey();
    validate(session);
    try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
        session.getMetaData().setMaxInactiveInterval(Duration.ofSeconds(interval));
    }
}
Also used : BatchContext(org.wildfly.clustering.ee.BatchContext)

Example 7 with BatchContext

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

the class DistributableSession method getLastAccessedTime.

@Override
public long getLastAccessedTime() {
    Session<LocalSessionContext> session = this.entry.getKey();
    validate(session);
    try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
        return session.getMetaData().getLastAccessedTime().toEpochMilli();
    }
}
Also used : BatchContext(org.wildfly.clustering.ee.BatchContext)

Example 8 with BatchContext

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

the class DistributableSession method setAttribute.

@Override
public Object setAttribute(String name, Object value) {
    if (value == null) {
        return this.removeAttribute(name);
    }
    Session<LocalSessionContext> session = this.entry.getKey();
    validate(session);
    try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
        if (CachedAuthenticatedSessionHandler.ATTRIBUTE_NAME.equals(name)) {
            AuthenticatedSession auth = (AuthenticatedSession) value;
            return AUTO_REAUTHENTICATING_MECHANISMS.contains(auth.getMechanism()) ? this.setLocalContext(auth) : session.getAttributes().setAttribute(name, new ImmutableAuthenticatedSession(auth));
        }
        Object old = session.getAttributes().setAttribute(name, value);
        if (old == null) {
            this.manager.getSessionListeners().attributeAdded(this, name, value);
        } else if (old != value) {
            this.manager.getSessionListeners().attributeUpdated(this, name, value, old);
        }
        return old;
    }
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) BatchContext(org.wildfly.clustering.ee.BatchContext)

Example 9 with BatchContext

use of org.wildfly.clustering.ee.BatchContext 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 10 with BatchContext

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

the class DistributableSession method getMaxInactiveInterval.

@Override
public int getMaxInactiveInterval() {
    Session<LocalSessionContext> session = this.entry.getKey();
    validate(session);
    try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
        return (int) session.getMetaData().getMaxInactiveInterval().getSeconds();
    }
}
Also used : BatchContext(org.wildfly.clustering.ee.BatchContext)

Aggregations

BatchContext (org.wildfly.clustering.ee.BatchContext)42 Test (org.junit.Test)30 Batch (org.wildfly.clustering.ee.Batch)19 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)15 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)11 SessionListeners (io.undertow.server.session.SessionListeners)9 SessionListener (io.undertow.server.session.SessionListener)8 Session (io.undertow.server.session.Session)6 SessionManager (io.undertow.server.session.SessionManager)6 HttpServerExchange (io.undertow.server.HttpServerExchange)5 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)5 Account (io.undertow.security.idm.Account)4 Instant (java.time.Instant)3 SessionConfig (io.undertow.server.session.SessionConfig)2 CachedAuthenticatedSessionHandler (io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler)2 Transaction (javax.transaction.Transaction)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1