use of org.apache.catalina.Manager in project tomee by apache.
the class TomcatWebAppBuilder method init.
/**
* {@inheritDoc}
*/
@Override
public void init(final StandardContext standardContext) {
if (isIgnored(standardContext)) {
return;
}
// just adding a carriage return to get logs more readable
LOGGER.info("------------------------- " + Contexts.getHostname(standardContext).replace("_", hosts.getDefaultHost()) + " -> " + finalName(standardContext.getPath()));
if (FORCE_RELOADABLE) {
final ContextInfo ctxInfo = getContextInfo(standardContext);
if (ctxInfo == null || (ctxInfo.appInfo != null && ctxInfo.appInfo.webAppAlone)) {
// don't do it for ears
standardContext.setReloadable(true);
}
}
if (SKIP_TLD) {
if (standardContext.getJarScanner() != null && standardContext.getJarScanner().getJarScanFilter() != null) {
final JarScanFilter jarScanFilter = standardContext.getJarScanner().getJarScanFilter();
if (StandardJarScanFilter.class.isInstance(jarScanFilter)) {
StandardJarScanFilter.class.cast(jarScanFilter).setDefaultTldScan(false);
}
}
}
final String name = standardContext.getName();
initJ2EEInfo(standardContext);
File warFile = Contexts.warPath(standardContext);
if (!warFile.exists()) {
return;
}
if (!warFile.isDirectory()) {
try {
warFile = DeploymentLoader.unpack(warFile);
} catch (final OpenEJBException e) {
LOGGER.error("can't unpack '" + warFile.getAbsolutePath() + "'");
}
}
standardContext.setCrossContext(SystemInstance.get().getOptions().get(OPENEJB_CROSSCONTEXT_PROPERTY, false));
standardContext.setNamingResources(new OpenEJBNamingResource(standardContext.getNamingResources()));
String sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY + "." + name, (String) null);
if (sessionManager == null) {
sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY, (String) null);
}
if (sessionManager != null) {
if (sessionManagerClass == null) {
try {
// the manager should be in standardclassloader
sessionManagerClass = ParentClassLoaderFinder.Helper.get().loadClass(sessionManager);
} catch (final ClassNotFoundException e) {
LOGGER.error("can't find '" + sessionManager + "', StandardManager will be used", e);
sessionManagerClass = StandardManager.class;
}
}
try {
final Manager mgr = (Manager) sessionManagerClass.newInstance();
standardContext.setManager(mgr);
} catch (final Exception e) {
LOGGER.error("can't instantiate '" + sessionManager + "', StandardManager will be used", e);
}
}
final LifecycleListener[] listeners = standardContext.findLifecycleListeners();
for (final LifecycleListener l : listeners) {
if (l instanceof ContextConfig) {
standardContext.removeLifecycleListener(l);
}
}
standardContext.addLifecycleListener(new OpenEJBContextConfig(new StandardContextInfo(standardContext)));
// force manually the namingContextListener to merge jndi in an easier way
final NamingContextListener ncl = new NamingContextListener();
try {
ncl.setName((String) GET_NAMING_CONTEXT_NAME.invoke(standardContext));
} catch (final Exception e) {
ncl.setName(getId(standardContext));
}
ncl.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite());
standardContext.setNamingContextListener(ncl);
standardContext.addLifecycleListener(ncl);
standardContext.addLifecycleListener(new TomcatJavaJndiBinder());
// listen some events
standardContext.addContainerListener(new TomEEContainerListener());
}
use of org.apache.catalina.Manager in project tomcat by apache.
the class SingleSignOn method expire.
private void expire(SingleSignOnSessionKey key) {
if (engine == null) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
return;
}
Container host = engine.findChild(key.getHostName());
if (host == null) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
return;
}
Context context = (Context) host.findChild(key.getContextName());
if (context == null) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
return;
}
Manager manager = context.getManager();
if (manager == null) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
return;
}
Session session = null;
try {
session = manager.findSession(key.getSessionId());
} catch (IOException e) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
return;
}
if (session == null) {
containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
return;
}
session.expire();
}
use of org.apache.catalina.Manager in project tomcat by apache.
the class ApplicationHttpRequest method isRequestedSessionIdValid.
/**
* Returns true if the request specifies a JSESSIONID that is valid within
* the context of this ApplicationHttpRequest, false otherwise.
*
* @return true if the request specifies a JSESSIONID that is valid within
* the context of this ApplicationHttpRequest, false otherwise.
*/
@Override
public boolean isRequestedSessionIdValid() {
if (crossContext) {
String requestedSessionId = getRequestedSessionId();
if (requestedSessionId == null) {
return false;
}
if (context == null) {
return false;
}
Manager manager = context.getManager();
if (manager == null) {
return false;
}
Session session = null;
try {
session = manager.findSession(requestedSessionId);
} catch (IOException e) {
// Ignore
}
if ((session != null) && session.isValid()) {
return true;
} else {
return false;
}
} else {
return super.isRequestedSessionIdValid();
}
}
use of org.apache.catalina.Manager in project tomcat by apache.
the class Request method doGetSession.
// ------------------------------------------------------ Protected Methods
protected Session doGetSession(boolean create) {
// There cannot be a session if no context has been assigned yet
Context context = getContext();
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) {
try {
session = manager.findSession(requestedSessionId);
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("request.session.failed", requestedSessionId, e.getMessage()), e);
} else {
log.info(sm.getString("request.session.failed", requestedSessionId, e.getMessage()));
}
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;
}
boolean trackModesIncludesCookie = context.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE);
if (trackModesIncludesCookie && response.getResponse().isCommitted()) {
throw new IllegalStateException(sm.getString("coyoteRequest.sessionCreateCommitted"));
}
// Re-use session IDs provided by the client in very limited
// circumstances.
String sessionId = getRequestedSessionId();
if (requestedSessionSSL) {
// If the session ID has been obtained from the SSL handshake then
// use it.
} else if (("/".equals(context.getSessionCookiePath()) && isRequestedSessionIdFromCookie())) {
/* This is the common(ish) use case: using the same session ID with
* multiple web applications on the same host. Typically this is
* used by Portlet implementations. It only works if sessions are
* tracked via cookies. The cookie must have a path of "/" else it
* won't be provided for requests to all web applications.
*
* Any session ID provided by the client should be for a session
* that already exists somewhere on the host. Check if the context
* is configured for this to be confirmed.
*/
if (context.getValidateClientProvidedNewSessionId()) {
boolean found = false;
for (Container container : getHost().findChildren()) {
Manager m = ((Context) container).getManager();
if (m != null) {
try {
if (m.findSession(sessionId) != null) {
found = true;
break;
}
} catch (IOException e) {
// Ignore. Problems with this manager will be
// handled elsewhere.
}
}
}
if (!found) {
sessionId = null;
}
}
} else {
sessionId = null;
}
session = manager.createSession(sessionId);
// Creating a new session cookie based on that session
if (session != null && trackModesIncludesCookie) {
Cookie cookie = ApplicationSessionCookieConfig.createSessionCookie(context, session.getIdInternal(), isSecure());
response.addSessionCookieInternal(cookie);
}
if (session == null) {
return null;
}
session.access();
return session;
}
use of org.apache.catalina.Manager in project tomcat by apache.
the class Request method changeSessionId.
@Override
public String changeSessionId() {
Session session = this.getSessionInternal(false);
if (session == null) {
throw new IllegalStateException(sm.getString("coyoteRequest.changeSessionId"));
}
Manager manager = this.getContext().getManager();
String newSessionId = manager.rotateSessionId(session);
this.changeSessionId(newSessionId);
return newSessionId;
}
Aggregations