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);
}
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();
}
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();
}
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);
}
Aggregations