Search in sources :

Example 11 with SessionListener

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

the class UndertowSessionExpirationListenerTestCase method sessionExpired.

@Test
public void sessionExpired() {
    Deployment deployment = mock(Deployment.class);
    UndertowSessionManager manager = mock(UndertowSessionManager.class);
    SessionManager<LocalSessionContext, Batch> delegateManager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    SessionListener listener = mock(SessionListener.class);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    ArgumentCaptor<Session> capturedSession = ArgumentCaptor.forClass(Session.class);
    String expectedSessionId = "session";
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    SessionExpirationListener expirationListener = new UndertowSessionExpirationListener(deployment, listeners);
    when(deployment.getSessionManager()).thenReturn(manager);
    when(manager.getSessionManager()).thenReturn(delegateManager);
    when(delegateManager.getBatcher()).thenReturn(batcher);
    when(batcher.suspendBatch()).thenReturn(batch);
    when(session.getId()).thenReturn(expectedSessionId);
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(Collections.emptySet());
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(Instant.now());
    when(metaData.getLastAccessedTime()).thenReturn(Instant.now());
    when(metaData.getMaxInactiveInterval()).thenReturn(Duration.ZERO);
    expirationListener.sessionExpired(session);
    verify(batcher).suspendBatch();
    verify(listener).sessionDestroyed(capturedSession.capture(), isNull(HttpServerExchange.class), same(SessionListener.SessionDestroyedReason.TIMEOUT));
    verify(batcher).resumeBatch(batch);
    assertSame(expectedSessionId, capturedSession.getValue().getId());
    assertSame(manager, capturedSession.getValue().getSessionManager());
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Deployment(io.undertow.servlet.api.Deployment) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) HttpServerExchange(io.undertow.server.HttpServerExchange) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionListener(io.undertow.server.session.SessionListener) Session(io.undertow.server.session.Session) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Test(org.junit.Test)

Example 12 with SessionListener

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

the class DistributableSingleSignOnManagerBuilder method build.

@Override
public ServiceBuilder<SingleSignOnManager> build(ServiceTarget target, ServiceName name, CapabilityServiceSupport support, String serverName, String hostName) {
    ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);
    Builder<SSOManagerFactory<AuthenticatedSession, String, String, Batch>> factoryBuilder = PROVIDER.<AuthenticatedSession, String, String>getBuilder(hostName).configure(support);
    Builder<SessionIdGenerator> generatorBuilder = new SessionIdGeneratorBuilder(hostServiceName);
    Builder<SSOManager<AuthenticatedSession, String, String, Void, Batch>> managerBuilder = new SSOManagerBuilder<>(factoryBuilder.getServiceName(), generatorBuilder.getServiceName(), () -> null);
    Builder<SessionListener> listenerBuilder = new SessionListenerBuilder(managerBuilder.getServiceName());
    Builder<SessionManagerRegistry> registryBuilder = new SessionManagerRegistryBuilder(hostServiceName, listenerBuilder.getServiceName());
    Arrays.asList(factoryBuilder, generatorBuilder, managerBuilder, listenerBuilder, registryBuilder).forEach(builder -> builder.build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install());
    return target.addService(name, new ValueService<>(this)).addDependency(managerBuilder.getServiceName(), SSOManager.class, this.manager).addDependency(registryBuilder.getServiceName(), SessionManagerRegistry.class, this.registry).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : SSOManager(org.wildfly.clustering.web.sso.SSOManager) SSOManagerFactory(org.wildfly.clustering.web.sso.SSOManagerFactory) ValueService(org.jboss.msc.service.ValueService) ServiceName(org.jboss.msc.service.ServiceName) SessionIdGenerator(io.undertow.server.session.SessionIdGenerator) SessionListener(io.undertow.server.session.SessionListener)

Aggregations

SessionListener (io.undertow.server.session.SessionListener)12 SessionListeners (io.undertow.server.session.SessionListeners)9 Test (org.junit.Test)9 Batch (org.wildfly.clustering.ee.Batch)9 BatchContext (org.wildfly.clustering.ee.BatchContext)8 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)7 HttpServerExchange (io.undertow.server.HttpServerExchange)4 ServletContainerInitializerInfo (io.undertow.servlet.api.ServletContainerInitializerInfo)2 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)1 AuthenticationMechanismFactory (io.undertow.security.api.AuthenticationMechanismFactory)1 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)1 HttpContinueReadHandler (io.undertow.server.handlers.HttpContinueReadHandler)1 PredicateHandler (io.undertow.server.handlers.PredicateHandler)1 Session (io.undertow.server.session.Session)1 SessionConfig (io.undertow.server.session.SessionConfig)1 SessionIdGenerator (io.undertow.server.session.SessionIdGenerator)1 ServletExtension (io.undertow.servlet.ServletExtension)1 Deployment (io.undertow.servlet.api.Deployment)1