Search in sources :

Example 6 with TLSServerParameters

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

the class NettyHttpServerEngineTest method testHttps.

@Test
public void testHttps() throws Exception {
    Map<String, TLSServerParameters> tlsParamsMap = new HashMap<>();
    tlsParamsMap.put(Integer.toString(PORT2), new TLSServerParameters());
    factory.setTlsServerParameters(tlsParamsMap);
    factory.createNettyHttpServerEngine(PORT2, "https");
    NettyHttpServerEngineFactory.destroyForPort(PORT2);
}
Also used : HashMap(java.util.HashMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) Test(org.junit.Test)

Example 7 with TLSServerParameters

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

the class UndertowHTTPServerEngineTest method testHttpAndHttps.

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

Example 8 with TLSServerParameters

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

the class HTTPUndertowTransportActivator 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.createUndertowHTTPServerEngine(host, port, "http");
        }
        UndertowHTTPServerEngine e = factory.retrieveUndertowHTTPServerEngine(port);
        configure(e, properties);
    } catch (GeneralSecurityException e) {
        throw new ConfigurationException(null, null, e);
    } catch (IOException e) {
        throw new ConfigurationException(null, null, e);
    }
}
Also used : UndertowHTTPServerEngine(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine) ConfigurationException(org.osgi.service.cm.ConfigurationException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters)

Example 9 with TLSServerParameters

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

the class UndertowSpringTypesFactory 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_undertow.configuration.TLSServerParametersIdentifiedType)

Example 10 with TLSServerParameters

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

the class TrustServerNoSpring method run.

protected void run() {
    Bus busLocal = BusFactory.getDefaultBus(true);
    setBus(busLocal);
    String address = "https://localhost:" + TrustManagerTest.PORT3 + "/SoapContext/HttpsPort";
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/Bethal.jks", this.getClass()), "password".toCharArray());
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(keyStore, "password".toCharArray());
        TLSServerParameters tlsParams = new TLSServerParameters();
        tlsParams.setKeyManagers(kmf.getKeyManagers());
        ClientAuthentication clientAuthentication = new ClientAuthentication();
        clientAuthentication.setRequired(false);
        clientAuthentication.setWant(true);
        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(TrustManagerTest.PORT3), "https", "tlsId");
        factory.initComplete();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    Endpoint.publish(address, new GreeterImpl());
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) GreeterImpl(org.apache.cxf.systest.http.GreeterImpl) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) KeyStore(java.security.KeyStore) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

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