/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ((manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager) manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ( (manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager)manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
/** * Mark Request that processed at primary node with attribute * primaryIndicatorName * * @param request * @throws IOException */ protected void createPrimaryIndicator(Request request) throws IOException { String id = request.getRequestedSessionId(); if ((id != null) && (id.length() > 0)) { Manager manager = request.getContext().getManager(); Session session = manager.findSession(id); if (session instanceof ClusterSession) { ClusterSession cses = (ClusterSession) session; if (log.isDebugEnabled()) log.debug(sm.getString( "ReplicationValve.session.indicator", request.getContext().getName(),id, primaryIndicatorName, Boolean.valueOf(cses.isPrimarySession()))); request.setAttribute(primaryIndicatorName, cses.isPrimarySession()?Boolean.TRUE:Boolean.FALSE); } else { if (log.isDebugEnabled()) { if (session != null) { log.debug(sm.getString( "ReplicationValve.session.found", request.getContext().getName(),id)); } else { log.debug(sm.getString( "ReplicationValve.session.invalid", request.getContext().getName(),id)); } } } } }
/** * Create new Manager without add to cluster (comes with start the manager) * * @param name * Context Name of this manager * @see org.apache.catalina.Cluster#createManager(java.lang.String) * @see DeltaManager#start() */ @Override public synchronized Manager createManager(String name) { if (log.isDebugEnabled()) { log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName()); } ClusterManager manager = null; try { manager = managerTemplate.cloneFromTemplate(); manager.setName(name); } catch (Exception x) { log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x); manager = new org.apache.catalina.ha.session.DeltaManager(); } finally { if ( manager != null) manager.setCluster(this); } return manager; }
/** * Deregister the MBean for this * <code>Manager</code> object. * * @param manager The Manager to be managed * * @exception Exception if an MBean cannot be deregistered * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static void destroyMBean(Manager manager) throws Exception { String mname = createManagedName(manager); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, manager); if( mserver.isRegistered(oname) ) mserver.unregisterMBean(oname); }
@Override public void sessionEvent(SessionEvent event) { if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) { return; } Session session = event.getSession(); Manager manager = session.getManager(); if (manager == null) { return; } Context context = (Context) manager.getContainer(); Authenticator authenticator = context.getAuthenticator(); if (!(authenticator instanceof AuthenticatorBase)) { return; } SingleSignOn sso = ((AuthenticatorBase) authenticator).sso; if (sso == null) { return; } sso.sessionDestroyed(ssoId, session); }
/** * Return <code>true</code> if the session identifier included in this * request identifies a valid session. */ public boolean isRequestedSessionIdValid() { 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) { session = null; } if ((session != null) && session.isValid()) return (true); else return (false); }
/** * Create new Manager without add to cluster (comes with start the manager) * * @param name * Context Name of this manager * @see org.apache.catalina.Cluster#createManager(java.lang.String) * @see DeltaManager#start() */ @Override public synchronized Manager createManager(String name) { if (log.isDebugEnabled()) { log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName()); } ClusterManager manager = null; try { manager = managerTemplate.cloneFromTemplate(); manager.setName(name); } catch (Exception x) { log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x); manager = new org.apache.catalina.ha.session.DeltaManager(); } finally { if (manager != null) manager.setCluster(this); } return manager; }
/** * Create, register, and return an MBean for this * <code>Manager</code> object. * * @param manager The Manager to be managed * * @exception Exception if an MBean cannot be created or registered */ static DynamicMBean createMBean(Manager manager) throws Exception { String mname = createManagedName(manager); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(manager); ObjectName oname = createObjectName(domain, manager); if( mserver.isRegistered( oname )) { mserver.unregisterMBean(oname); } mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this <code>Manager</code> object. * * @param manager * The Manager to be managed * * @exception Exception * if an MBean cannot be deregistered * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static void destroyMBean(Manager manager) throws Exception { String mname = createManagedName(manager); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, manager); if (mserver.isRegistered(oname)) mserver.unregisterMBean(oname); }
/** * Create, register, and return an MBean for this * <code>Manager</code> object. * * @param manager The Manager to be managed * * @exception Exception if an MBean cannot be created or registered */ public static ModelMBean createMBean(Manager manager) throws Exception { String mname = createManagedName(manager); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ModelMBean mbean = managed.createMBean(manager); ObjectName oname = createObjectName(domain, manager); mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>Manager</code> object. * * @param manager The Manager to be managed * * @exception Exception if an MBean cannot be deregistered */ public static void destroyMBean(Manager manager) throws Exception { String mname = createManagedName(manager); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, manager); mserver.unregisterMBean(oname); }
/** * Is this an instance of the default <code>Manager</code> configuration, * with all-default properties? * * @param manager Manager to be tested */ private boolean isDefaultManager(Manager manager) { if (!(manager instanceof StandardManager)) { return (false); } StandardManager smanager = (StandardManager) manager; if ((smanager.getDebug() != 0) || !smanager.getPathname().equals("SESSIONS.ser") || (smanager.getCheckInterval() != 60) || !smanager.getRandomClass().equals("java.security.SecureRandom") || (smanager.getMaxActiveSessions() != -1) || !smanager.getAlgorithm().equals("MD5")) { return (false); } return (true); }
@Override public void registerManager(Manager manager) { if (!(manager instanceof ClusterManager)) { log.warn("Manager [ " + manager + "] does not implement ClusterManager, addition to cluster has been aborted."); return; } ClusterManager cmanager = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); }
@Override public void registerManager(Manager manager) { if (! (manager instanceof ClusterManager)) { log.warn("Manager [ " + manager + "] does not implement ClusterManager, addition to cluster has been aborted."); return; } ClusterManager cmanager = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); }
/** * Construct a new Session associated with the specified Manager. * * @param manager * The manager with which this Session is associated */ public StandardSession(Manager manager) { super(); this.manager = manager; // Initialize access count if (ACTIVITY_CHECK) { accessCount = new AtomicInteger(); } }
/** * Set the Manager with which this Store is associated. * * @param manager * The newly associated Manager */ @Override public void setManager(Manager manager) { Manager oldManager = this.manager; this.manager = manager; support.firePropertyChange("manager", oldManager, this.manager); }
@Bean public TomcatMetrics metrics(ApplicationContext applicationContext) { Manager manager = null; if (applicationContext instanceof EmbeddedWebApplicationContext) { manager = getManagerFromContext((EmbeddedWebApplicationContext) applicationContext); } return new TomcatMetrics(manager, Collections.emptyList()); }
private Manager getManagerFromContext(EmbeddedWebApplicationContext applicationContext) { EmbeddedServletContainer embeddedServletContainer = applicationContext.getEmbeddedServletContainer(); if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) { return getManagerFromContainer((TomcatEmbeddedServletContainer) embeddedServletContainer); } return null; }
private Manager getManagerFromContainer(TomcatEmbeddedServletContainer servletContainer) { for (Container container : servletContainer.getTomcat().getHost().findChildren()) { if (container instanceof Context) { return ((Context) container).getManager(); } } return null; }
/** * get jvmroute from engine * * @param request current request * @return return jvmRoute from ManagerBase or null */ protected String getLocalJvmRoute(Request request) { Manager manager = getManager(request); if(manager instanceof ManagerBase) return ((ManagerBase) manager).getJvmRoute(); return null ; }
/** * get ClusterManager * * @param request current request * @return manager or null */ protected Manager getManager(Request request) { Manager manager = request.getContext().getManager(); if (log.isDebugEnabled()) { if(manager != null) log.debug(sm.getString("jvmRoute.foundManager", manager, request.getContext().getName())); else log.debug(sm.getString("jvmRoute.notFoundManager", request.getContext().getName())); } return manager; }
/** * get ClusterManager * * @param request * current request * @return manager or null */ protected Manager getManager(Request request) { Manager manager = request.getContext().getManager(); if (log.isDebugEnabled()) { if (manager != null) log.debug(sm.getString("jvmRoute.foundManager", manager, request.getContext().getName())); else log.debug(sm.getString("jvmRoute.notFoundManager", request.getContext().getName())); } return manager; }
/** * Remove an application from cluster replication bus. * * @see org.apache.catalina.Cluster#removeManager(Manager) */ @Override public void removeManager(Manager manager) { if (manager != null && manager instanceof ClusterManager ) { ClusterManager cmgr = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT,manager); managers.remove(getManagerName(cmgr.getName(),manager)); cmgr.setCluster(null); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager); } }
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) { if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) { String path = null; if (cn != null) { path = cn.getPath(); } throw new IllegalArgumentException(smClient.getString( "managerServlet.invalidPath", RequestUtil.filter(path))); } Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( "managerServlet.noContext", RequestUtil.filter(cn.getDisplayName()))); } Manager manager = ctxt.getManager(); List<Session> sessions = new ArrayList<Session>(); sessions.addAll(Arrays.asList(manager.findSessions())); if (manager instanceof DistributedManager && showProxySessions) { // Add dummy proxy sessions Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull(); // Remove active (primary and backup) session IDs from full list for (Session session : sessions) { sessionIds.remove(session.getId()); } // Left with just proxy sessions - add them for (String sessionId : sessionIds) { sessions.add(new DummyProxySession(sessionId)); } } return sessions; }
/** * Return the Manager with which this Container is associated. If there is * no associated Manager, return the Manager associated with our parent * Container (if any); otherwise return <code>null</code>. */ @Override public Manager getManager() { if (manager != null) return (manager); if (parent != null) return (parent.getManager()); return (null); }
/** * Set the Manager with which this Store is associated. * * @param manager The newly associated Manager */ @Override public void setManager(Manager manager) { Manager oldManager = this.manager; this.manager = manager; support.firePropertyChange("manager", oldManager, this.manager); }
/** * Construct a new Session associated with the specified Manager. * * @param manager The manager with which this Session is associated */ public StandardSession(Manager manager) { super(); this.manager = manager; // Initialize access count if (ACTIVITY_CHECK) { accessCount = new AtomicInteger(); } }
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(); }
/** * 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(); } }
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) { if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) { String path = null; if (cn != null) { path = cn.getPath(); } throw new IllegalArgumentException( smClient.getString("managerServlet.invalidPath", RequestUtil.filter(path))); } Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException( smClient.getString("managerServlet.noContext", RequestUtil.filter(cn.getDisplayName()))); } Manager manager = ctxt.getManager(); List<Session> sessions = new ArrayList<Session>(); sessions.addAll(Arrays.asList(manager.findSessions())); if (manager instanceof DistributedManager && showProxySessions) { // Add dummy proxy sessions Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull(); // Remove active (primary and backup) session IDs from full list for (Session session : sessions) { sessionIds.remove(session.getId()); } // Left with just proxy sessions - add them for (String sessionId : sessionIds) { sessions.add(new DummyProxySession(sessionId)); } } return sessions; }
private Manager getSessionManager(Context context) { // Must be set for the persistent manager to work correctly. System.setProperty("org.apache.catalina.session.StandardSession.ACTIVITY_CHECK", "true"); PersistentManager manager = new PersistentManager(); StoreBase store; // Check if Migration has run and setup JDBC persistence if( !hibernateMigrationService.hasRunSystemMigration("com.tle.tomcat.migration.CreateTomcatSessionEntity") ) { // Use filestore until JDBC setup complete LOGGER.info("Setting up temporary file session store"); FileStore fileStore = new FileStore(); fileStore.setDirectory(System.getProperty("java.io.tmpdir")); store = fileStore; } else { LOGGER.info("Setting up JDBC session store"); JDBCStore jdbcStore = new JDBCStore(); jdbcStore.setConnectionURL(dataSourceService.getSystemUrl()); jdbcStore.setConnectionName(dataSourceService.getSystemUsername()); jdbcStore.setConnectionPassword(dataSourceService.getSystemPassword()); jdbcStore.setDriverName(dataSourceService.getDriverClass()); jdbcStore.setSessionTable("tomcat_sessions"); store = jdbcStore; } manager.setContext(context); manager.setProcessExpiresFrequency(3); // Every 30 seconds manager.setStore(store); // Persist immediately but leave in memory manager.setMaxIdleBackup(0); // Don't remove from memory for 30 minutes manager.setMaxIdleSwap((int) TimeUnit.MINUTES.toSeconds(30)); return manager; }
/** * @param name * @param manager * @return TODO */ @Override public String getManagerName(String name, Manager manager) { String clusterName = name; if (clusterName == null) clusterName = manager.getContainer().getName(); if (getContainer() instanceof Engine) { Context context = (Context) manager.getContainer(); Container host = context.getParent(); if (host instanceof Host && clusterName != null && !(clusterName.startsWith(host.getName() + "#"))) { clusterName = host.getName() + "#" + clusterName; } } return clusterName; }
/** * 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. */ 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) { session = null; } if ((session != null) && session.isValid()) { return (true); } else { return (false); } } else { return super.isRequestedSessionIdValid(); } }