Search in sources :

Example 1 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession 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 AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession 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 3 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSingleSignOnTestCase method getAccount.

@Test
public void getAccount() {
    BatchContext context = mock(BatchContext.class);
    Account account = mock(Account.class);
    String mechanism = HttpServletRequest.BASIC_AUTH;
    AuthenticatedSession authentication = new AuthenticatedSession(account, mechanism);
    when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.sso.getAuthentication()).thenReturn(authentication);
    Account result = this.subject.getAccount();
    assertSame(account, result);
    verifyZeroInteractions(this.batch);
    verify(context).close();
}
Also used : Account(io.undertow.security.idm.Account) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 4 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession 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 5 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSession method setLocalContext.

private AuthenticatedSession setLocalContext(AuthenticatedSession auth) {
    LocalSessionContext localContext = this.entry.getKey().getLocalContext();
    AuthenticatedSession old = localContext.getAuthenticatedSession();
    localContext.setAuthenticatedSession(auth);
    return old;
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)

Aggregations

AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)14 Batch (org.wildfly.clustering.ee.Batch)8 BatchContext (org.wildfly.clustering.ee.BatchContext)8 Test (org.junit.Test)7 Account (io.undertow.security.idm.Account)6 CachedAuthenticatedSessionHandler (io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)3 OptionMap (org.xnio.OptionMap)3 SingleSignOn (io.undertow.security.impl.SingleSignOn)2