Search in sources :

Example 16 with BatchContext

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

the class DistributableSessionTestCase method getAuthenticatedSessionAttribute.

@Test
public void getAuthenticatedSessionAttribute() {
    String name = CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession";
    this.validate(session -> session.getAttribute(name));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    Account account = mock(Account.class);
    AuthenticatedSession auth = new AuthenticatedSession(account, HttpServletRequest.FORM_AUTH);
    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.getAttribute(name)).thenReturn(auth);
    AuthenticatedSession result = (AuthenticatedSession) this.adapter.getAttribute(name);
    assertSame(account, result.getAccount());
    assertSame(HttpServletRequest.FORM_AUTH, result.getMechanism());
    verify(context).close();
    reset(context);
    LocalSessionContext localContext = mock(LocalSessionContext.class);
    AuthenticatedSession expected = new AuthenticatedSession(account, HttpServletRequest.BASIC_AUTH);
    when(attributes.getAttribute(name)).thenReturn(null);
    when(this.session.getLocalContext()).thenReturn(localContext);
    when(localContext.getAuthenticatedSession()).thenReturn(expected);
    result = (AuthenticatedSession) this.adapter.getAttribute(name);
    assertSame(expected, result);
    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 17 with BatchContext

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

the class DistributableSingleSignOnTestCase method invalidate.

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

Example 18 with BatchContext

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

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

the class DistributableSessionTestCase method setSameAttribute.

@Test
public void setSameAttribute() {
    String name = "name";
    Integer value = Integer.valueOf(1);
    this.validate(session -> session.setAttribute(name, value));
    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 = value;
    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(name, value)).thenReturn(expected);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    Object result = this.adapter.setAttribute(name, value);
    assertSame(expected, result);
    verify(listener, never()).attributeAdded(this.adapter, name, value);
    verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
    verify(listener, never()).attributeRemoved(same(this.adapter), same(name), any());
    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 20 with BatchContext

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

the class DistributableSessionTestCase method getAttribute.

@Test
public void getAttribute() {
    String name = "name";
    this.validate(session -> session.getAttribute(name));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    Object expected = new Object();
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttribute(name)).thenReturn(expected);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    Object result = this.adapter.getAttribute(name);
    assertSame(expected, result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) 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