use of org.wildfly.clustering.ee.Batch 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 org.wildfly.clustering.ee.Batch in project wildfly by wildfly.
the class SSOManagerBuilder method start.
@Override
public void start(StartContext context) throws StartException {
SSOManagerFactory<A, D, S, Batch> factory = this.factory.getValue();
Module module = Module.forClass(this.getClass());
this.context = new SimpleMarshallingContextFactory().createMarshallingContext(new SimpleMarshallingConfigurationRepository(MarshallingVersion.class, MarshallingVersion.CURRENT, module), null);
this.manager = factory.createSSOManager(this);
this.manager.start();
}
use of org.wildfly.clustering.ee.Batch 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 org.wildfly.clustering.ee.Batch in project wildfly by wildfly.
the class DistributableSession method changeSessionId.
@Override
public String changeSessionId(HttpServerExchange exchange, SessionConfig config) {
Session<LocalSessionContext> oldSession = this.entry.getKey();
validate(oldSession);
SessionManager<LocalSessionContext, Batch> manager = this.manager.getSessionManager();
String id = manager.createIdentifier();
try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
Session<LocalSessionContext> newSession = manager.createSession(id);
for (String name : oldSession.getAttributes().getAttributeNames()) {
newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name));
}
newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval());
newSession.getMetaData().setLastAccessedTime(oldSession.getMetaData().getLastAccessedTime());
newSession.getLocalContext().setAuthenticatedSession(oldSession.getLocalContext().getAuthenticatedSession());
config.setSessionId(exchange, id);
this.entry = new SimpleImmutableEntry<>(newSession, config);
oldSession.invalidate();
}
// Invoke listeners outside of the context of the batch associated with this session
this.manager.getSessionListeners().sessionIdChanged(this, oldSession.getId());
return id;
}
use of org.wildfly.clustering.ee.Batch in project wildfly by wildfly.
the class DistributableSessionManager method createSession.
@Override
public io.undertow.server.session.Session createSession(HttpServerExchange exchange, SessionConfig config) {
if (config == null) {
throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
}
String requestedId = config.findSessionId(exchange);
String id = (requestedId == null) ? this.manager.createIdentifier() : requestedId;
Runnable closeTask = this.getSessionCloseTask();
boolean close = true;
try {
Batcher<Batch> batcher = this.manager.getBatcher();
// Batch will be closed by Session.close();
Batch batch = batcher.createBatch();
try {
Session<LocalSessionContext> session = this.manager.createSession(id);
if (session == null) {
throw UndertowClusteringLogger.ROOT_LOGGER.sessionAlreadyExists(id);
}
if (requestedId == null) {
config.setSessionId(exchange, id);
}
io.undertow.server.session.Session result = new DistributableSession(this, session, config, batcher.suspendBatch(), closeTask);
this.listeners.sessionCreated(result, exchange);
if (this.statistics != null) {
this.statistics.record(result);
}
close = false;
return result;
} catch (RuntimeException | Error e) {
batch.discard();
throw e;
} finally {
if (close) {
batch.close();
}
}
} finally {
if (close) {
closeTask.run();
}
}
}
Aggregations