Search in sources :

Example 1 with BatchContext

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

the class DistributableSingleSignOn method iterator.

@Override
public Iterator<Session> iterator() {
    try (BatchContext context = this.batcher.resumeBatch(this.batch)) {
        Sessions<String, String> sessions = this.sso.getSessions();
        Set<String> deployments = sessions.getDeployments();
        List<Session> result = new ArrayList<>(deployments.size());
        for (String deployment : sessions.getDeployments()) {
            String sessionId = sessions.getSession(deployment);
            if (sessionId != null) {
                SessionManager manager = this.registry.getSessionManager(deployment);
                if (manager != null) {
                    result.add(new InvalidatableSession(manager, sessionId));
                }
            }
        }
        return result.iterator();
    }
}
Also used : SessionManager(io.undertow.server.session.SessionManager) ArrayList(java.util.ArrayList) BatchContext(org.wildfly.clustering.ee.BatchContext) Session(io.undertow.server.session.Session) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)

Example 2 with BatchContext

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

the class DistributableSingleSignOnTestCase method getSession.

@Test
public void getSession() {
    String deployment = "deployment";
    String sessionId = "session";
    BatchContext context = mock(BatchContext.class);
    SessionManager manager = mock(SessionManager.class);
    Sessions<String, String> sessions = mock(Sessions.class);
    when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
    when(manager.getDeploymentName()).thenReturn(deployment);
    when(this.sso.getSessions()).thenReturn(sessions);
    when(sessions.getSession(deployment)).thenReturn(sessionId);
    Session result = this.subject.getSession(manager);
    assertSame(sessionId, result.getId());
    assertSame(manager, result.getSessionManager());
    verifyZeroInteractions(this.batch);
    verify(context).close();
}
Also used : SessionManager(io.undertow.server.session.SessionManager) BatchContext(org.wildfly.clustering.ee.BatchContext) Session(io.undertow.server.session.Session) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Test(org.junit.Test)

Example 3 with BatchContext

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

the class DistributableSingleSignOnTestCase method contains.

@Test
public void contains() {
    String deployment = "deployment";
    BatchContext context = mock(BatchContext.class);
    Session session = mock(Session.class);
    SessionManager manager = mock(SessionManager.class);
    Sessions<String, String> sessions = mock(Sessions.class);
    when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
    when(session.getSessionManager()).thenReturn(manager);
    when(manager.getDeploymentName()).thenReturn(deployment);
    when(this.sso.getSessions()).thenReturn(sessions);
    when(sessions.getDeployments()).thenReturn(Collections.<String>emptySet());
    boolean result = this.subject.contains(session);
    assertFalse(result);
    verifyZeroInteractions(this.batch);
    verify(context).close();
    reset(context);
    when(sessions.getDeployments()).thenReturn(Collections.singleton(deployment));
    result = this.subject.contains(session);
    assertTrue(result);
    verifyZeroInteractions(this.batch);
    verify(context).close();
}
Also used : SessionManager(io.undertow.server.session.SessionManager) BatchContext(org.wildfly.clustering.ee.BatchContext) Session(io.undertow.server.session.Session) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Test(org.junit.Test)

Example 4 with BatchContext

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

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

the class DistributableSingleSignOnTestCase method close.

@Test
public void close() {
    BatchContext context = mock(BatchContext.class);
    when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
    this.subject.close();
    verify(this.batch).close();
    verify(context).close();
    reset(this.batch);
    this.subject.close();
    verify(this.batch, never()).close();
}
Also used : BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

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