use of org.apache.cxf.configuration.security.ClientAuthentication in project cxf by apache.
the class HTTPJettyTransportActivator 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 ("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 ("enableRevocation".equals(k)) {
enableRevocation = 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;
}
use of org.apache.cxf.configuration.security.ClientAuthentication in project cxf by apache.
the class JettyHTTPServerEngineBeanDefinitionParser method mapTLSServerParameters.
private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) {
BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class);
// read the attributes
NamedNodeMap as = e.getAttributes();
for (int i = 0; i < as.getLength(); i++) {
Attr a = (Attr) as.item(i);
if (a.getNamespaceURI() == null) {
String aname = a.getLocalName();
if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) {
paramsbean.addPropertyValue(aname, a.getValue());
}
}
}
// read the child elements
Node n = e.getFirstChild();
while (n != null) {
if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) {
n = n.getNextSibling();
continue;
}
String ename = n.getLocalName();
// Schema should require that no more than one each of these exist.
String ref = ((Element) n).getAttribute("ref");
if ("keyManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("keyManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, KeyManagersType.class);
}
} else if ("trustManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("trustManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, TrustManagersType.class);
}
} else if ("cipherSuites".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CipherSuites.class);
} else if ("cipherSuitesFilter".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, FiltersType.class);
} else if ("excludeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ExcludeProtocols.class);
} else if ("includeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, IncludeProtocols.class);
} else if ("secureRandomParameters".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, SecureRandomParameters.class);
} else if ("clientAuthentication".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ClientAuthentication.class);
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CertificateConstraintsType.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
n = n.getNextSibling();
}
BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class);
jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition());
bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition());
}
use of org.apache.cxf.configuration.security.ClientAuthentication in project cxf by apache.
the class UndertowHTTPServerEngineBeanDefinitionParser method mapTLSServerParameters.
private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) {
BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class);
// read the attributes
NamedNodeMap as = e.getAttributes();
for (int i = 0; i < as.getLength(); i++) {
Attr a = (Attr) as.item(i);
if (a.getNamespaceURI() == null) {
String aname = a.getLocalName();
if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) {
paramsbean.addPropertyValue(aname, a.getValue());
}
}
}
// read the child elements
Node n = e.getFirstChild();
while (n != null) {
if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) {
n = n.getNextSibling();
continue;
}
String ename = n.getLocalName();
// Schema should require that no more than one each of these exist.
String ref = ((Element) n).getAttribute("ref");
if ("keyManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("keyManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, KeyManagersType.class);
}
} else if ("trustManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("trustManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, TrustManagersType.class);
}
} else if ("cipherSuites".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CipherSuites.class);
} else if ("cipherSuitesFilter".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, FiltersType.class);
} else if ("excludeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ExcludeProtocols.class);
} else if ("includeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, IncludeProtocols.class);
} else if ("secureRandomParameters".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, SecureRandomParameters.class);
} else if ("clientAuthentication".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ClientAuthentication.class);
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CertificateConstraintsType.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
n = n.getNextSibling();
}
BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class);
jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition());
bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition());
}
use of org.apache.cxf.configuration.security.ClientAuthentication 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());
}
use of org.apache.cxf.configuration.security.ClientAuthentication in project cxf by apache.
the class NettyHttpServerEngineBeanDefinitionParser method mapTLSServerParameters.
private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) {
BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class);
// read the attributes
NamedNodeMap as = e.getAttributes();
for (int i = 0; i < as.getLength(); i++) {
Attr a = (Attr) as.item(i);
if (a.getNamespaceURI() == null) {
String aname = a.getLocalName();
if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) {
paramsbean.addPropertyValue(aname, a.getValue());
}
}
}
// read the child elements
Node n = e.getFirstChild();
while (n != null) {
if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) {
n = n.getNextSibling();
continue;
}
String ename = n.getLocalName();
// Schema should require that no more than one each of these exist.
String ref = ((Element) n).getAttribute("ref");
if ("keyManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("keyManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, KeyManagersType.class);
}
} else if ("trustManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("trustManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, TrustManagersType.class);
}
} else if ("cipherSuites".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CipherSuites.class);
} else if ("cipherSuitesFilter".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, FiltersType.class);
} else if ("secureRandomParameters".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, SecureRandomParameters.class);
} else if ("clientAuthentication".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ClientAuthentication.class);
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CertificateConstraintsType.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
n = n.getNextSibling();
}
BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class);
jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition());
bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition());
}
Aggregations