当前位置: 首页>>代码示例>>Java>>正文


Java SSLSessionContext.setSessionTimeout方法代码示例

本文整理汇总了Java中javax.net.ssl.SSLSessionContext.setSessionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java SSLSessionContext.setSessionTimeout方法的具体用法?Java SSLSessionContext.setSessionTimeout怎么用?Java SSLSessionContext.setSessionTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.SSLSessionContext的用法示例。


在下文中一共展示了SSLSessionContext.setSessionTimeout方法的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: main

import javax.net.ssl.SSLSessionContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
//        try {
            SSLServerSocketFactory ssf =
                (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
            SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket();
            String[] protocols = ss.getSupportedProtocols();
            for (int i = 0; i < protocols.length; i++) {
//                try {
                    if (protocols[i].equals("SSLv2Hello")) {
                        continue;
                    }
                    SSLContext sslc = SSLContext.getInstance(protocols[i]);
                    SSLSessionContext sslsc = sslc.getServerSessionContext();
                    System.out.println("Protocol: " + protocols[i]);
                    sslsc.setSessionTimeout(Integer.MAX_VALUE);
                    int newtime = sslsc.getSessionTimeout();
                    if (newtime != Integer.MAX_VALUE) {
                        throw new Exception ("Expected timeout: " +
                            Integer.MAX_VALUE + ", got instead: " +
                            newtime);
                    }
//                } catch (Exception e) {
//                }
            }
//        } catch (Exception e) {
//            System.out.println(e);
//        }
        System.out.println("Finished");
    }
 
开发者ID:vicmarcal,项目名称:JAVA_UNIT,代码行数:30,代码来源:Timeout.java

示例4: 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

示例5: testSessionTimeout

import javax.net.ssl.SSLSessionContext; //导入方法依赖的package包/类
@Test
public void testSessionTimeout() 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 timeout was set, id's should be identical
        Assert.assertArrayEquals(host1SessionId, connectAndWrite(clientContext, port1));
        Assert.assertArrayEquals(host2SessionId, connectAndWrite(clientContext, port2));

        // Set the session timeout to 1 second and sleep for 2 to ensure the timeout works
        clientSession.setSessionTimeout(1);
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertFalse(Arrays.equals(host1SessionId, connectAndWrite(clientContext, port1)));
        Assert.assertFalse(Arrays.equals(host1SessionId, connectAndWrite(clientContext, port2)));

        serverSocket1.close();
        serverSocket2.close();
        acceptThread1.join();
        acceptThread2.join();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-openssl,代码行数:35,代码来源:ClientSessionTest.java

示例6: 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

示例7: configureSessionContext

import javax.net.ssl.SSLSessionContext; //导入方法依赖的package包/类
/**
 * Configures a {@link SSLSessionContext}, client or server, with the supplied session timeout.
 *
 * @param sessionContext the context to configure
 * @param sessionTimeout the timeout time period
 * @throws GeneralSecurityException if {@code sessionContext} is {@code null}
 */
protected void configureSessionContext(
    SSLSessionContext sessionContext, String sessionTimeout) throws GeneralSecurityException {
    
    int sessionTimeoutInt = Integer.parseInt(this.parsePropertyValue(sessionTimeout));
    
    if (sessionContext != null) {
        sessionContext.setSessionTimeout(sessionTimeoutInt);
    } else {
        throw new GeneralSecurityException(
                "The SSLContext does not support SSLSessionContext, "
                        + "but a session timeout is configured. Set sessionTimeout to null "
                        + "to avoid this error.");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:BaseSSLContextParameters.java

示例8: 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

示例9: 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

示例10: test_sessionTimeout

import javax.net.ssl.SSLSessionContext; //导入方法依赖的package包/类
/**
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 * @tests javax.net.ssl.SSLSessionContex#getSessionTimeout()
 * @tests javax.net.ssl.SSLSessionContex#setSessionTimeout(int seconds)
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getSessionTimeout",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "setSessionTimeout",
        args = {int.class}
    )
})
public final void test_sessionTimeout() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, null, null);
    SSLSessionContext sc = context
            .getClientSessionContext();
    sc.setSessionTimeout(100);
    assertEquals("100 wasn't returned", 100, sc.getSessionTimeout());
    sc.setSessionTimeout(5000);
    assertEquals("5000 wasn't returned", 5000, sc.getSessionTimeout());

    try {
        sc.setSessionTimeout(-1);
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException iae) {
        //expected
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:38,代码来源:SSLSessionContextTest.java

示例11: 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

示例12: trustAllHttpsCertificates

import javax.net.ssl.SSLSessionContext; //导入方法依赖的package包/类
private static void trustAllHttpsCertificates() throws Exception {
   // Create a trust manager that does not validate certificate chains:
   TrustManager[] trustAllCerts = new TrustManager[1];

   TrustManager tm = new TrustAllTrustManager();

   trustAllCerts[0] = tm;

   SSLContext sc = SSLContext.getInstance("SSL");

   SSLSessionContext sslsc = sc.getServerSessionContext();

   sslsc.setSessionTimeout(0);

   sc.init(null, trustAllCerts, null);

   HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:19,代码来源:VMwareUtil.java


注:本文中的javax.net.ssl.SSLSessionContext.setSessionTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。