Java 8 SSLServerSocket - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SSLServerSocket class.

This code example shows how to use the following methods:setEnabledCipherSuites, setEnabledProtocols, setNeedClientAuth, setWantClientAuth
    public ServerSocket createServerSocket(int port, int backlog, InetAddress inetAddress) throws IOException {
        this.initSSLContext();
        SSLServerSocketFactory serverSocketFactory = this.sslContext.getServerSocketFactory();
        SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port, backlog, inetAddress);
        if (this.jsseSecurityDomain.getProtocols() != null)
            serverSocket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols());
        if (this.jsseSecurityDomain.getCipherSuites() != null)
            serverSocket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites());
 
        if (this.jsseSecurityDomain.isClientAuth() || this.require_mutual_auth)
            serverSocket.setNeedClientAuth(true);
        else 
            serverSocket.setWantClientAuth(this.request_mutual_auth);
 
        return serverSocket;
    } 
 
    @Override 
    public void configure(Configuration configuration) throws ConfigurationException {
        // get the configured security domain name. 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setEnabledCipherSuites, setNeedClientAuth, setUseClientMode, setWantClientAuth
	 * {@inheritDoc} 
	 */ 
	@Override 
	protected ServerSocket createServerSocket() throws IOException {
		SSLServerSocket serverSocket = (SSLServerSocket) SSL.createServerSocket();
		serverSocket.setNeedClientAuth(false);
		serverSocket.setUseClientMode(false);
		serverSocket.setWantClientAuth(false);
 
		serverSocket.setEnabledCipherSuites(new String[] {
		    "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", // We want PFS (DHE) 
		    // "TLS_RSA_WITH_AES_256_CBC_SHA", 
		}); 
 
		return serverSocket;
	} 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getUseClientMode, setUseClientMode
     * javax.net.ssl.SSLServerSocket#getUseClientMode() 
     * javax.net.ssl.SSLServerSocket#setUseClientMode(boolean mode) 
     */ 
    public void test_UseClientMode() throws Exception { 
        SSLServerSocket sss = getSSLServerSocket();
        sss.setUseClientMode(false);
        assertFalse(sss.getUseClientMode());
        sss.setUseClientMode(true);
        assertTrue(sss.getUseClientMode());
    } 
 
    /** 
     * @throws IOException 
     * javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean want) 
     * javax.net.ssl.SSLServerSocket#getWantClientAuthCreation() 
     */ 
    public void test_WantClientAuth() throws Exception { 
        SSLServerSocket sss = getSSLServerSocket();
        sss.setWantClientAuth(true);
        assertTrue(sss.getWantClientAuth());
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setSoTimeout, setEnabledCipherSuites, setNeedClientAuth
 
  private static TServerSocket createServer(SSLServerSocketFactory factory, int port, int timeout, boolean clientAuth,
                                    InetAddress ifAddress, TSSLTransportParameters params) throws TTransportException {
    try { 
      SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 100, ifAddress);
      serverSocket.setSoTimeout(timeout);
      serverSocket.setNeedClientAuth(clientAuth);
      if (params != null && params.cipherSuites != null) {
        serverSocket.setEnabledCipherSuites(params.cipherSuites);
      } 
      return new TServerSocket(serverSocket);
    } catch (Exception e) {
      throw new TTransportException("Could not bind to port " + port, e);
    } 
  } 
 
  /** 
   * Get a default SSL wrapped TSocket connected to the specified host and port. All 
   * the client methods return a bound connection. So there is no need to call open() on the  
   * TTransport. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getClass, accept, getInetAddress, getLocalPort, getNeedClientAuth
            SSLServerSocketFactory ssf = sc.getServerSocketFactory();
            SSLServerSocket s = (SSLServerSocket) ssf.createServerSocket(8888);
            System.out.println("Server started:");
            printServerSocketInfo(s);
            // Listening to the port 
            SSLSocket c = (SSLSocket) s.accept();
            printSocketInfo(c);
            BufferedWriter w = new BufferedWriter(new OutputStreamWriter(c.getOutputStream()));
            BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream()));
            String m = r.readLine();
            w.write("HTTP/1.0 200 OK");
            w.newLine();
            w.write("Content-Type: text/html");
            w.newLine();
            w.newLine();
            w.write("<html><body>Hello world!</body></html>");
            w.newLine();
            w.flush();
            w.close();
            r.close();

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setSoTimeout, getSupportedCipherSuites, getSupportedProtocols, setEnabledCipherSuites, setEnabledProtocols
    final SSLServerSocket socket =
      (SSLServerSocket)m_serverSocketFactory.createServerSocket(
        localEndPoint.getPort(), 50,
        InetAddress.getByName(localEndPoint.getHost()));
 
    socket.setSoTimeout(timeout);
 
    socket.setEnabledCipherSuites(socket.getSupportedCipherSuites());
    socket.setEnabledProtocols(socket.getSupportedProtocols());
 
    return socket;
  } 
 
  /** 
   * Factory method for client sockets. 
   * 
   * @param remoteEndPoint Remote host and port. 
   * @return A new <code>Socket</code>. 
   * @exception IOException If an error occurs. 
   */ 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setSoTimeout, getSupportedCipherSuites, getSupportedProtocols, setEnabledCipherSuites, setEnabledProtocols
    final SSLServerSocket socket =
      (SSLServerSocket)m_serverSocketFactory.createServerSocket(
        localEndPoint.getPort(), 50,
        InetAddress.getByName(localEndPoint.getHost()));
 
    socket.setSoTimeout(timeout);
 
    socket.setEnabledCipherSuites(socket.getSupportedCipherSuites());
    socket.setEnabledProtocols(socket.getSupportedProtocols());
 
    return socket;
  } 
 
  /** 
   * Factory method for client sockets. 
   * 
   * @param remoteEndPoint Remote host and port. 
   * @return A new <code>Socket</code>. 
   * @exception IOException If an error occurs. 
   */ 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setNeedClientAuth, setWantClientAuth
	 * 							or client is rejected 
	 */ 
	public ServerSocket createServerSocket(int port) throws IOException {
	    SSLServerSocket result = (SSLServerSocket) ssf.createServerSocket(port);
	    //Require Client Authentication 
	    result.setWantClientAuth(true);
	    result.setNeedClientAuth(true);
		return (new RMISSLServerSocketMonitor(result, this.myPubKeyHash, 
					this.allowedClientKeys, this.log));
    } 
 
	/** 
	 * Returns a hash of this object 
	 * @return int = hash of this object 
	 */ 
    public int hashCode() { 
    	return getClass().hashCode();
    } 
 
    /** 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setSoTimeout, setEnabledCipherSuites, setNeedClientAuth
 
  private static TServerSocket createServer(SSLServerSocketFactory factory, int port, int timeout, boolean clientAuth,
                                    InetAddress ifAddress, TSSLTransportParameters params) throws TTransportException {
    try { 
      SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 100, ifAddress);
      serverSocket.setSoTimeout(timeout);
      serverSocket.setNeedClientAuth(clientAuth);
      if (params != null && params.cipherSuites != null) {
        serverSocket.setEnabledCipherSuites(params.cipherSuites);
      } 
      return new TServerSocket(serverSocket, timeout);
    } catch (Exception e) {
      throw new TTransportException("Could not bind to port " + port, e);
    } 
  } 
 
  /** 
   * Get a default SSL wrapped TSocket connected to the specified host and port. All 
   * the client methods return a bound connection. So there is no need to call open() on the  
   * TTransport. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setEnabledCipherSuites, setNeedClientAuth
        SSLServerSocket s = (SSLServerSocket)
            factory.createServerSocket( port );
 
        if (JSSEUtil.wantClientAuth(request_mutual_auth, require_mutual_auth))
        { 
            JSSEUtil.setWantClientAuth(s, request_mutual_auth);
        } 
        else if (require_mutual_auth)
        { 
            s.setNeedClientAuth( require_mutual_auth );
        } 
 
        // Andrew T. Finnell / Change made for e-Security Inc. 2002 
        // We need a way to enable the cipher suites that we would 
        // like to use. We should obtain these from the properties file. 
        if( cipher_suites.length > 0)
        { 
            s.setEnabledCipherSuites ( cipher_suites );
        } 
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 SSLServerSocket Questions & Answers:

See Code Examples for Java 8 SSLServerSocket Methods: