Search in sources :

Example 36 with BatchContext

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

the class DistributableSessionTestCase method changeSessionId.

@Test
public void changeSessionId() {
    HttpServerExchange exchange = new HttpServerExchange(null);
    SessionConfig config = mock(SessionConfig.class);
    this.validate(session -> session.changeSessionId(exchange, config));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    Session<LocalSessionContext> session = mock(Session.class);
    SessionAttributes oldAttributes = mock(SessionAttributes.class);
    SessionAttributes newAttributes = mock(SessionAttributes.class);
    SessionMetaData oldMetaData = mock(SessionMetaData.class);
    SessionMetaData newMetaData = mock(SessionMetaData.class);
    LocalSessionContext oldContext = mock(LocalSessionContext.class);
    LocalSessionContext newContext = mock(LocalSessionContext.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    String oldSessionId = "old";
    String newSessionId = "new";
    String name = "name";
    Object value = new Object();
    Instant now = Instant.now();
    Duration interval = Duration.ofSeconds(10L);
    AuthenticatedSession authenticatedSession = new AuthenticatedSession(null, null);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(manager.createIdentifier()).thenReturn(newSessionId);
    when(manager.createSession(newSessionId)).thenReturn(session);
    when(this.session.getAttributes()).thenReturn(oldAttributes);
    when(this.session.getMetaData()).thenReturn(oldMetaData);
    when(session.getAttributes()).thenReturn(newAttributes);
    when(session.getMetaData()).thenReturn(newMetaData);
    when(oldAttributes.getAttributeNames()).thenReturn(Collections.singleton(name));
    when(oldAttributes.getAttribute(name)).thenReturn(value);
    when(newAttributes.setAttribute(name, value)).thenReturn(null);
    when(oldMetaData.getLastAccessedTime()).thenReturn(now);
    when(oldMetaData.getMaxInactiveInterval()).thenReturn(interval);
    when(this.session.getId()).thenReturn(oldSessionId);
    when(session.getId()).thenReturn(newSessionId);
    when(this.session.getLocalContext()).thenReturn(oldContext);
    when(session.getLocalContext()).thenReturn(newContext);
    when(oldContext.getAuthenticatedSession()).thenReturn(authenticatedSession);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    String result = this.adapter.changeSessionId(exchange, config);
    assertSame(newSessionId, result);
    verify(newMetaData).setLastAccessedTime(now);
    verify(newMetaData).setMaxInactiveInterval(interval);
    verify(config).setSessionId(exchange, newSessionId);
    verify(newContext).setAuthenticatedSession(same(authenticatedSession));
    verify(listener).sessionIdChanged(this.adapter, oldSessionId);
    verify(context).close();
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Instant(java.time.Instant) SessionConfig(io.undertow.server.session.SessionConfig) BatchContext(org.wildfly.clustering.ee.BatchContext) Duration(java.time.Duration) HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Example 37 with BatchContext

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

the class DistributableSessionTestCase method setAuthenticatedSessionAttribute.

@Test
public void setAuthenticatedSessionAttribute() {
    String name = CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession";
    Account account = mock(Account.class);
    AuthenticatedSession auth = new AuthenticatedSession(account, HttpServletRequest.FORM_AUTH);
    this.validate(session -> session.setAttribute(name, "bar"));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    Account oldAccount = mock(Account.class);
    AuthenticatedSession oldAuth = new AuthenticatedSession(oldAccount, HttpServletRequest.FORM_AUTH);
    ArgumentCaptor<AuthenticatedSession> capturedAuth = ArgumentCaptor.forClass(AuthenticatedSession.class);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.setAttribute(same(name), capturedAuth.capture())).thenReturn(oldAuth);
    AuthenticatedSession result = (AuthenticatedSession) this.adapter.setAttribute(name, auth);
    assertSame(auth.getAccount(), capturedAuth.getValue().getAccount());
    assertSame(auth.getMechanism(), capturedAuth.getValue().getMechanism());
    assertSame(oldAccount, result.getAccount());
    assertSame(HttpServletRequest.FORM_AUTH, result.getMechanism());
    verify(context).close();
    reset(context, attributes);
    capturedAuth = ArgumentCaptor.forClass(AuthenticatedSession.class);
    when(attributes.setAttribute(same(name), capturedAuth.capture())).thenReturn(null);
    result = (AuthenticatedSession) this.adapter.setAttribute(name, auth);
    assertSame(auth.getAccount(), capturedAuth.getValue().getAccount());
    assertSame(auth.getMechanism(), capturedAuth.getValue().getMechanism());
    assertNull(result);
    verify(context).close();
    reset(context, attributes);
    auth = new AuthenticatedSession(account, HttpServletRequest.BASIC_AUTH);
    AuthenticatedSession oldSession = new AuthenticatedSession(oldAccount, HttpServletRequest.BASIC_AUTH);
    LocalSessionContext localContext = mock(LocalSessionContext.class);
    when(this.session.getLocalContext()).thenReturn(localContext);
    when(localContext.getAuthenticatedSession()).thenReturn(oldSession);
    result = (AuthenticatedSession) this.adapter.setAttribute(name, auth);
    verify(localContext).setAuthenticatedSession(same(auth));
    verify(context).close();
}
Also used : Account(io.undertow.security.idm.Account) CachedAuthenticatedSessionHandler(io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Batch(org.wildfly.clustering.ee.Batch) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 38 with BatchContext

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

the class DistributableSessionTestCase method invalidate.

@Test
public void invalidate() {
    HttpServerExchange exchange = new HttpServerExchange(null);
    this.validate(session -> session.invalidate(exchange));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    String sessionId = "session";
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    when(this.session.getId()).thenReturn(sessionId);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    this.adapter.invalidate(exchange);
    verify(this.session).invalidate();
    verify(this.config).clearSession(exchange, sessionId);
    verify(listener).sessionDestroyed(this.adapter, exchange, SessionDestroyedReason.INVALIDATED);
    verify(this.batch).close();
    verify(context).close();
    verify(this.closeTask).run();
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) BatchContext(org.wildfly.clustering.ee.BatchContext) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Example 39 with BatchContext

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

the class DistributableSessionTestCase method removeAttribute.

@Test
public void removeAttribute() {
    String name = "name";
    this.validate(session -> session.removeAttribute(name));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    Object expected = new Object();
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.removeAttribute(name)).thenReturn(expected);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    Object result = this.adapter.removeAttribute(name);
    assertSame(expected, result);
    verify(listener).attributeRemoved(this.adapter, name, expected);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) BatchContext(org.wildfly.clustering.ee.BatchContext) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Example 40 with BatchContext

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

the class DistributableSingleSignOnTestCase method remove.

@Test
public void remove() {
    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);
    this.subject.remove(session);
    verify(sessions).removeSession(deployment);
    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

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