Search in sources :

Example 11 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSingleSignOnManagerTestCase method createSingleSignOn.

@Test
public void createSingleSignOn() {
    String id = "sso";
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    Account account = mock(Account.class);
    String mechanism = HttpServletRequest.BASIC_AUTH;
    SSO<AuthenticatedSession, String, String, Void> sso = mock(SSO.class);
    ArgumentCaptor<AuthenticatedSession> authenticationCaptor = ArgumentCaptor.forClass(AuthenticatedSession.class);
    when(this.manager.createIdentifier()).thenReturn(id);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.createSSO(same(id), authenticationCaptor.capture())).thenReturn(sso);
    SingleSignOn result = this.subject.createSingleSignOn(account, mechanism);
    verify(batcher).suspendBatch();
    assertNotNull(result);
    AuthenticatedSession capturedAuthentication = authenticationCaptor.getValue();
    assertNotNull(capturedAuthentication);
    assertSame(capturedAuthentication.getAccount(), account);
    assertSame(capturedAuthentication.getMechanism(), mechanism);
}
Also used : Account(io.undertow.security.idm.Account) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Batch(org.wildfly.clustering.ee.Batch) SingleSignOn(io.undertow.security.impl.SingleSignOn) Test(org.junit.Test)

Example 12 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSingleSignOnManagerTestCase method findSingleSignOn.

@Test
public void findSingleSignOn() {
    String id = "sso";
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    SSO<AuthenticatedSession, String, String, Void> sso = mock(SSO.class);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.findSSO(id)).thenReturn(sso);
    SingleSignOn result = this.subject.findSingleSignOn(id);
    assertNotNull(result);
    verify(batcher).suspendBatch();
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Batch(org.wildfly.clustering.ee.Batch) SingleSignOn(io.undertow.security.impl.SingleSignOn) Test(org.junit.Test)

Example 13 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSingleSignOnTestCase method getMechanismName.

@Test
public void getMechanismName() {
    BatchContext context = mock(BatchContext.class);
    Account account = mock(Account.class);
    String mechanism = HttpServletRequest.CLIENT_CERT_AUTH;
    AuthenticatedSession authentication = new AuthenticatedSession(account, mechanism);
    when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.sso.getAuthentication()).thenReturn(authentication);
    String result = this.subject.getMechanismName();
    assertEquals(HttpServletRequest.CLIENT_CERT_AUTH, 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 14 with AuthenticatedSession

use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.

the class DistributableSessionTestCase method setAuthenticatedSessionAttribute.

@Test
public void setAuthenticatedSessionAttribute() {
    when(this.session.getMetaData()).thenReturn(this.metaData);
    when(this.metaData.isNew()).thenReturn(false);
    io.undertow.server.session.Session session = new DistributableSession(this.manager, this.session, this.config, this.batch, this.closeTask);
    String name = CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession";
    Account account = mock(Account.class);
    AuthenticatedSession auth = new AuthenticatedSession(account, HttpServletRequest.FORM_AUTH);
    SessionManager<Map<String, Object>, 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) session.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();
    verify(this.session, never()).close();
    verify(this.closeTask, never()).accept(null);
    reset(context, attributes);
    capturedAuth = ArgumentCaptor.forClass(AuthenticatedSession.class);
    when(attributes.setAttribute(same(name), capturedAuth.capture())).thenReturn(null);
    result = (AuthenticatedSession) session.setAttribute(name, auth);
    assertSame(auth.getAccount(), capturedAuth.getValue().getAccount());
    assertSame(auth.getMechanism(), capturedAuth.getValue().getMechanism());
    assertNull(result);
    verify(context).close();
    verify(this.session, never()).close();
    verify(this.closeTask, never()).accept(null);
    reset(context, attributes);
    auth = new AuthenticatedSession(account, HttpServletRequest.BASIC_AUTH);
    AuthenticatedSession oldSession = new AuthenticatedSession(oldAccount, HttpServletRequest.BASIC_AUTH);
    Map<String, Object> localContext = new HashMap<>();
    localContext.put(name, oldSession);
    when(this.session.getLocalContext()).thenReturn(localContext);
    result = (AuthenticatedSession) session.setAttribute(name, auth);
    assertSame(auth, localContext.get(name));
    verify(context).close();
    verify(this.session, never()).close();
    verify(this.closeTask, never()).accept(null);
    reset(context);
    doThrow(IllegalStateException.class).when(this.session).getAttributes();
    assertThrows(IllegalStateException.class, () -> session.setAttribute(name, oldAuth));
    verify(context).close();
    verify(this.session).close();
    verify(this.closeTask).accept(null);
}
Also used : Account(io.undertow.security.idm.Account) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) HashMap(java.util.HashMap) BatchContext(org.wildfly.clustering.ee.BatchContext) CachedAuthenticatedSessionHandler(io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler) Batch(org.wildfly.clustering.ee.Batch) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) OptionMap(org.xnio.OptionMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)14 Batch (org.wildfly.clustering.ee.Batch)8 BatchContext (org.wildfly.clustering.ee.BatchContext)8 Test (org.junit.Test)7 Account (io.undertow.security.idm.Account)6 CachedAuthenticatedSessionHandler (io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)3 OptionMap (org.xnio.OptionMap)3 SingleSignOn (io.undertow.security.impl.SingleSignOn)2