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


Java SSLSessionContext類代碼示例

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


SSLSessionContext類屬於javax.net.ssl包,在下文中一共展示了SSLSessionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getSessionContext

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * For server sessions, this returns the set of sessions which
 * are currently valid in this process.  For client sessions,
 * this returns null.
 */
@Override
public SSLSessionContext getSessionContext() {
    /*
     * An interim security policy until we can do something
     * more specific in 1.2. Only allow trusted code (code which
     * can set system properties) to get an
     * SSLSessionContext. This is to limit the ability of code to
     * look up specific sessions or enumerate over them. Otherwise,
     * code can only get session objects from successful SSL
     * connections which implies that they must have had permission
     * to make the network connection in the first place.
     */
    SecurityManager sm;
    if ((sm = System.getSecurityManager()) != null) {
        sm.checkPermission(new SSLPermission("getSSLSessionContext"));
    }

    return context;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SSLSessionImpl.java

示例3: clearSessionCache

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}.
 *
 * @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated
 * @param remoteAddress  associated with sessions to invalidate
 */
private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) {
    final String hostName = remoteAddress.getHostName();
    final int port = remoteAddress.getPort();
    final Enumeration<byte[]> ids = sessionContext.getIds();

    if (ids == null) {
        return;
    }

    while (ids.hasMoreElements()) {
        final byte[] id = ids.nextElement();
        final SSLSession session = sessionContext.getSession(id);
        if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName)
                && session.getPeerPort() == port) {
            session.invalidate();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Invalidated session " + session);
            }
        }
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:28,代碼來源:SdkTLSSocketFactory.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:how2j,項目名稱:lazycat,代碼行數:20,代碼來源:JSSESocketFactory.java

示例5: test_SSLContext_getServerSessionContext

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Test
public void test_SSLContext_getServerSessionContext() throws Exception {
    for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
        SSLContext sslContext = SSLContext.getInstance(protocol);
        SSLSessionContext sessionContext = sslContext.getServerSessionContext();
        assertNotNull(sessionContext);

        if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
            assertSame(
                    SSLContext.getInstance(protocol).getServerSessionContext(), sessionContext);
        } else {
            assertNotSame(
                    SSLContext.getInstance(protocol).getServerSessionContext(), sessionContext);
        }
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:17,代碼來源:SSLContextTest.java

示例6: test_SSLContext_getClientSessionContext

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Test
public void test_SSLContext_getClientSessionContext() throws Exception {
    for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
        SSLContext sslContext = SSLContext.getInstance(protocol);
        SSLSessionContext sessionContext = sslContext.getClientSessionContext();
        assertNotNull(sessionContext);

        if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
            assertSame(
                    SSLContext.getInstance(protocol).getClientSessionContext(), sessionContext);
        } else {
            assertNotSame(
                    SSLContext.getInstance(protocol).getClientSessionContext(), sessionContext);
        }
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:17,代碼來源:SSLContextTest.java

示例7: test_getSession

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 * @tests javax.net.ssl.SSLSessionContex#getSession(byte[] sessionId)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getSession",
    args = {byte[].class}
)
public final void test_getSession() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, null, null);
    SSLSessionContext sc = context
            .getClientSessionContext();
    try {
        sc.getSession(null);
    } catch (NullPointerException e) {
        // expected
    }
    assertNull(sc.getSession(new byte[5]));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:24,代碼來源:SSLSessionContextTest.java

示例8: getSessionContext

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * For server sessions, this returns the set of sessions which
 * are currently valid in this process.  For client sessions,
 * this returns null.
 */
public SSLSessionContext getSessionContext() {
    /*
     * An interim security policy until we can do something
     * more specific in 1.2. Only allow trusted code (code which
     * can set system properties) to get an
     * SSLSessionContext. This is to limit the ability of code to
     * look up specific sessions or enumerate over them. Otherwise,
     * code can only get session objects from successful SSL
     * connections which implies that they must have had permission
     * to make the network connection in the first place.
     */
    SecurityManager sm;
    if ((sm = System.getSecurityManager()) != null) {
        sm.checkPermission(new SSLPermission("getSSLSessionContext"));
    }

    return context;
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:24,代碼來源:SSLSessionImpl.java

示例9: findSessionToResume

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
private SSLSessionImpl findSessionToResume() {
    String host;
    int port;
    if (engineOwner != null) {
        host = engineOwner.getPeerHost();
        port = engineOwner.getPeerPort();
    } else {
        host = socketOwner.getInetAddress().getHostName();
        port = socketOwner.getPort();
    }
    if (host == null || port == -1) {
        return null; // starts new session
    }
    
    byte[] id;
    SSLSession ses;
    SSLSessionContext context = parameters.getClientSessionContext();
    for (Enumeration<?> en = context.getIds(); en.hasMoreElements();) {
        id = (byte[])en.nextElement();
        ses = context.getSession(id);
        if (host.equals(ses.getPeerHost()) && port == ses.getPeerPort()) {
            return (SSLSessionImpl)((SSLSessionImpl)ses).clone(); // resume
        }            
    }
    return null; // starts new session
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:27,代碼來源:ClientHandshakeImpl.java

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

示例11: findSessionToResume

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
private SSLSessionImpl findSessionToResume() {
    String host;
    int port;
    if (engineOwner != null) {
        host = engineOwner.getPeerHost();
        port = engineOwner.getPeerPort();
    } else {
        host = socketOwner.getInetAddress().getHostName();
        port = socketOwner.getPort();
    }
    if (host == null || port == -1) {
        return null; // starts new session
    }
    
    byte[] id;
    SSLSession ses;
    SSLSessionContext context = parameters.getClientSessionContext();
    for (Enumeration en = context.getIds(); en.hasMoreElements();) {
        id = (byte[])en.nextElement();
        ses = context.getSession(id);
        if (host.equals(ses.getPeerHost()) && port == ses.getPeerPort()) {
            return (SSLSessionImpl)((SSLSessionImpl)ses).clone(); // resume
        }            
    }
    return null; // starts new session
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:27,代碼來源:ClientHandshakeImpl.java

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

示例13: init

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * Reads the keystore and initializes the SSL socket factory.
 */
void init() throws IOException {
	try {

		String clientAuthStr = endpoint.getClientAuth();
		if ("true".equalsIgnoreCase(clientAuthStr) || "yes".equalsIgnoreCase(clientAuthStr)) {
			requireClientAuth = true;
		} else if ("want".equalsIgnoreCase(clientAuthStr)) {
			wantClientAuth = true;
		}

		SSLContext context = createSSLContext();
		context.init(getKeyManagers(), getTrustManagers(), null);

		// Configure SSL session cache
		SSLSessionContext sessionContext = context.getServerSessionContext();
		if (sessionContext != null) {
			configureSessionContext(sessionContext);
		}

		// create proxy
		sslProxy = context.getServerSocketFactory();

		// Determine which cipher suites to enable
		enabledCiphers = getEnableableCiphers(context);
		enabledProtocols = getEnableableProtocols(context);

		allowUnsafeLegacyRenegotiation = "true".equals(endpoint.getAllowUnsafeLegacyRenegotiation());

		// Check the SSL config is OK
		checkConfig();

	} catch (Exception e) {
		if (e instanceof IOException)
			throw (IOException) e;
		throw new IOException(e.getMessage(), e);
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:41,代碼來源:JSSESocketFactory.java

示例14: setClientSessionCache

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * Sets the client-side persistent cache to be used by the context.
 */
public static void setClientSessionCache(SSLContext context, SSLClientSessionCache cache) {
    SSLSessionContext clientContext = context.getClientSessionContext();
    if (!(clientContext instanceof ClientSessionContext)) {
        throw new IllegalArgumentException(
                "Not a conscrypt client context: " + clientContext.getClass().getName());
    }
    ((ClientSessionContext) clientContext).setPersistentCache(cache);
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:12,代碼來源:Conscrypt.java

示例15: setServerSessionCache

import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
 * Sets the server-side persistent cache to be used by the context.
 */
public static void setServerSessionCache(SSLContext context, SSLServerSessionCache cache) {
    SSLSessionContext serverContext = context.getServerSessionContext();
    if (!(serverContext instanceof ServerSessionContext)) {
        throw new IllegalArgumentException(
                "Not a conscrypt client context: " + serverContext.getClass().getName());
    }
    ((ServerSessionContext) serverContext).setPersistentCache(cache);
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:12,代碼來源:Conscrypt.java


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