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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations