Search in sources :

Example 1 with SessionIdGenerator

use of org.apache.catalina.SessionIdGenerator in project tomcat70 by apache.

the class ManagerBase method startInternal.

@Override
protected void startInternal() throws LifecycleException {
    // nulls.
    while (sessionCreationTiming.size() < TIMING_STATS_CACHE_SIZE) {
        sessionCreationTiming.add(null);
    }
    while (sessionExpirationTiming.size() < TIMING_STATS_CACHE_SIZE) {
        sessionExpirationTiming.add(null);
    }
    /* Create sessionIdGenerator if not explicitly configured */
    SessionIdGenerator sessionIdGenerator = getSessionIdGenerator();
    if (sessionIdGenerator == null) {
        sessionIdGenerator = new StandardSessionIdGenerator();
        setSessionIdGenerator(sessionIdGenerator);
    }
    if (sessionIdLength != SESSION_ID_LENGTH_UNSET) {
        sessionIdGenerator.setSessionIdLength(sessionIdLength);
    }
    sessionIdGenerator.setJvmRoute(getJvmRoute());
    if (sessionIdGenerator instanceof SessionIdGeneratorBase) {
        SessionIdGeneratorBase sig = (SessionIdGeneratorBase) sessionIdGenerator;
        sig.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
        sig.setSecureRandomClass(getSecureRandomClass());
        sig.setSecureRandomProvider(getSecureRandomProvider());
    }
    if (sessionIdGenerator instanceof Lifecycle) {
        ((Lifecycle) sessionIdGenerator).start();
    } else {
        // Force initialization of the random number generator
        if (log.isDebugEnabled())
            log.debug("Force random number initialization starting");
        sessionIdGenerator.generateSessionId();
        if (log.isDebugEnabled())
            log.debug("Force random number initialization completed");
    }
}
Also used : StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) Lifecycle(org.apache.catalina.Lifecycle) SessionIdGenerator(org.apache.catalina.SessionIdGenerator) StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) SessionIdGeneratorBase(org.apache.catalina.util.SessionIdGeneratorBase)

Example 2 with SessionIdGenerator

use of org.apache.catalina.SessionIdGenerator in project tomcat by apache.

the class PersistentManagerSF method storeChildren.

/**
 * Store the specified PersistentManager properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aManager
 *            PersistentManager whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aManager, StoreDescription parentDesc) throws Exception {
    if (aManager instanceof PersistentManager) {
        PersistentManager manager = (PersistentManager) aManager;
        // Store nested <Store> element
        Store store = manager.getStore();
        storeElement(aWriter, indent, store);
        // Store nested <SessionIdGenerator> element
        SessionIdGenerator sessionIdGenerator = manager.getSessionIdGenerator();
        if (sessionIdGenerator != null) {
            storeElement(aWriter, indent, sessionIdGenerator);
        }
    }
}
Also used : PersistentManager(org.apache.catalina.session.PersistentManager) Store(org.apache.catalina.Store) SessionIdGenerator(org.apache.catalina.SessionIdGenerator)

Example 3 with SessionIdGenerator

use of org.apache.catalina.SessionIdGenerator in project tomcat by apache.

the class ManagerBase method startInternal.

@Override
protected void startInternal() throws LifecycleException {
    // nulls.
    while (sessionCreationTiming.size() < TIMING_STATS_CACHE_SIZE) {
        sessionCreationTiming.add(null);
    }
    while (sessionExpirationTiming.size() < TIMING_STATS_CACHE_SIZE) {
        sessionExpirationTiming.add(null);
    }
    /* Create sessionIdGenerator if not explicitly configured */
    SessionIdGenerator sessionIdGenerator = getSessionIdGenerator();
    if (sessionIdGenerator == null) {
        sessionIdGenerator = new StandardSessionIdGenerator();
        setSessionIdGenerator(sessionIdGenerator);
    }
    sessionIdGenerator.setJvmRoute(getJvmRoute());
    if (sessionIdGenerator instanceof SessionIdGeneratorBase) {
        SessionIdGeneratorBase sig = (SessionIdGeneratorBase) sessionIdGenerator;
        sig.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
        sig.setSecureRandomClass(getSecureRandomClass());
        sig.setSecureRandomProvider(getSecureRandomProvider());
    }
    if (sessionIdGenerator instanceof Lifecycle) {
        ((Lifecycle) sessionIdGenerator).start();
    } else {
        // Force initialization of the random number generator
        if (log.isDebugEnabled()) {
            log.debug("Force random number initialization starting");
        }
        sessionIdGenerator.generateSessionId();
        if (log.isDebugEnabled()) {
            log.debug("Force random number initialization completed");
        }
    }
}
Also used : StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) Lifecycle(org.apache.catalina.Lifecycle) SessionIdGenerator(org.apache.catalina.SessionIdGenerator) StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) SessionIdGeneratorBase(org.apache.catalina.util.SessionIdGeneratorBase)

Example 4 with SessionIdGenerator

use of org.apache.catalina.SessionIdGenerator in project tomcat70 by apache.

the class ClusterManagerBase method clone.

protected void clone(ClusterManagerBase copy) {
    copy.setName("Clone-from-" + getName());
    copy.setMaxActiveSessions(getMaxActiveSessions());
    copy.setProcessExpiresFrequency(getProcessExpiresFrequency());
    copy.setNotifyListenersOnReplication(isNotifyListenersOnReplication());
    copy.setSessionAttributeNameFilter(getSessionAttributeNameFilter());
    copy.setSessionAttributeValueClassNameFilter(getSessionAttributeValueClassNameFilter());
    copy.setWarnOnSessionAttributeFilterFailure(getWarnOnSessionAttributeFilterFailure());
    copy.setSecureRandomClass(getSecureRandomClass());
    copy.setSecureRandomProvider(getSecureRandomProvider());
    copy.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
    if (getSessionIdGenerator() != null) {
        try {
            SessionIdGenerator copyIdGenerator = sessionIdGeneratorClass.newInstance();
            copyIdGenerator.setSessionIdLength(getSessionIdGenerator().getSessionIdLength());
            copyIdGenerator.setJvmRoute(getSessionIdGenerator().getJvmRoute());
            copy.setSessionIdGenerator(copyIdGenerator);
        } catch (InstantiationException e) {
        // Ignore
        } catch (IllegalAccessException e) {
        // Ignore
        }
    }
    copy.setRecordAllActions(isRecordAllActions());
}
Also used : SessionIdGenerator(org.apache.catalina.SessionIdGenerator)

Example 5 with SessionIdGenerator

use of org.apache.catalina.SessionIdGenerator in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sessionIdGeneratorIsConfiguredWithAttributesFromTheManager.

@Test
void sessionIdGeneratorIsConfiguredWithAttributesFromTheManager() {
    System.setProperty("jvmRoute", "test");
    try {
        TomcatServletWebServerFactory factory = getFactory();
        this.webServer = factory.getWebServer();
        this.webServer.start();
    } finally {
        System.clearProperty("jvmRoute");
    }
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    Context context = (Context) tomcat.getHost().findChildren()[0];
    SessionIdGenerator sessionIdGenerator = context.getManager().getSessionIdGenerator();
    assertThat(sessionIdGenerator).isInstanceOf(LazySessionIdGenerator.class);
    assertThat(sessionIdGenerator.getJvmRoute()).isEqualTo("test");
}
Also used : InitialContext(javax.naming.InitialContext) ServletContext(jakarta.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) SessionIdGenerator(org.apache.catalina.SessionIdGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

SessionIdGenerator (org.apache.catalina.SessionIdGenerator)7 Lifecycle (org.apache.catalina.Lifecycle)2 SessionIdGeneratorBase (org.apache.catalina.util.SessionIdGeneratorBase)2 StandardSessionIdGenerator (org.apache.catalina.util.StandardSessionIdGenerator)2 ServletContext (jakarta.servlet.ServletContext)1 InitialContext (javax.naming.InitialContext)1 Context (org.apache.catalina.Context)1 Manager (org.apache.catalina.Manager)1 Store (org.apache.catalina.Store)1 StandardContext (org.apache.catalina.core.StandardContext)1 PersistentManager (org.apache.catalina.session.PersistentManager)1 StandardManager (org.apache.catalina.session.StandardManager)1 Tomcat (org.apache.catalina.startup.Tomcat)1 Test (org.junit.jupiter.api.Test)1