use of org.apache.catalina.authenticator.SingleSignOn 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;
}
}
use of org.apache.catalina.authenticator.SingleSignOn in project Payara by payara.
the class VirtualServer method configureSingleSignOn.
/**
* Configures the SSO valve of this VirtualServer.
*/
void configureSingleSignOn(boolean globalSSOEnabled, WebContainerFeatureFactory webContainerFeatureFactory, boolean ssoFailoverEnabled) {
if (!isSSOEnabled(globalSSOEnabled)) {
/*
* Disable SSO
*/
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.DISABLE_SSO, getID());
}
boolean hasExistingSSO = false;
// Remove existing SSO valve (if any)
GlassFishValve[] valves = getValves();
for (int i = 0; valves != null && i < valves.length; i++) {
if (valves[i] instanceof SingleSignOn) {
removeValve(valves[i]);
hasExistingSSO = true;
break;
}
}
this.ssoFailoverEnabled = ssoFailoverEnabled;
if (hasExistingSSO) {
setSingleSignOnForChildren(null);
}
} else {
/*
* Enable SSO
*/
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.ENABLE_SSO, getID());
}
GlassFishSingleSignOn sso = null;
// find existing SSO (if any), in case of a reconfig
GlassFishValve[] valves = getValves();
for (int i = 0; valves != null && i < valves.length; i++) {
if (valves[i] instanceof GlassFishSingleSignOn) {
sso = (GlassFishSingleSignOn) valves[i];
break;
}
}
if (sso != null && this.ssoFailoverEnabled != ssoFailoverEnabled) {
removeValve(sso);
sso = null;
// then SSO Valve will be recreated
}
if (sso == null) {
SSOFactory ssoFactory = webContainerFeatureFactory.getSSOFactory();
sso = ssoFactory.createSingleSignOnValve(getName());
this.ssoFailoverEnabled = ssoFailoverEnabled;
setSingleSignOnForChildren(sso);
addValve((GlassFishValve) sso);
}
// set max idle time if given
Property idle = vsBean.getProperty(SSO_MAX_IDLE);
if (idle != null && idle.getValue() != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.SSO_MAX_INACTIVE_SET, new Object[] { idle.getValue(), getID() });
}
sso.setMaxInactive(Integer.parseInt(idle.getValue()));
}
// set expirer thread sleep time if given
Property expireTime = vsBean.getProperty(SSO_REAP_INTERVAL);
if (expireTime != null && expireTime.getValue() != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.SSO_REAP_INTERVAL_SET);
}
sso.setReapInterval(Integer.parseInt(expireTime.getValue()));
}
configureSingleSignOnCookieSecure();
configureSingleSignOnCookieHttpOnly();
}
}
Aggregations