Example usage for javax.net.ssl SSLServerSocket getNeedClientAuth

List of usage examples for javax.net.ssl SSLServerSocket getNeedClientAuth

Introduction

In this page you can find the example usage for javax.net.ssl SSLServerSocket getNeedClientAuth.

Prototype

public abstract boolean getNeedClientAuth();

Source Link

Document

Returns true if client authentication will be required on newly accepted server-mode SSLSockets.

Usage

From source file:com.adito.server.jetty.CustomJsseListener.java

protected ServerSocket newServerSocket(InetAddrPort p_address, int p_acceptQueueSize) throws IOException {
    SSLServerSocket serverSocket = (SSLServerSocket) super.newServerSocket(p_address, p_acceptQueueSize);
    if (serverSocket.getNeedClientAuth()) {

        serverSocket.setNeedClientAuth(require);
        setNeedClientAuth(require);//w w  w.ja v  a  2s .co  m
        if (!require)
            serverSocket.setWantClientAuth(true);
    }

    String[] ciphers = serverSocket.getSupportedCipherSuites();
    String[] protocols = serverSocket.getSupportedProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are supported:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    if (createAvailableCipherSuitesList) {
        File f = new File(ContextHolder.getContext().getTempDirectory(), "availableCipherSuites.txt");
        BufferedWriter writer = null;

        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
            if (log.isInfoEnabled())
                log.info("The following cipher suites are supported:");
            for (int i = 0; i < ciphers.length; i++) {
                if (log.isInfoEnabled())
                    log.info("     " + ciphers[i]);
                writer.write(ciphers[i]);
                writer.newLine();
            }
        } catch (Throwable e) {
            log.error("Could not create cipher list!", e);
            configureContext = false;
        } finally {
            if (writer != null)
                writer.close();
        }
        createAvailableCipherSuitesList = false;
    }

    if (configureContext) {

        PropertyList list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedProtocols"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledProtocols(list.asArray());
        }

        list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedCiphers"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledCipherSuites(list.asArray());
        }
    }

    protocols = serverSocket.getEnabledProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are enabled:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    ciphers = serverSocket.getEnabledCipherSuites();
    if (log.isInfoEnabled()) {
        log.info("The following cipher suites are enabled:");
        for (int i = 0; i < ciphers.length; i++) {
            log.info("     " + ciphers[i]);
        }
    }

    return serverSocket;
}