當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLSessionContext.setSessionCacheSize方法代碼示例

本文整理匯總了Java中javax.net.ssl.SSLSessionContext.setSessionCacheSize方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLSessionContext.setSessionCacheSize方法的具體用法?Java SSLSessionContext.setSessionCacheSize怎麽用?Java SSLSessionContext.setSessionCacheSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.SSLSessionContext的用法示例。


在下文中一共展示了SSLSessionContext.setSessionCacheSize方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configureSessionContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
    int sessionCacheSize;
    if (endpoint.getSessionCacheSize() != null) {
        sessionCacheSize = Integer.parseInt(
                endpoint.getSessionCacheSize());
    } else {
        sessionCacheSize = defaultSessionCacheSize;
    }

    int sessionTimeout;
    if (endpoint.getSessionTimeout() != null) {
        sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
    } else {
        sessionTimeout = defaultSessionTimeout;
    }

    sslSessionContext.setSessionCacheSize(sessionCacheSize);
    sslSessionContext.setSessionTimeout(sessionTimeout);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:JSSESocketFactory.java

示例2: configureSessionContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
	int sessionCacheSize;
	if (endpoint.getSessionCacheSize() != null) {
		sessionCacheSize = Integer.parseInt(endpoint.getSessionCacheSize());
	} else {
		sessionCacheSize = defaultSessionCacheSize;
	}

	int sessionTimeout;
	if (endpoint.getSessionTimeout() != null) {
		sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
	} else {
		sessionTimeout = defaultSessionTimeout;
	}

	sslSessionContext.setSessionCacheSize(sessionCacheSize);
	sslSessionContext.setSessionTimeout(sessionTimeout);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:20,代碼來源:JSSESocketFactory.java

示例3: configureSessionContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
    int sessionCacheSize;
    if (endpoint.getSessionCacheSize() != null) {
        sessionCacheSize = Integer.parseInt(
                endpoint.getSessionCacheSize());
    } else {
        sessionCacheSize = defaultSessionCacheSize;
    }
    
    int sessionTimeout;
    if (endpoint.getSessionTimeout() != null) {
        sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
    } else {
        sessionTimeout = defaultSessionTimeout;
    }

    sslSessionContext.setSessionCacheSize(sessionCacheSize);
    sslSessionContext.setSessionTimeout(sessionTimeout);
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:21,代碼來源:JSSESocketFactory.java

示例4: assertNoConnectSetSessionCacheSizeBehavior

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
private static void assertNoConnectSetSessionCacheSizeBehavior(
        int expectedDefault, SSLSessionContext s) {
    try {
        s.setSessionCacheSize(-1);
        fail();
    } catch (IllegalArgumentException expected) {
        // Ignored.
    }
    assertEquals(expectedDefault, s.getSessionCacheSize());
    s.setSessionCacheSize(1);
    assertEquals(1, s.getSessionCacheSize());
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:13,代碼來源:SSLSessionContextTest.java

示例5: newSSLContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
private static SSLContext newSSLContext(X509Certificate[] trustCertCollection,
        TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain, PrivateKey key,
        String keyPassword, KeyManagerFactory keyManagerFactory, long sessionCacheSize,
        long sessionTimeout) throws SSLException {
    if (key == null && keyManagerFactory == null) {
        throw new NullPointerException("key, keyManagerFactory");
    }

    try {
        if (trustCertCollection != null) {
            trustManagerFactory = buildTrustManagerFactory(trustCertCollection,
                    trustManagerFactory);
        }
        if (key != null) {
            keyManagerFactory = buildKeyManagerFactory(keyCertChain, key, keyPassword,
                    keyManagerFactory);
        }

        // Initialize the SSLContext to work with our key managers.
        SSLContext ctx = SSLContext.getInstance(PROTOCOL);
        ctx.init(keyManagerFactory.getKeyManagers(),
                trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
                null);

        SSLSessionContext sessCtx = ctx.getServerSessionContext();
        if (sessionCacheSize > 0) {
            sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
        }
        if (sessionTimeout > 0) {
            sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
        }
        return ctx;
    } catch (Exception e) {
        if (e instanceof SSLException) {
            throw (SSLException) e;
        }
        throw new SSLException("failed to initialize the server-side SSL context", e);
    }
}
 
開發者ID:generallycloud,項目名稱:baseio,代碼行數:40,代碼來源:JdkSslServerContext.java

示例6: JdkSslServerContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
/**
 * Creates a new instance.
 * @param trustCertChainFile an X.509 certificate chain file in PEM format.
 *                      This provides the certificate chains used for mutual authentication.
 *                      {@code null} to use the system default
 * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
 *                            that verifies the certificates sent from clients.
 *                            {@code null} to use the default or the results of parsing {@code trustCertChainFile}
 * @param keyCertChainFile an X.509 certificate chain file in PEM format
 * @param keyFile a PKCS#8 private key file in PEM format
 * @param keyPassword the password of the {@code keyFile}.
 *                    {@code null} if it's not password-protected.
 * @param keyManagerFactory the {@link KeyManagerFactory} that provides the {@link KeyManager}s
 *                          that is used to encrypt data being sent to clients.
 *                          {@code null} to use the default or the results of parsing
 *                          {@code keyCertChainFile} and {@code keyFile}.
 * @param ciphers the cipher suites to enable, in the order of preference.
 *                {@code null} to use the default cipher suites.
 * @param cipherFilter a filter to apply over the supplied list of ciphers
 *                Only required if {@code provider} is {@link SslProvider#JDK}
 * @param apn Application Protocol Negotiator object.
 * @param sessionCacheSize the size of the cache used for storing SSL session objects.
 *                         {@code 0} to use the default value.
 * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
 *                       {@code 0} to use the default value.
 */
public JdkSslServerContext(File trustCertChainFile, TrustManagerFactory trustManagerFactory,
        File keyCertChainFile, File keyFile, String keyPassword, KeyManagerFactory keyManagerFactory,
        Iterable<String> ciphers, CipherSuiteFilter cipherFilter, JdkApplicationProtocolNegotiator apn,
        long sessionCacheSize, long sessionTimeout) throws SSLException {
    super(ciphers, cipherFilter, apn);
    if (keyFile == null && keyManagerFactory == null) {
        throw new NullPointerException("keyFile, keyManagerFactory");
    }

    try {
        if (trustCertChainFile != null) {
            trustManagerFactory = buildTrustManagerFactory(trustCertChainFile, trustManagerFactory);
        }
        if (keyFile != null) {
            keyManagerFactory = buildKeyManagerFactory(keyCertChainFile, keyFile, keyPassword, keyManagerFactory);
        }

        // Initialize the SSLContext to work with our key managers.
        ctx = SSLContext.getInstance(PROTOCOL);
        ctx.init(keyManagerFactory.getKeyManagers(),
                 trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
                 null);

        SSLSessionContext sessCtx = ctx.getServerSessionContext();
        if (sessionCacheSize > 0) {
            sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
        }
        if (sessionTimeout > 0) {
            sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
        }
    } catch (Exception e) {
        throw new SSLException("failed to initialize the server-side SSL context", e);
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:61,代碼來源:JdkSslServerContext.java

示例7: JdkSslClientContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
/**
 * Creates a new instance.
 * @param trustCertChainFile an X.509 certificate chain file in PEM format.
 *                      {@code null} to use the system default
 * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
 *                            that verifies the certificates sent from servers.
 *                            {@code null} to use the default or the results of parsing {@code trustCertChainFile}
 * @param keyCertChainFile an X.509 certificate chain file in PEM format.
 *                      This provides the public key for mutual authentication.
 *                      {@code null} to use the system default
 * @param keyFile a PKCS#8 private key file in PEM format.
 *                      This provides the private key for mutual authentication.
 *                      {@code null} for no mutual authentication.
 * @param keyPassword the password of the {@code keyFile}.
 *                    {@code null} if it's not password-protected.
 *                    Ignored if {@code keyFile} is {@code null}.
 * @param keyManagerFactory the {@link KeyManagerFactory} that provides the {@link KeyManager}s
 *                          that is used to encrypt data being sent to servers.
 *                          {@code null} to use the default or the results of parsing
 *                          {@code keyCertChainFile} and {@code keyFile}.
 * @param ciphers the cipher suites to enable, in the order of preference.
 *                {@code null} to use the default cipher suites.
 * @param cipherFilter a filter to apply over the supplied list of ciphers
 * @param apn Application Protocol Negotiator object.
 * @param sessionCacheSize the size of the cache used for storing SSL session objects.
 *                         {@code 0} to use the default value.
 * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
 *                       {@code 0} to use the default value.
 */
public JdkSslClientContext(File trustCertChainFile, TrustManagerFactory trustManagerFactory,
        File keyCertChainFile, File keyFile, String keyPassword, KeyManagerFactory keyManagerFactory,
        Iterable<String> ciphers, CipherSuiteFilter cipherFilter, JdkApplicationProtocolNegotiator apn,
        long sessionCacheSize, long sessionTimeout) throws SSLException {
    super(ciphers, cipherFilter, apn);

    try {
        if (trustCertChainFile != null) {
            trustManagerFactory = buildTrustManagerFactory(trustCertChainFile, trustManagerFactory);
        }
        if (keyFile != null) {
            keyManagerFactory = buildKeyManagerFactory(keyCertChainFile, keyFile, keyPassword, keyManagerFactory);
        }
        ctx = SSLContext.getInstance(PROTOCOL);
        ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
                 trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
                 null);

        SSLSessionContext sessCtx = ctx.getClientSessionContext();
        if (sessionCacheSize > 0) {
            sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
        }
        if (sessionTimeout > 0) {
            sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
        }
    } catch (Exception e) {
        throw new SSLException("failed to initialize the client-side SSL context", e);
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:59,代碼來源:JdkSslClientContext.java

示例8: test_sessionCacheSize

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
/**
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 * @tests javax.net.ssl.SSLSessionContex#getSessionCacheSize()
 * @tests javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getSessionCacheSize",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "setSessionCacheSize",
        args = {int.class}
    )
})
public final void test_sessionCacheSize() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, null, null);
    SSLSessionContext sc = context
            .getClientSessionContext();
    sc.setSessionCacheSize(10);
    assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
    sc.setSessionCacheSize(5);
    assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());

    try {
        sc.setSessionCacheSize(-1);
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException iae) {
        //expected
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:38,代碼來源:SSLSessionContextTest.java

示例9: assertNoConnectSetSessionCacheSizeBehavior

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
private static void assertNoConnectSetSessionCacheSizeBehavior(int expectedDefault,
                                                               SSLSessionContext s) {
    try {
        s.setSessionCacheSize(-1);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(expectedDefault, s.getSessionCacheSize());
    s.setSessionCacheSize(1);
    assertEquals(1, s.getSessionCacheSize());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:12,代碼來源:SSLSessionContextTest.java

示例10: JdkSslServerContext

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
/**
 * Creates a new instance.
 *
 * @param trustCertChainFile an X.509 certificate chain file in PEM format.
 *        This provides the certificate chains used for mutual authentication.
 *        {@code null} to use the system default
 * @param trustManagerFactory the {@link TrustManagerFactory} that provides the
 *        {@link TrustManager}s
 *        that verifies the certificates sent from clients.
 *        {@code null} to use the default or the results of parsing {@code trustCertChainFile}
 * @param keyCertChainFile an X.509 certificate chain file in PEM format
 * @param keyFile a PKCS#8 private key file in PEM format
 * @param keyPassword the password of the {@code keyFile}.
 *        {@code null} if it's not password-protected.
 * @param keyManagerFactory the {@link KeyManagerFactory} that provides the {@link KeyManager}s
 *        that is used to encrypt data being sent to clients.
 *        {@code null} to use the default or the results of parsing
 *        {@code keyCertChainFile} and {@code keyFile}.
 * @param ciphers the cipher suites to enable, in the order of preference.
 *        {@code null} to use the default cipher suites.
 * @param cipherFilter a filter to apply over the supplied list of ciphers
 *        Only required if {@code provider} is {@link SslProvider#JDK}
 * @param apn Application Protocol Negotiator object.
 * @param sessionCacheSize the size of the cache used for storing SSL session objects.
 *        {@code 0} to use the default value.
 * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
 *        {@code 0} to use the default value.
 */
public JdkSslServerContext(final File trustCertChainFile,
    final File keyCertChainFile, final File keyFile, final String keyPassword,
    final long sessionCacheSize, final long sessionTimeout) throws SSLException {

  try {
    TrustManagerFactory trustManagerFactory = null;
    if (trustCertChainFile != null) {
      trustManagerFactory = buildTrustManagerFactory(trustCertChainFile, trustManagerFactory);
    }
    KeyManagerFactory keyManagerFactory = buildKeyManagerFactory(keyCertChainFile, keyFile,
        keyPassword);

    // Initialize the SSLContext to work with our key managers.
    ctx = SSLContext.getInstance(PROTOCOL);
    ctx.init(keyManagerFactory.getKeyManagers(),
        trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
        null);

    SSLSessionContext sessCtx = ctx.getServerSessionContext();
    if (sessionCacheSize > 0) {
      sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
    }
    if (sessionTimeout > 0) {
      sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
    }
  } catch (Exception e) {
    throw new SSLException("failed to initialize the server-side SSL context", e);
  }
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:58,代碼來源:JdkSslServerContext.java

示例11: testSessionSize

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
@Test
public void testSessionSize() throws Exception {
    final int port1 = SSLTestUtils.PORT;
    final int port2 = SSLTestUtils.SECONDARY_PORT;

    try (
            ServerSocket serverSocket1 = SSLTestUtils.createServerSocket(port1);
            ServerSocket serverSocket2 = SSLTestUtils.createServerSocket(port2)
    ) {

        final Thread acceptThread1 = startServer(serverSocket1);
        final Thread acceptThread2 = startServer(serverSocket2);
        SSLContext clientContext = SSLTestUtils.createClientSSLContext("openssl.TLSv1");

        final SSLSessionContext clientSession = clientContext.getClientSessionContext();

        byte[] host1SessionId = connectAndWrite(clientContext, port1);
        byte[] host2SessionId = connectAndWrite(clientContext, port2);

        // No cache limit was set, id's should be identical
        Assert.assertArrayEquals(host1SessionId, connectAndWrite(clientContext, port1));
        Assert.assertArrayEquals(host2SessionId, connectAndWrite(clientContext, port2));

        // Set the cache size to 1
        clientSession.setSessionCacheSize(1);
        // The second session id should be the one kept as it was the last one used
        Assert.assertArrayEquals(host2SessionId, connectAndWrite(clientContext, port2));
        // Connect again to the first host, this should not match the initial session id for the first host
        byte[] nextId = connectAndWrite(clientContext, port1);
        Assert.assertFalse(Arrays.equals(host1SessionId, nextId));
        // Once more connect to the first host and this should match the previous session id
        Assert.assertArrayEquals(nextId, connectAndWrite(clientContext, port1));
        // Connect to the second host which should be purged at this point
        Assert.assertFalse(Arrays.equals(nextId, connectAndWrite(clientContext, port2)));

        // Reset the cache limit and ensure both sessions are cached
        clientSession.setSessionCacheSize(0);
        host1SessionId = connectAndWrite(clientContext, port1);
        host2SessionId = connectAndWrite(clientContext, port2);

        // No cache limit was set, id's should be identical
        Assert.assertArrayEquals(host1SessionId, connectAndWrite(clientContext, port1));
        Assert.assertArrayEquals(host2SessionId, connectAndWrite(clientContext, port2));

        serverSocket1.close();
        serverSocket2.close();
        acceptThread1.join();
        acceptThread2.join();
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-openssl,代碼行數:51,代碼來源:ClientSessionTest.java

示例12: test_SSLSessionContext_setSessionCacheSize_dynamic

import javax.net.ssl.SSLSessionContext; //導入方法依賴的package包/類
public void test_SSLSessionContext_setSessionCacheSize_dynamic() {
    TestSSLContext c = TestSSLContext.create();
    SSLSessionContext client = c.clientContext.getClientSessionContext();
    SSLSessionContext server = c.serverContext.getServerSessionContext();

    String[] supportedCipherSuites = c.serverSocket.getSupportedCipherSuites();
    c.serverSocket.setEnabledCipherSuites(supportedCipherSuites);
    LinkedList<String> uniqueCipherSuites
        = new LinkedList(Arrays.asList(supportedCipherSuites));
    // only use RSA cipher suites which will work with our TrustProvider
    Iterator<String> i = uniqueCipherSuites.iterator();
    while (i.hasNext()) {
        String cipherSuite = i.next();

        // Certificate key length too long for export ciphers
        if (cipherSuite.startsWith("SSL_RSA_EXPORT_")) {
            i.remove();
            continue;
        }

        if (cipherSuite.startsWith("SSL_RSA_")) {
            continue;
        }
        if (cipherSuite.startsWith("TLS_RSA_")) {
            continue;
        }
        if (cipherSuite.startsWith("TLS_DHE_RSA_")) {
            continue;
        }
        if (cipherSuite.startsWith("SSL_DHE_RSA_")) {
            continue;
        }
        i.remove();
    }

    /*
     * having more than 3 uniqueCipherSuites is a test
     * requirement, not a requirement of the interface or
     * implementation. It simply allows us to make sure that we
     * will not get a cached session ID since we'll have to
     * renegotiate a new session due to the new cipher suite
     * requirement. even this test only really needs three if it
     * reused the unique cipher suites every time it resets the
     * session cache.
     */
    assertTrue(uniqueCipherSuites.size() >= 3);
    String cipherSuite1 = uniqueCipherSuites.get(0);
    String cipherSuite2 = uniqueCipherSuites.get(1);
    String cipherSuite3 = uniqueCipherSuites.get(2);

    TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null);
    assertSSLSessionContextSize(1, c);
    TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null);
    assertSSLSessionContextSize(2, c);
    TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null);
    assertSSLSessionContextSize(3, c);

    client.setSessionCacheSize(1);
    server.setSessionCacheSize(1);
    assertEquals(1, client.getSessionCacheSize());
    assertEquals(1, server.getSessionCacheSize());
    assertSSLSessionContextSize(1, c);
    TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null);
    assertSSLSessionContextSize(1, c);

    client.setSessionCacheSize(2);
    server.setSessionCacheSize(2);
    TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null);
    assertSSLSessionContextSize(2, c);
    TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null);
    assertSSLSessionContextSize(2, c);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:73,代碼來源:SSLSessionContextTest.java


注:本文中的javax.net.ssl.SSLSessionContext.setSessionCacheSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。