use of org.apache.catalina.session.PersistentManagerBase in project Payara by payara.
the class Request method doGetSession.
// ------------------------------------------------------ Protected Methods
protected Session doGetSession(boolean create) {
// There cannot be a session if no context has been assigned yet
if (context == null) {
return null;
}
// Return the current session if it exists and is valid
if (session != null && !session.isValid()) {
session = null;
}
if (session != null) {
return session;
}
// Return the requested session if it exists and is valid
Manager manager = context.getManager();
if (manager == null) {
// Sessions are not supported
return null;
}
if (requestedSessionId != null) {
if (!checkUnsuccessfulSessionFind || !unsuccessfulSessionFind) {
try {
if (manager.isSessionVersioningSupported()) {
session = manager.findSession(requestedSessionId, requestedSessionVersion);
// XXX need to revisit
if (session instanceof StandardSession) {
incrementSessionVersion((StandardSession) session, context);
}
} else {
session = manager.findSession(requestedSessionId, this);
}
if (session == null) {
unsuccessfulSessionFind = true;
}
} catch (IOException e) {
session = null;
}
}
if (session != null && !session.isValid()) {
session = null;
}
if (session != null) {
session.access();
return session;
}
}
// Create a new session if requested and the response is not committed
if (!create) {
return null;
}
if (context != null && response != null && context.getCookies() && response.getResponse().isCommitted()) {
throw new IllegalStateException(rb.getString(LogFacade.CANNOT_CREATE_SESSION_EXCEPTION));
}
// START S1AS8PE 4817642
if (requestedSessionId != null && context.getReuseSessionID()) {
session = manager.createSession(requestedSessionId);
if (manager instanceof PersistentManagerBase) {
((PersistentManagerBase) manager).removeFromInvalidatedSessions(requestedSessionId);
}
// END S1AS8PE 4817642
// START GlassFish 896
} else if (sessionTracker.getActiveSessions() > 0) {
synchronized (sessionTracker) {
if (sessionTracker.getActiveSessions() > 0) {
String id = sessionTracker.getSessionId();
session = manager.createSession(id);
if (manager instanceof PersistentManagerBase) {
((PersistentManagerBase) manager).removeFromInvalidatedSessions(id);
}
}
}
// END GlassFish 896
// START S1AS8PE 4817642
} else {
// END S1AS8PE 4817642
// Use the connector's random number generator (if any) to generate
// a session ID. Fallback to the default session ID generator if
// the connector does not implement one.
String id = generateSessionId();
if (id != null) {
session = manager.createSession(id);
} else {
session = manager.createSession();
}
// START S1AS8PE 4817642
}
// END S1AS8PE 4817642
StandardHost reqHost = (StandardHost) getHost();
if (reqHost != null) {
SingleSignOn sso = reqHost.getSingleSignOn();
if (sso != null) {
String ssoId = (String) getNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
if (ssoId != null) {
long ssoVersion = 0L;
Long ssoVersionObj = (Long) getNote(org.apache.catalina.authenticator.Constants.REQ_SSO_VERSION_NOTE);
if (ssoVersionObj != null) {
ssoVersion = ssoVersionObj.longValue();
}
sso.associate(ssoId, ssoVersion, session);
removeNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
}
}
}
// START GlassFish 896
sessionTracker.track(session);
// Creating a new session cookie based on the newly created session
if (session != null && getContext() != null) {
if (manager.isSessionVersioningSupported()) {
incrementSessionVersion((StandardSession) session, context);
}
addSessionCookie();
}
if (session != null) {
session.access();
return session;
} else {
return null;
}
}
Aggregations