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


Java SSLServerSocket.setNeedClientAuth方法代码示例

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


在下文中一共展示了SSLServerSocket.setNeedClientAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: finishServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Configure the SSLServerSocket based on this SocketCreator's settings.
 */
private void finishServerSocket(SSLServerSocket serverSocket) throws IOException {
  serverSocket.setUseClientMode(false);
  if (this.sslConfig.isRequireAuth()) {
    // serverSocket.setWantClientAuth( true );
    serverSocket.setNeedClientAuth(true);
  }
  serverSocket.setEnableSessionCreation(true);

  // restrict protocols
  String[] protocols = this.sslConfig.getProtocolsAsStringArray();
  if (!"any".equalsIgnoreCase(protocols[0])) {
    serverSocket.setEnabledProtocols(protocols);
  }
  // restrict ciphers
  String[] ciphers = this.sslConfig.getCiphersAsStringArray();
  if (!"any".equalsIgnoreCase(ciphers[0])) {
    serverSocket.setEnabledCipherSuites(ciphers);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:SocketCreator.java

示例2: configureServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Set the server socket configuration to our required
 * QOS values.
 *
 * A small experiment shows that setting either (want, need) parameter to either true or false sets the
 * other parameter to false.
 *
 * @param serverSocket
 *               The newly created SSLServerSocket.
 *
 * @throws IOException if server socket can't be configured
 */
private void configureServerSocket(SSLServerSocket serverSocket) throws IOException {
    // set the authentication value and cipher suite info.
    serverSocket.setEnabledCipherSuites(cipherSuites);
    if (clientAuthRequired) {
        serverSocket.setNeedClientAuth(true);
    } else if (clientAuthSupported) {
        serverSocket.setWantClientAuth(true);
    } else {
        serverSocket.setNeedClientAuth(false); //could set want with the same effect
    }
    serverSocket.setSoTimeout(SOCKET_TIMEOUT_MS);

    if (log.isDebugEnabled()) {
        log.debug("Created SSL server socket on port " + serverSocket.getLocalPort());
        log.debug("    client authentication " + (clientAuthSupported ? "SUPPORTED" : "UNSUPPORTED"));
        log.debug("    client authentication " + (clientAuthRequired ? "REQUIRED" : "OPTIONAL"));
        log.debug("    cipher suites:");

        for (int i = 0; i < cipherSuites.length; i++) {
            log.debug("    " + cipherSuites[i]);
        }
    }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:36,代码来源:SocketFactory.java

示例3: doServerSide

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf = getSSLServerSF();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslssf.createServerSocket(serverPort);

    // require client authentication.
    sslServerSocket.setNeedClientAuth(true);

    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    InputStream sslIS = sslSocket.getInputStream();
    OutputStream sslOS = sslSocket.getOutputStream();

    sslIS.read();
    sslOS.write('A');
    sslOS.flush();

    sslSocket.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:EmptyCertificateAuthorities.java

示例4: newSslServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public SSLServerSocket newSslServerSocket(String host,int port,int backlog) throws IOException {
    SSLServerSocketFactory factory = sslContext.getServerSocketFactory();

    SSLServerSocket socket = 
        (SSLServerSocket) (host==null ?
      factory.createServerSocket(port, backlog):
      factory.createServerSocket(port, backlog, InetAddress.getByName(host)));

    if (sslConfig.getWantClientAuth())
        socket.setWantClientAuth(sslConfig.getWantClientAuth());
    if (sslConfig.getNeedClientAuth())
        socket.setNeedClientAuth(sslConfig.getNeedClientAuth());

    socket.setEnabledCipherSuites(selectCipherSuites(socket.getEnabledCipherSuites(),
			 socket.getSupportedCipherSuites()));
    socket.setEnabledProtocols(selectProtocols(socket.getEnabledProtocols(),socket.getSupportedProtocols()));
	
    return socket;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:20,代码来源:SslContextFactory.java

示例5: start

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Starts this test server.
 */
public void start() throws Exception {
    Asserts.check(servicedSocket == null, "Already running");
    final ServerSocket ssock;
    if (sslcontext != null) {
        final SSLServerSocketFactory sf = sslcontext.getServerSocketFactory();
        final SSLServerSocket sslsock = (SSLServerSocket) sf.createServerSocket();
        if (forceSSLAuth) {
            sslsock.setNeedClientAuth(true);
        } else {
            sslsock.setWantClientAuth(true);
        }
        ssock = sslsock;
    } else {
        ssock = new ServerSocket();
    }

    ssock.setReuseAddress(true); // probably pointless for port '0'
    ssock.bind(TEST_SERVER_ADDR);
    servicedSocket = ssock;

    listenerThread = new ListenerThread();
    listenerThread.setDaemon(false);
    listenerThread.start();
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:28,代码来源:LocalTestServer.java

示例6: createServer

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private static GfxdTSSLServerSocket createServer(
    SSLServerSocketFactory factory, InetSocketAddress bindAddress,
    SocketParameters params) throws TTransportException {
  try {
    SSLServerSocket serverSocket = (SSLServerSocket)factory
        .createServerSocket(bindAddress.getPort(), 100,
            bindAddress.getAddress());
    if (params != null) {
      if (params.getSSLEnabledProtocols() != null) {
        serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols());
      }
      if (params.getSSLCipherSuites() != null) {
        serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites());
      }
      serverSocket.setNeedClientAuth(params.getSSLClientAuth());
    }
    return new GfxdTSSLServerSocket(serverSocket, bindAddress, params);
  } catch (Exception e) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not bind to host:port " + bindAddress.toString(), e);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:23,代码来源:GfxdTSSLServerSocketFactory.java

示例7: initSslServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Initializes the SSL server socket. Configures the certificate request
 * (need or want) and the enabled cipher suites.
 * 
 * @param sslServerSocket
 *            The server socket to initialize.
 * @return The initialized server socket.
 */
protected SSLServerSocket initSslServerSocket(
        SSLServerSocket sslServerSocket) {
    if (getContextFactory().isNeedClientAuthentication()) {
        sslServerSocket.setNeedClientAuth(true);
    } else if (getContextFactory().isWantClientAuthentication()) {
        sslServerSocket.setWantClientAuth(true);
    }

    if ((getContextFactory().getEnabledCipherSuites() != null)
            || (getContextFactory().getDisabledCipherSuites() != null)) {
        sslServerSocket.setEnabledCipherSuites(getContextFactory()
                .getSelectedCipherSuites(
                        sslServerSocket.getSupportedCipherSuites()));
    }

    if ((getContextFactory().getEnabledProtocols() != null)
            || (getContextFactory().getDisabledProtocols() != null)) {
        sslServerSocket.setEnabledProtocols(getContextFactory()
                .getSelectedSslProtocols(
                        sslServerSocket.getSupportedProtocols()));
    }

    return sslServerSocket;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:33,代码来源:WrapperSslServerSocketFactory.java

示例8: newSslServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public SSLServerSocket newSslServerSocket(String host,int port,int backlog) throws IOException
{
    SSLServerSocketFactory factory = _context.getServerSocketFactory();

    SSLServerSocket socket =
        (SSLServerSocket) (host==null ?
                    factory.createServerSocket(port,backlog):
                    factory.createServerSocket(port,backlog,InetAddress.getByName(host)));

    if (getWantClientAuth())
        socket.setWantClientAuth(getWantClientAuth());
    if (getNeedClientAuth())
        socket.setNeedClientAuth(getNeedClientAuth());

    socket.setEnabledCipherSuites(selectCipherSuites(
                                        socket.getEnabledCipherSuites(),
                                        socket.getSupportedCipherSuites()));
    socket.setEnabledProtocols(selectProtocols(socket.getEnabledProtocols(),socket.getSupportedProtocols()));

    return socket;
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:22,代码来源:SslContextFactory.java

示例9: test_NeedClientAuth

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * @throws IOException
 * @tests javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean need)
 * @tests javax.net.ssl.SSLServerSocket#getNeedClientAuthCreation()
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "setNeedClientAuth",
        args = {boolean.class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getNeedClientAuth",
        args = {}
    )
})
public void test_NeedClientAuth() throws Exception {
    SSLServerSocket sss = getSSLServerSocket();
    sss.setNeedClientAuth(true);
    assertTrue(sss.getNeedClientAuth());
    sss.setNeedClientAuth(false);
    assertFalse(sss.getNeedClientAuth());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:SSLServerSocketTest.java

示例10: TestAmqpPeerRunner

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public TestAmqpPeerRunner(TestAmqpPeer peer, SSLContext sslContext, boolean needClientCert) throws IOException
{
    int port = useFixedPort ? PORT : 0;
    this.needClientCert = needClientCert;

    if (sslContext == null)
    {
        _serverSocket = new ServerSocket(port);
    }
    else
    {
        SSLServerSocketFactory socketFactory = sslContext.getServerSocketFactory();
        _serverSocket = socketFactory.createServerSocket(port);

        SSLServerSocket sslServerSocket = (SSLServerSocket) _serverSocket;
        if (this.needClientCert)
        {
            sslServerSocket.setNeedClientAuth(true);
        }
    }

    _testFrameParser = new TestFrameParser(peer);
    _peer = peer;
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:25,代码来源:TestAmqpPeerRunner.java

示例11: testSetGetWantClientAuth

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * setWantClientAuth(boolean want) method testing.
 * getWantClientAuth() method testing.
 */
public void testSetGetWantClientAuth() throws Exception {
    SSLServerSocket ssocket = createSSLServerSocket();

    ssocket.setNeedClientAuth(true);
    ssocket.setWantClientAuth(false);
    assertFalse("Result does not correspond to expected",
            ssocket.getWantClientAuth());
    assertFalse("Socket did not reset its want client auth state",
            ssocket.getNeedClientAuth());
    ssocket.setNeedClientAuth(true);
    ssocket.setWantClientAuth(true);
    assertTrue("Result does not correspond to expected",
            ssocket.getWantClientAuth());
    assertFalse("Socket did not reset its want client auth state",
            ssocket.getNeedClientAuth());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SSLServerSocketImplTest.java

示例12: createServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private ServerSocket createServerSocket( int port , int tcpBackLog , InetAddress localAddr , boolean useSSL ) throws JMSException
{
    try
    {
        if (useSSL)
        {
            SSLServerSocket socket = (SSLServerSocket)createSSLContext().getServerSocketFactory().createServerSocket(port,tcpBackLog,localAddr);
            socket.setNeedClientAuth(false);
            return socket;
        }
        else
            return new ServerSocket(port,tcpBackLog,localAddr);
    }
    catch (Exception e)
    {
        throw new FFMQException("Cannot create server socket","NETWORK_ERROR",e);
    }
}
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:19,代码来源:TcpListener.java

示例13: createServerSocket

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
public ServerSocket createServerSocket(int port) throws IOException  {
    SSLServerSocket sslServerSocket =
            (SSLServerSocket) sslServerSocketFactory.createServerSocket(port, 0, bindAddress);
    if (getEnabledCipherSuites() != null) {
        sslServerSocket.setEnabledCipherSuites(getEnabledCipherSuites());
    }
    if (getEnabledProtocols() == null) {
        sslServerSocket.setEnabledProtocols(defaultProtocols);
    } else {
        sslServerSocket.setEnabledProtocols(getEnabledProtocols());
    }
    sslServerSocket.setNeedClientAuth(getNeedClientAuth());
    return sslServerSocket;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:JmxRemoteLifecycleListener.java

示例14: configureClientAuth

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Configure Client authentication for this version of JSSE.  The
 * JSSE included in Java 1.4 supports the 'want' value.  Prior
 * versions of JSSE will treat 'want' as 'false'.
 * @param socket the SSLServerSocket
 */
protected void configureClientAuth(SSLServerSocket socket){
    if (wantClientAuth){
        socket.setWantClientAuth(wantClientAuth);
    } else {
        socket.setNeedClientAuth(requireClientAuth);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:14,代码来源:JSSESocketFactory.java

示例15: init

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public void init() throws Exception {
	
	//这个类是原生包中的SSL连接的上下文类
	SSLContext context = SSLContext.getInstance("SSL");
	
	//服务器端证书库
	KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
	FileInputStream keystoreFis = new FileInputStream(keystorePath);
	keystore.load(keystoreFis, keystorePassword.toCharArray());
	//信任证书库
	KeyStore trustKeystore = KeyStore.getInstance("jks");
	FileInputStream trustKeystoreFis = new FileInputStream(trustKeystorePath);
	trustKeystore.load(trustKeystoreFis, truststorePassword.toCharArray());
	
	//密钥库
	KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
	kmf.init(keystore, keystorePassword.toCharArray());

	//信任库
	TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
	tmf.init(trustKeystore);
	
	//初始化SSL上下文
	context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
	//初始化SSLSocket
	sslServerSocket = (SSLServerSocket)context.getServerSocketFactory().createServerSocket(port);
	//设置这个SSLServerSocket需要授权的客户端访问
	sslServerSocket.setNeedClientAuth(true);
	
	keystoreFis.close();
	trustKeystoreFis.close();
	System.out.println("SSLServer initialized.");
}
 
开发者ID:strictnerd,项目名称:LearningSummary,代码行数:34,代码来源:SSLServer.java


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