Java Code Examples for org.apache.tomcat.util.compat.JreCompat#getInstance()

The following examples show how to use org.apache.tomcat.util.compat.JreCompat#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSSESocketFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Configures SSLEngine to honor cipher suites ordering based upon
 * endpoint configuration.
 *
 * @throws InvalidAlgorithmParameterException If the runtime JVM doesn't
 *         support this setting.
 */
protected void configureUseServerCipherSuitesOrder(SSLServerSocket socket) {
    String useServerCipherSuitesOrderStr = endpoint
            .getUseServerCipherSuitesOrder().trim();

    // Only use this feature if the user explicitly requested its use.
    if(!"".equals(useServerCipherSuitesOrderStr)) {
        boolean useServerCipherSuitesOrder =
                ("true".equalsIgnoreCase(useServerCipherSuitesOrderStr)
                        || "yes".equalsIgnoreCase(useServerCipherSuitesOrderStr));
        JreCompat jreCompat = JreCompat.getInstance();
        jreCompat.setUseServerCipherSuitesOrder(socket, useServerCipherSuitesOrder);
    }
}
 
Example 2
Source File: AbstractEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Configures SSLEngine to honor cipher suites ordering based upon
 * endpoint configuration.
 *
 * @throws InvalidAlgorithmParameterException If the runtime JVM doesn't
 *         support this setting.
 */
protected void configureUseServerCipherSuitesOrder(SSLEngine engine) {
    String useServerCipherSuitesOrderStr = this
            .getUseServerCipherSuitesOrder().trim();

    // Only use this feature if the user explicitly requested its use.
    if(!"".equals(useServerCipherSuitesOrderStr)) {
        boolean useServerCipherSuitesOrder =
                ("true".equalsIgnoreCase(useServerCipherSuitesOrderStr)
                        || "yes".equalsIgnoreCase(useServerCipherSuitesOrderStr));
        JreCompat jreCompat = JreCompat.getInstance();
        jreCompat.setUseServerCipherSuitesOrder(engine, useServerCipherSuitesOrder);
    }
}
 
Example 3
Source File: JSSESocketFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Configures SSLEngine to honor cipher suites ordering based upon
 * endpoint configuration.
 *
 * @throws InvalidAlgorithmParameterException If the runtime JVM doesn't
 *         support this setting.
 */
protected void configureUseServerCipherSuitesOrder(SSLServerSocket socket) {
    String useServerCipherSuitesOrderStr = endpoint
            .getUseServerCipherSuitesOrder().trim();

    // Only use this feature if the user explicitly requested its use.
    if(!"".equals(useServerCipherSuitesOrderStr)) {
        boolean useServerCipherSuitesOrder =
                ("true".equalsIgnoreCase(useServerCipherSuitesOrderStr)
                        || "yes".equalsIgnoreCase(useServerCipherSuitesOrderStr));
        JreCompat jreCompat = JreCompat.getInstance();
        jreCompat.setUseServerCipherSuitesOrder(socket, useServerCipherSuitesOrder);
    }
}
 
Example 4
Source File: AbstractEndpoint.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Configures SSLEngine to honor cipher suites ordering based upon
 * endpoint configuration.
 *
 * @throws InvalidAlgorithmParameterException If the runtime JVM doesn't
 *         support this setting.
 */
protected void configureUseServerCipherSuitesOrder(SSLEngine engine) {
    String useServerCipherSuitesOrderStr = this
            .getUseServerCipherSuitesOrder().trim();

    // Only use this feature if the user explicitly requested its use.
    if(!"".equals(useServerCipherSuitesOrderStr)) {
        boolean useServerCipherSuitesOrder =
                ("true".equalsIgnoreCase(useServerCipherSuitesOrderStr)
                        || "yes".equalsIgnoreCase(useServerCipherSuitesOrderStr));
        JreCompat jreCompat = JreCompat.getInstance();
        jreCompat.setUseServerCipherSuitesOrder(engine, useServerCipherSuitesOrder);
    }
}
 
Example 5
Source File: WebappClassLoaderBase.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void checkThreadLocalsForLeaks() {
    Thread[] threads = getThreads();

    try {
        // Make the fields in the Thread class that store ThreadLocals
        // accessible
        Field threadLocalsField =
            Thread.class.getDeclaredField("threadLocals");
        threadLocalsField.setAccessible(true);
        Field inheritableThreadLocalsField =
            Thread.class.getDeclaredField("inheritableThreadLocals");
        inheritableThreadLocalsField.setAccessible(true);
        // Make the underlying array of ThreadLoad.ThreadLocalMap.Entry objects
        // accessible
        Class<?> tlmClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap");
        Field tableField = tlmClass.getDeclaredField("table");
        tableField.setAccessible(true);
        Method expungeStaleEntriesMethod = tlmClass.getDeclaredMethod("expungeStaleEntries");
        expungeStaleEntriesMethod.setAccessible(true);

        for (int i = 0; i < threads.length; i++) {
            Object threadLocalMap;
            if (threads[i] != null) {

                // Clear the first map
                threadLocalMap = threadLocalsField.get(threads[i]);
                if (null != threadLocalMap){
                    expungeStaleEntriesMethod.invoke(threadLocalMap);
                    checkThreadLocalMapForLeaks(threadLocalMap, tableField);
                }

                // Clear the second map
                threadLocalMap =inheritableThreadLocalsField.get(threads[i]);
                if (null != threadLocalMap){
                    expungeStaleEntriesMethod.invoke(threadLocalMap);
                    checkThreadLocalMapForLeaks(threadLocalMap, tableField);
                }
            }
        }
    } catch (Throwable t) {
        JreCompat jreCompat = JreCompat.getInstance();
        if (jreCompat.isInstanceOfInaccessibleObjectException(t)) {
            // Must be running on Java 9 without the necessary command line
            // options.
            log.warn(sm.getString("webappClassLoader.addExportsThreadLocal"));
        } else {
            ExceptionUtils.handleThrowable(t);
            log.warn(sm.getString(
                    "webappClassLoader.checkThreadLocalsForLeaksFail",
                    getContextName()), t);
        }
    }
}