Package com.noelios.restlet.util

Examples of com.noelios.restlet.util.SslContextFactory


    /** Starts the Restlet. */
    @Override
    public void start() throws Exception {
        // Initialize the SSL context
        final SslContextFactory sslContextFactory = HttpsUtils
                .getSslContextFactory(this);
        SSLContext sslContext;
        /*
         * If an SslContextFactory has been set up, its settings take priority
         * over the other parameters (which are otherwise used to build and
         * initialise an SSLContext).
         */
        if (sslContextFactory == null) {
            final KeyStore keyStore = KeyStore.getInstance(getKeystoreType());
            final FileInputStream fis = getKeystorePath() == null ? null
                    : new FileInputStream(getKeystorePath());
            final char[] password = getKeystorePassword() == null ? null
                    : getKeystorePassword().toCharArray();
            keyStore.load(fis, password);
            if (fis != null) {
                fis.close();
            }

            final KeyManagerFactory keyManagerFactory = KeyManagerFactory
                    .getInstance(getCertAlgorithm());
            keyManagerFactory.init(keyStore, getKeyPassword().toCharArray());

            final TrustManagerFactory trustManagerFactory = TrustManagerFactory
                    .getInstance(getCertAlgorithm());
            trustManagerFactory.init(keyStore);

            sslContext = SSLContext.getInstance(getSslProtocol());
            sslContext.init(keyManagerFactory.getKeyManagers(),
                    trustManagerFactory.getTrustManagers(), null);
        } else {
            sslContext = sslContextFactory.createSslContext();
        }

        // Initialize the socket
        SSLServerSocket serverSocket = null;
        final String addr = getHelped().getAddress();
View Full Code Here


     * @return A new internal Jetty connector.
     */
    @Override
    protected AbstractConnector createConnector() {
        AbstractConnector result = null;
        final SslContextFactory sslContextFactory = HttpsUtils
                .getSslContextFactory(this);

        final String[] excludedCipherSuites = HttpsUtils
                .getDisabledCipherSuites(this);

        // Create and configure the Jetty HTTP connector
        switch (getType()) {
        case 1:
            // Selecting NIO connector
            /*
             * If an SslContextFactory has been set up, its settings take
             * priority over the other parameters (which would otherwise be used
             * to build and initialise an SSLContext internally). Jetty's
             * SslSelectChannelConnector does not have a setSslContext method
             * yet, so we override its createSSLContext() method for this
             * purpose.
             */
            SslSelectChannelConnector nioResult;
            if (sslContextFactory == null) {
                nioResult = new SslSelectChannelConnector();
                nioResult.setKeyPassword(getKeyPassword());
                nioResult.setKeystore(getKeystorePath());
                nioResult.setKeystoreType(getKeystoreType());
                nioResult.setPassword(getKeystorePassword());
                nioResult.setProtocol(getSslProtocol());
                nioResult.setProvider(getSecurityProvider());
                nioResult.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
                nioResult.setSslKeyManagerFactoryAlgorithm(getCertAlgorithm());
                nioResult
                        .setSslTrustManagerFactoryAlgorithm(getCertAlgorithm());
                nioResult.setTrustPassword(getKeystorePassword());
            } else {
                nioResult = new SslSelectChannelConnector() {
                    @Override
                    protected SSLContext createSSLContext() throws Exception {
                        return sslContextFactory.createSslContext();
                    }
                };
            }

            if (isNeedClientAuthentication()) {
                nioResult.setNeedClientAuth(true);
            } else if (isWantClientAuthentication()) {
                nioResult.setWantClientAuth(true);
            }

            if (excludedCipherSuites != null) {
                nioResult.setExcludeCipherSuites(excludedCipherSuites);
            }

            result = nioResult;
            break;
        case 2:
            // Blocking BIO connector
            /*
             * If an SslContextFactory has been set up, its settings take
             * priority over the other parameters (which would otherwise be used
             * to build and initialise an SSLContext internally). Jetty's
             * SslSocketConnector does not have a setSslContext method yet, so
             * we override its createFactory() method for this purpose.
             */
            SslSocketConnector bioResult;
            if (sslContextFactory == null) {
                bioResult = new SslSocketConnector();
                bioResult.setKeyPassword(getKeyPassword());
                bioResult.setKeystore(getKeystorePath());
                bioResult.setKeystoreType(getKeystoreType());
                bioResult.setPassword(getKeystorePassword());
                bioResult.setProtocol(getSslProtocol());
                bioResult.setProvider(getSecurityProvider());
                bioResult.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
                bioResult.setSslKeyManagerFactoryAlgorithm(getCertAlgorithm());
                bioResult
                        .setSslTrustManagerFactoryAlgorithm(getCertAlgorithm());
                bioResult.setTrustPassword(getKeystorePassword());
            } else {
                bioResult = new SslSocketConnector() {
                    @Override
                    protected SSLServerSocketFactory createFactory()
                            throws Exception {
                        final SSLContext sslContext = sslContextFactory
                                .createSslContext();
                        return sslContext.getServerSocketFactory();
                    }

                };
View Full Code Here

     *            The helper to use.
     *
     * @return The SSL context factory.
     */
    public static SslContextFactory getSslContextFactory(Helper<?> helper) {
        SslContextFactory result = (SslContextFactory) ((helper.getContext() == null) ? null
                : helper.getContext().getAttributes().get("sslContextFactory"));

        if (result == null) {
            String[] sslContextFactoryNames = helper.getHelpedParameters()
                    .getValuesArray("sslContextFactory");
            if (sslContextFactoryNames != null) {
                for (String sslContextFactoryName : sslContextFactoryNames) {
                    try {
                        Class<? extends SslContextFactory> sslContextFactoryClass = Class
                                .forName(sslContextFactoryName).asSubclass(
                                        SslContextFactory.class);
                        result = sslContextFactoryClass.newInstance();
                        result.init(helper.getHelpedParameters());
                    } catch (ClassNotFoundException e) {
                        Context.getCurrentLogger().log(
                                Level.WARNING,
                                "Unable to find SslContextFactory class: "
                                        + sslContextFactoryName, e);
View Full Code Here

     *            The helper to use.
     *
     * @return The SSL context factory.
     */
    public static SslContextFactory getSslContextFactory(Helper<?> helper) {
        SslContextFactory result = (SslContextFactory) ((helper.getContext() == null) ? null
                : helper.getContext()).getAttributes().get("sslContextFactory");

        if (result == null) {
            String[] sslContextFactoryNames = helper.getHelpedParameters()
                    .getValuesArray("sslContextFactory");
            if (sslContextFactoryNames != null) {
                for (String sslContextFactoryName : sslContextFactoryNames) {
                    try {
                        Class<? extends SslContextFactory> sslContextFactoryClass = Class
                                .forName(sslContextFactoryName).asSubclass(
                                        SslContextFactory.class);
                        result = sslContextFactoryClass.newInstance();
                        result.init(helper.getHelpedParameters());
                    } catch (ClassNotFoundException e) {
                        Context.getCurrentLogger().log(
                                Level.WARNING,
                                "Unable to find SslContextFactory class: "
                                        + sslContextFactoryName, e);
View Full Code Here

TOP

Related Classes of com.noelios.restlet.util.SslContextFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.