Search in sources :

Example 1 with TLSServerParameters

use of org.apache.cxf.configuration.jsse.TLSServerParameters in project testcases by coheigea.

the class ClientAuthServer method run.

protected void run() {
    Bus busLocal = BusFactory.getDefaultBus(true);
    setBus(busLocal);
    String address = "https://localhost:" + TLSOCSPClientAuthTest.PORT + "/doubleit/services/doubleittlsocspclientauth";
    try {
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(ClassLoaderUtils.getResourceAsStream("servicestore.jks", this.getClass()), "sspass".toCharArray());
        PKIXBuilderParameters param = new PKIXBuilderParameters(keyStore, new X509CertSelector());
        param.setRevocationEnabled(true);
        tmf.init(new CertPathTrustManagerParameters(param));
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(keyStore, "skpass".toCharArray());
        ClientAuthentication clientAuthentication = new ClientAuthentication();
        clientAuthentication.setRequired(true);
        clientAuthentication.setWant(true);
        TLSServerParameters tlsParams = new TLSServerParameters();
        tlsParams.setTrustManagers(tmf.getTrustManagers());
        tlsParams.setKeyManagers(kmf.getKeyManagers());
        tlsParams.setClientAuthentication(clientAuthentication);
        Map<String, TLSServerParameters> map = new HashMap<>();
        map.put("tlsId", tlsParams);
        JettyHTTPServerEngineFactory factory = busLocal.getExtension(JettyHTTPServerEngineFactory.class);
        factory.setTlsServerParametersMap(map);
        factory.createJettyHTTPServerEngine("localhost", Integer.parseInt(TLSOCSPClientAuthTest.PORT), "https", "tlsId");
        factory.initComplete();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    Endpoint.publish(address, new DoubleItPortTypeImpl());
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) DoubleItPortTypeImpl(org.apache.coheigea.cxf.ocsp.common.DoubleItPortTypeImpl) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication)

Example 2 with TLSServerParameters

use of org.apache.cxf.configuration.jsse.TLSServerParameters in project chuidiang-ejemplos by chuidiang.

the class Main method coinfigureJettyTLs.

public static void coinfigureJettyTLs() throws Exception {
    /*
         * create a JettyHTTPServerEngineFactory to handle the configuration of
         * network port numbers for use with "HTTPS"
         */
    JettyHTTPServerEngineFactory jettyHTTPServerEngineFactory = new JettyHTTPServerEngineFactory();
    // load the key store containing the server certificate
    File keyStoreFile = new File(KEY_STORE_PATH_NAME);
    KeyStore keyStore = KeyStore.getInstance("PKCS12");
    keyStore.load(new FileInputStream(keyStoreFile), KEY_STORE_PASSWORD.toCharArray());
    // create a key manager to handle the server private/public key pair
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, PRIVATE_KEY_PASSWORD.toCharArray());
    KeyManager[] keyManager = keyManagerFactory.getKeyManagers();
    // set the TLSServerParameters on theJettyHTTPServerEngineFactory
    TLSServerParameters tLSServerParameters = new TLSServerParameters();
    tLSServerParameters.setKeyManagers(keyManager);
    jettyHTTPServerEngineFactory.setTLSServerParametersForPort(9443, tLSServerParameters);
}
Also used : JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) File(java.io.File) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) FileInputStream(java.io.FileInputStream) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 3 with TLSServerParameters

use of org.apache.cxf.configuration.jsse.TLSServerParameters in project cxf by apache.

the class JettySpringTypesFactory method toTLSServerParamenters.

private static Map<String, TLSServerParameters> toTLSServerParamenters(List<TLSServerParametersIdentifiedType> list) {
    Map<String, TLSServerParameters> map = new TreeMap<>();
    for (TLSServerParametersIdentifiedType t : list) {
        try {
            TLSServerParameters parameter = new TLSServerParametersConfig(t.getTlsServerParameters());
            map.put(t.getId(), parameter);
        } catch (Exception e) {
            throw new RuntimeException("Could not configure TLS for id " + t.getId(), e);
        }
    }
    return map;
}
Also used : TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType)

Example 4 with TLSServerParameters

use of org.apache.cxf.configuration.jsse.TLSServerParameters in project cxf by apache.

the class JettyHTTPServerEngineFactoryHolder method init.

public void init() {
    try {
        Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
        JettyHTTPServerEngineFactoryConfigType config = getJaxbObject(element, JettyHTTPServerEngineFactoryConfigType.class);
        Bus defaultBus = BusFactory.getDefaultBus();
        factory = new JettyHTTPServerEngineFactory(defaultBus);
        Map<String, ThreadingParameters> threadingParametersMap = new TreeMap<>();
        if (config.getIdentifiedThreadingParameters() != null) {
            for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
                ThreadingParameters rThreads = new ThreadingParameters();
                String id = threads.getId();
                if (threads.getThreadingParameters().getMaxThreads() != null) {
                    rThreads.setMaxThreads(threads.getThreadingParameters().getMaxThreads());
                }
                if (threads.getThreadingParameters().getMinThreads() != null) {
                    rThreads.setMinThreads(threads.getThreadingParameters().getMinThreads());
                }
                rThreads.setThreadNamePrefix(threads.getThreadingParameters().getThreadNamePrefix());
                threadingParametersMap.put(id, rThreads);
            }
            factory.setThreadingParametersMap(threadingParametersMap);
        }
        // SSL
        Map<String, TLSServerParameters> sslMap = new TreeMap<>();
        if (config.getIdentifiedTLSServerParameters() != null) {
            for (TLSServerParametersIdentifiedType t : config.getIdentifiedTLSServerParameters()) {
                try {
                    TLSServerParameters parameter = new TLSServerParametersConfig(t.getTlsServerParameters());
                    sslMap.put(t.getId(), parameter);
                } catch (Exception e) {
                    throw new RuntimeException("Could not configure TLS for id " + t.getId(), e);
                }
            }
            factory.setTlsServerParametersMap(sslMap);
        }
        // Engines
        List<JettyHTTPServerEngine> engineList = new ArrayList<>();
        for (JettyHTTPServerEngineConfigType engine : config.getEngine()) {
            JettyHTTPServerEngine eng = new JettyHTTPServerEngine(factory.getMBeanContainer(), engine.getHost(), engine.getPort());
            if (engine.getConnector() != null && connectorMap != null) {
                // we need to setup the Connector from the connectorMap
                Connector connector = connectorMap.get(engine.getPort().toString());
                if (connector != null) {
                    eng.setConnector(connector);
                } else {
                    throw new RuntimeException("Could not find the connector instance for engine with port" + engine.getPort().toString());
                }
            }
            if (engine.getHandlers() != null && handlersMap != null) {
                List<Handler> handlers = handlersMap.get(engine.getPort().toString());
                if (handlers != null) {
                    eng.setHandlers(handlers);
                } else {
                    throw new RuntimeException("Could not find the handlers instance for engine with port" + engine.getPort().toString());
                }
            }
            if (engine.isContinuationsEnabled() != null) {
                eng.setContinuationsEnabled(engine.isContinuationsEnabled());
            }
            if (engine.isSendServerVersion() != null) {
                eng.setSendServerVersion(engine.isSendServerVersion());
            }
            if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost())) {
                eng.setHost(engine.getHost());
            }
            if (engine.getMaxIdleTime() != null) {
                eng.setMaxIdleTime(engine.getMaxIdleTime());
            }
            if (engine.getPort() != null) {
                eng.setPort(engine.getPort());
            }
            if (engine.isReuseAddress() != null) {
                eng.setReuseAddress(engine.isReuseAddress());
            }
            if (engine.isSessionSupport() != null) {
                eng.setSessionSupport(engine.isSessionSupport());
            }
            if (engine.getSessionTimeout() != null) {
                eng.setSessionTimeout(engine.getSessionTimeout().intValue());
            }
            if (engine.getThreadingParameters() != null) {
                ThreadingParametersType threads = engine.getThreadingParameters();
                ThreadingParameters rThreads = new ThreadingParameters();
                if (threads.getMaxThreads() != null) {
                    rThreads.setMaxThreads(threads.getMaxThreads());
                }
                if (threads.getMinThreads() != null) {
                    rThreads.setMinThreads(threads.getMinThreads());
                }
                eng.setThreadingParameters(rThreads);
            }
            // eng.setServer(engine.getTlsServerParameters());
            if (engine.getTlsServerParameters() != null && (engine.getTlsServerParameters().getKeyManagers() != null || engine.getTlsServerParameters().getTrustManagers() != null)) {
                try {
                    TLSServerParameters parameter = new TLSServerParametersConfig(engine.getTlsServerParameters());
                    eng.setTlsServerParameters(parameter);
                } catch (Exception e) {
                    throw new RuntimeException("Could not configure TLS for engine on  " + eng.getHost() + ":" + eng.getPort(), e);
                }
            }
            eng.finalizeConfig();
            engineList.add(eng);
        }
        factory.setEnginesList(engineList);
        // Unravel this completely.
        factory.initComplete();
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
}
Also used : Bus(org.apache.cxf.Bus) ThreadingParameters(org.apache.cxf.transport.http_jetty.ThreadingParameters) JettyHTTPServerEngineConfigType(org.apache.cxf.transports.http_jetty.configuration.JettyHTTPServerEngineConfigType) Connector(org.eclipse.jetty.server.Connector) ThreadingParametersType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) JettyHTTPServerEngineFactoryConfigType(org.apache.cxf.transports.http_jetty.configuration.JettyHTTPServerEngineFactoryConfigType) TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType) StringReader(java.io.StringReader) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType)

Example 5 with TLSServerParameters

use of org.apache.cxf.configuration.jsse.TLSServerParameters in project cxf by apache.

the class HTTPJettyTransportActivator method updated.

public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
    if (pid == null) {
        return;
    }
    int port = Integer.parseInt((String) properties.get("port"));
    String host = (String) properties.get("host");
    try {
        TLSServerParameters tls = createTlsServerParameters(properties);
        if (tls != null) {
            factory.setTLSServerParametersForPort(host, port, tls);
        } else {
            factory.createJettyHTTPServerEngine(host, port, "http");
        }
        JettyHTTPServerEngine e = factory.retrieveJettyHTTPServerEngine(port);
        configure(e, properties);
    } catch (GeneralSecurityException | IOException e) {
        throw new ConfigurationException(null, null, e);
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) GeneralSecurityException(java.security.GeneralSecurityException) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) IOException(java.io.IOException) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters)

Aggregations

TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)20 IOException (java.io.IOException)6 TreeMap (java.util.TreeMap)6 JAXBException (javax.xml.bind.JAXBException)6 TLSServerParametersConfig (org.apache.cxf.configuration.jsse.TLSServerParametersConfig)6 ArrayList (java.util.ArrayList)5 GeneralSecurityException (java.security.GeneralSecurityException)4 ClientAuthentication (org.apache.cxf.configuration.security.ClientAuthentication)4 JettyHTTPServerEngineFactory (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 StringReader (java.io.StringReader)3 KeyStore (java.security.KeyStore)3 HashMap (java.util.HashMap)3 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)3 JAXBElement (javax.xml.bind.JAXBElement)3 Bus (org.apache.cxf.Bus)3 Test (org.junit.Test)3 Element (org.w3c.dom.Element)3 URL (java.net.URL)2 StringTokenizer (java.util.StringTokenizer)2