Search in sources :

Example 1 with Session

use of io.undertow.server.session.Session in project wildfly by wildfly.

the class DistributableSingleSignOnTestCase method add.

@Test
public void add() {
    String deployment = "deployment";
    String sessionId = "session";
    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.getId()).thenReturn(sessionId);
    when(session.getSessionManager()).thenReturn(manager);
    when(manager.getDeploymentName()).thenReturn(deployment);
    when(this.sso.getSessions()).thenReturn(sessions);
    this.subject.add(session);
    verify(sessions).addSession(deployment, sessionId);
    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 2 with Session

use of io.undertow.server.session.Session in project wildfly by wildfly.

the class LogoutSessionListener method sessionDestroyed.

@Override
public void sessionDestroyed(HttpSessionEvent se) {
    //we need to get the current account
    //there are two options here, we can look for the account in the current request
    //or we can look for the account that has been saved in the session
    //for maximum compatibility we do both
    ServletRequestContext src = ServletRequestContext.current();
    Account requestAccount = null;
    if (src != null) {
        requestAccount = src.getExchange().getSecurityContext().getAuthenticatedAccount();
        if (requestAccount != null) {
            clearAccount(requestAccount);
        }
    }
    if (se.getSession() instanceof HttpSessionImpl) {
        final HttpSessionImpl impl = (HttpSessionImpl) se.getSession();
        Session session;
        if (WildFlySecurityManager.isChecking()) {
            session = WildFlySecurityManager.doChecked(new PrivilegedAction<Session>() {

                @Override
                public Session run() {
                    return impl.getSession();
                }
            });
        } else {
            session = impl.getSession();
        }
        if (session != null) {
            AuthenticatedSessionManager.AuthenticatedSession authenticatedSession = (AuthenticatedSessionManager.AuthenticatedSession) session.getAttribute(CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession");
            if (authenticatedSession != null) {
                Account sessionAccount = authenticatedSession.getAccount();
                if (sessionAccount != null && !sessionAccount.equals(requestAccount)) {
                    clearAccount(sessionAccount);
                }
            }
        }
    }
}
Also used : Account(io.undertow.security.idm.Account) CachedAuthenticatedSessionHandler(io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler) HttpSessionImpl(io.undertow.servlet.spec.HttpSessionImpl) PrivilegedAction(java.security.PrivilegedAction) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) AuthenticatedSessionManager(io.undertow.security.api.AuthenticatedSessionManager) Session(io.undertow.server.session.Session)

Example 3 with Session

use of io.undertow.server.session.Session 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 4 with Session

use of io.undertow.server.session.Session 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 5 with Session

use of io.undertow.server.session.Session 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)

Aggregations

Session (io.undertow.server.session.Session)33 SessionManager (io.undertow.server.session.SessionManager)19 Test (org.junit.Test)10 HttpServerExchange (io.undertow.server.HttpServerExchange)9 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)7 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)7 HttpSessionImpl (io.undertow.servlet.spec.HttpSessionImpl)7 HttpString (io.undertow.util.HttpString)7 HttpHandler (io.undertow.server.HttpHandler)6 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)6 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)6 IOException (java.io.IOException)6 BatchContext (org.wildfly.clustering.ee.BatchContext)6 SessionConfig (io.undertow.server.session.SessionConfig)5 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)4 TestHttpClient (io.undertow.testutils.TestHttpClient)4 Map (java.util.Map)4 Header (org.apache.http.Header)4 HttpResponse (org.apache.http.HttpResponse)4 HeaderMap (io.undertow.util.HeaderMap)3