use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.
the class DistributableSingleSignOnManager method createSingleSignOn.
@Override
public SingleSignOn createSingleSignOn(Account account, String mechanism) {
String id = this.manager.createIdentifier();
Batcher<Batch> batcher = this.manager.getBatcher();
// Batch will be closed when SSO is closed
@SuppressWarnings("resource") Batch batch = batcher.createBatch();
try {
AuthenticatedSession session = new AuthenticatedSession(account, mechanism);
SSO<AuthenticatedSession, String, String, Void> sso = this.manager.createSSO(id, session);
if (log.isTraceEnabled()) {
log.tracef("Creating SSO ID %s for Principal %s and Roles %s", id, account.getPrincipal().getName(), account.getRoles().toString());
}
return new DistributableSingleSignOn(sso, this.registry, batcher, batcher.suspendBatch());
} catch (RuntimeException | Error e) {
batch.discard();
batch.close();
throw e;
}
}
use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.
the class SessionListenerBuilder method sessionIdChanged.
@Override
public void sessionIdChanged(Session session, String oldSessionId) {
SSOManager<AuthenticatedSession, String, String, Void, Batch> manager = this.manager.getValue();
try (Batch batch = manager.getBatcher().createBatch()) {
Sessions<String, String> sessions = manager.findSessionsContaining(oldSessionId);
if (sessions != null) {
String deployment = sessions.getDeployments().stream().filter(key -> sessions.getSession(key) != null).findFirst().get();
sessions.removeSession(deployment);
sessions.addSession(deployment, session.getId());
}
}
}
use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.
the class DistributableSingleSignOnTestCase method getAccount.
@Test
public void getAccount() {
BatchContext context = mock(BatchContext.class);
Account account = mock(Account.class);
String mechanism = HttpServletRequest.BASIC_AUTH;
AuthenticatedSession authentication = new AuthenticatedSession(account, mechanism);
when(this.batcher.resumeBatch(this.batch)).thenReturn(context);
when(this.sso.getAuthentication()).thenReturn(authentication);
Account result = this.subject.getAccount();
assertSame(account, result);
verifyZeroInteractions(this.batch);
verify(context).close();
}
use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.
the class DistributableSession method setAttribute.
@Override
public Object setAttribute(String name, Object value) {
if (value == null) {
return this.removeAttribute(name);
}
Session<LocalSessionContext> session = this.entry.getKey();
validate(session);
try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
if (CachedAuthenticatedSessionHandler.ATTRIBUTE_NAME.equals(name)) {
AuthenticatedSession auth = (AuthenticatedSession) value;
return AUTO_REAUTHENTICATING_MECHANISMS.contains(auth.getMechanism()) ? this.setLocalContext(auth) : session.getAttributes().setAttribute(name, new ImmutableAuthenticatedSession(auth));
}
Object old = session.getAttributes().setAttribute(name, value);
if (old == null) {
this.manager.getSessionListeners().attributeAdded(this, name, value);
} else if (old != value) {
this.manager.getSessionListeners().attributeUpdated(this, name, value, old);
}
return old;
}
}
use of io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession in project wildfly by wildfly.
the class DistributableSession method setLocalContext.
private AuthenticatedSession setLocalContext(AuthenticatedSession auth) {
LocalSessionContext localContext = this.entry.getKey().getLocalContext();
AuthenticatedSession old = localContext.getAuthenticatedSession();
localContext.setAuthenticatedSession(auth);
return old;
}
Aggregations