Search in sources :

Example 11 with TLSServerParameters

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

the class JettyHTTPServerEngineTest method testHttpAndHttps.

@Test
public void testHttpAndHttps() throws Exception {
    JettyHTTPServerEngine engine = factory.createJettyHTTPServerEngine(PORT1, "http");
    assertTrue("Protocol must be http", "http".equals(engine.getProtocol()));
    engine = new JettyHTTPServerEngine();
    engine.setPort(PORT2);
    engine.setMaxIdleTime(30000);
    engine.setTlsServerParameters(new TLSServerParameters());
    engine.finalizeConfig();
    List<JettyHTTPServerEngine> list = new ArrayList<>();
    list.add(engine);
    factory.setEnginesList(list);
    engine = factory.createJettyHTTPServerEngine(PORT2, "https");
    JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
    // need to create a servant to create the connector
    engine.addServant(new URL("https://localhost:" + PORT2 + "/test"), handler1);
    assertTrue("Protocol must be https", "https".equals(engine.getProtocol()));
    assertEquals("Get the wrong maxIdleTime.", 30000, getMaxIdle(engine.getConnector()));
    factory.setTLSServerParametersForPort(PORT1, new TLSServerParameters());
    engine = factory.createJettyHTTPServerEngine(PORT1, "https");
    assertTrue("Protocol must be https", "https".equals(engine.getProtocol()));
    factory.setTLSServerParametersForPort(PORT3, new TLSServerParameters());
    engine = factory.createJettyHTTPServerEngine(PORT3, "https");
    assertTrue("Protocol must be https", "https".equals(engine.getProtocol()));
    JettyHTTPServerEngineFactory.destroyForPort(PORT1);
    JettyHTTPServerEngineFactory.destroyForPort(PORT2);
    JettyHTTPServerEngineFactory.destroyForPort(PORT3);
}
Also used : ArrayList(java.util.ArrayList) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) URL(java.net.URL) Test(org.junit.Test)

Example 12 with TLSServerParameters

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

the class NettyHttpServerEngineFactory method createNettyHttpServerEngine.

public synchronized NettyHttpServerEngine createNettyHttpServerEngine(String host, int port, String protocol) throws IOException {
    LOG.log(Level.FINE, "CREATING_NETTY_SERVER_ENGINE", port);
    TLSServerParameters tlsServerParameters = null;
    if ("https".equals(protocol) && tlsServerParametersMap != null) {
        tlsServerParameters = tlsServerParametersMap.get(Integer.toString(port));
    }
    NettyHttpServerEngine ref = getOrCreate(this, host, port, tlsServerParameters);
    // checking the protocol
    if (!protocol.equals(ref.getProtocol())) {
        throw new IOException("Protocol mismatch for port " + port + ": " + "engine's protocol is " + ref.getProtocol() + ", the url protocol is " + protocol);
    }
    return ref;
}
Also used : IOException(java.io.IOException) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters)

Example 13 with TLSServerParameters

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

the class NettySpringTypesFactory method toTLSServerParamenters.

private static Map<String, TLSServerParameters> toTLSServerParamenters(List<TLSServerParametersIdentifiedType> list) {
    Map<String, TLSServerParameters> map = new TreeMap<String, TLSServerParameters>();
    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_netty_server.configuration.TLSServerParametersIdentifiedType)

Example 14 with TLSServerParameters

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

the class UndertowHTTPServerEngineFactoryHolder method init.

public void init() {
    try {
        Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
        UndertowHTTPServerEngineFactoryConfigType config = getJaxbObject(element, UndertowHTTPServerEngineFactoryConfigType.class);
        factory = new UndertowHTTPServerEngineFactory();
        Map<String, ThreadingParameters> threadingParametersMap = new TreeMap<String, ThreadingParameters>();
        if (config.getIdentifiedThreadingParameters() != null) {
            for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
                ThreadingParameters rThreads = new ThreadingParameters();
                String id = threads.getId();
                rThreads.setMaxThreads(threads.getThreadingParameters().getMaxThreads());
                rThreads.setMinThreads(threads.getThreadingParameters().getMinThreads());
                rThreads.setWorkerIOThreads(threads.getThreadingParameters().getWorkerIOThreads());
                threadingParametersMap.put(id, rThreads);
            }
            factory.setThreadingParametersMap(threadingParametersMap);
        }
        // SSL
        Map<String, TLSServerParameters> sslMap = new TreeMap<String, TLSServerParameters>();
        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<UndertowHTTPServerEngine> engineList = new ArrayList<>();
        for (UndertowHTTPServerEngineConfigType engine : config.getEngine()) {
            UndertowHTTPServerEngine eng = new UndertowHTTPServerEngine();
            if (engine.getHandlers() != null && handlersMap != null) {
                List<CXFUndertowHttpHandler> 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.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.getThreadingParameters() != null) {
                ThreadingParametersType threads = engine.getThreadingParameters();
                ThreadingParameters rThreads = new ThreadingParameters();
                rThreads.setMaxThreads(threads.getMaxThreads());
                rThreads.setMinThreads(threads.getMinThreads());
                rThreads.setWorkerIOThreads(threads.getWorkerIOThreads());
                eng.setThreadingParameters(rThreads);
            }
            if (engine.getTlsServerParameters() != null) {
                TLSServerParameters parameter = null;
                try {
                    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 : UndertowHTTPServerEngine(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine) ThreadingParameters(org.apache.cxf.transport.http_undertow.ThreadingParameters) ThreadingParametersType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) UndertowHTTPServerEngineFactoryConfigType(org.apache.cxf.transports.http_undertow.configuration.UndertowHTTPServerEngineFactoryConfigType) TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) CXFUndertowHttpHandler(org.apache.cxf.transport.http_undertow.CXFUndertowHttpHandler) UndertowHTTPServerEngineFactory(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersIdentifiedType) UndertowHTTPServerEngineConfigType(org.apache.cxf.transports.http_undertow.configuration.UndertowHTTPServerEngineConfigType) StringReader(java.io.StringReader) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_undertow.configuration.TLSServerParametersIdentifiedType)

Example 15 with TLSServerParameters

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

the class HTTPUndertowTransportActivator method createTlsServerParameters.

private TLSServerParameters createTlsServerParameters(Dictionary<String, ?> d) {
    Enumeration<String> keys = d.keys();
    TLSServerParameters p = null;
    SecureRandomParameters srp = null;
    KeyManagersType kmt = null;
    TrustManagersType tmt = null;
    boolean enableRevocation = false;
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if (k.startsWith("tlsServerParameters.")) {
            if (p == null) {
                p = new TLSServerParameters();
            }
            String v = (String) d.get(k);
            k = k.substring("tlsServerParameters.".length());
            if ("secureSocketProtocol".equals(k)) {
                p.setSecureSocketProtocol(v);
            } else if ("jsseProvider".equals(k)) {
                p.setJsseProvider(v);
            } else if ("certAlias".equals(k)) {
                p.setCertAlias(v);
            } else if ("enableRevocation".equals(k)) {
                enableRevocation = Boolean.parseBoolean(v);
            } else if ("clientAuthentication.want".equals(k)) {
                if (p.getClientAuthentication() == null) {
                    p.setClientAuthentication(new ClientAuthentication());
                }
                p.getClientAuthentication().setWant(Boolean.parseBoolean(v));
            } else if ("clientAuthentication.required".equals(k)) {
                if (p.getClientAuthentication() == null) {
                    p.setClientAuthentication(new ClientAuthentication());
                }
                p.getClientAuthentication().setRequired(Boolean.parseBoolean(v));
            } else if (k.startsWith("certConstraints.")) {
                configureCertConstraints(p, k, v);
            } else if (k.startsWith("secureRandomParameters.")) {
                srp = configureSecureRandom(srp, k, v);
            } else if (k.startsWith("cipherSuitesFilter.")) {
                configureCipherSuitesFilter(p, k, v);
            } else if (k.startsWith("cipherSuites")) {
                StringTokenizer st = new StringTokenizer(v, ",");
                while (st.hasMoreTokens()) {
                    p.getCipherSuites().add(st.nextToken());
                }
            } else if (k.startsWith("excludeProtocols")) {
                StringTokenizer st = new StringTokenizer(v, ",");
                while (st.hasMoreTokens()) {
                    p.getExcludeProtocols().add(st.nextToken());
                }
            } else if (k.startsWith("trustManagers.")) {
                tmt = getTrustManagers(tmt, k.substring("trustManagers.".length()), v);
            } else if (k.startsWith("keyManagers.")) {
                kmt = getKeyManagers(kmt, k.substring("keyManagers.".length()), v);
            }
        }
    }
    try {
        if (srp != null) {
            p.setSecureRandom(TLSParameterJaxBUtils.getSecureRandom(srp));
        }
        if (kmt != null) {
            p.setKeyManagers(TLSParameterJaxBUtils.getKeyManagers(kmt));
        }
        if (tmt != null) {
            p.setTrustManagers(TLSParameterJaxBUtils.getTrustManagers(tmt, enableRevocation));
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return p;
}
Also used : KeyManagersType(org.apache.cxf.configuration.security.KeyManagersType) StringTokenizer(java.util.StringTokenizer) SecureRandomParameters(org.apache.cxf.configuration.security.SecureRandomParameters) TrustManagersType(org.apache.cxf.configuration.security.TrustManagersType) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) GeneralSecurityException(java.security.GeneralSecurityException) ConfigurationException(org.osgi.service.cm.ConfigurationException) IOException(java.io.IOException)

Aggregations

TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)17 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 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 StringReader (java.io.StringReader)3 JAXBElement (javax.xml.bind.JAXBElement)3 ClientAuthentication (org.apache.cxf.configuration.security.ClientAuthentication)3 Test (org.junit.Test)3 Element (org.w3c.dom.Element)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 StringTokenizer (java.util.StringTokenizer)2 Bus (org.apache.cxf.Bus)2 KeyManagersType (org.apache.cxf.configuration.security.KeyManagersType)2 SecureRandomParameters (org.apache.cxf.configuration.security.SecureRandomParameters)2 TrustManagersType (org.apache.cxf.configuration.security.TrustManagersType)2