Commit de2281d1 authored by Roeland Luykx's avatar Roeland Luykx

fixes ticket https://sourceforge.net/p/ehealthconnector/tickets/44/

set soap_12 as default but configurable for soap messages
some renamings

git-svn-id: https://svn.code.sf.net/p/ehealthconnector/code/trunk@1715 e99adb7c-5e35-42fd-8d1b-cdb378af05e8
parent fe4f55dd
......@@ -53,7 +53,7 @@ import org.ehealth_connector.security.ch.ppq.impl.PrivacyPolicyFeedBuilderImpl;
import org.ehealth_connector.security.ch.ppq.impl.PrivacyPolicyQueryBuilderImpl;
import org.ehealth_connector.security.communication.ch.impl.ConvenienceUserAccessAuthenticationChImpl;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfig;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl;
import org.ehealth_connector.security.communication.config.IdpClientConfig;
import org.ehealth_connector.security.communication.config.XuaClientConfig;
import org.ehealth_connector.security.communication.config.impl.IdpClientBasicAuthConfigBuilderImpl;
......@@ -762,7 +762,7 @@ public class DemoXua {
PrivacyPolicyQuery query = builder.create();
final String urlString = "https://ehealthsuisse.ihe-europe.net:10443/ppq-repository";
final PpClientConfig clientConfiguration = new PpqClientConfigBuilderImpl()//
final PpClientConfig clientConfiguration = new PpClientConfigBuilderImpl()//
.url(urlString)//
.clientKeyStore("rsc/demoXua/security/ehs_gazelle.p12")//
.clientKeyStorePassword("testit")//
......@@ -1017,7 +1017,7 @@ public class DemoXua {
.create(((AssertionImpl) assertion).getWrappedObject());
final String urlString = "https://ehealthsuisse.ihe-europe.net:10443/ppq-repository";
final PpClientConfig clientConfiguration = new PpqClientConfigBuilderImpl()//
final PpClientConfig clientConfiguration = new PpClientConfigBuilderImpl()//
.url(urlString)//
.clientKeyStore("rsc/demoXua/security/ehs_gazelle.p12")//
.clientKeyStorePassword("testit")//
......
......@@ -19,6 +19,7 @@ package org.ehealth_connector.security.communication.ch.ppq.config.impl;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfig;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfigBuilder;
import org.ehealth_connector.security.communication.config.SoapClientConfig.SoapVersion;
import org.ehealth_connector.security.communication.config.SoapClientConfigBuilder;
/**
......@@ -29,12 +30,13 @@ import org.ehealth_connector.security.communication.config.SoapClientConfigBuild
* <div class="it"></div>
* <!-- @formatter:on -->
*/
public class PpqClientConfigBuilderImpl implements PpClientConfigBuilder {
public class PpClientConfigBuilderImpl implements PpClientConfigBuilder {
private PpqClientConfigImpl config;
private PpClientConfigImpl config;
public PpqClientConfigBuilderImpl() {
config = new PpqClientConfigImpl();
public PpClientConfigBuilderImpl() {
config = new PpClientConfigImpl();
config.setSoapVersion(SoapVersion.SOAP_12);
}
@Override
......@@ -96,4 +98,10 @@ public class PpqClientConfigBuilderImpl implements PpClientConfigBuilder {
return this;
}
@Override
public SoapClientConfigBuilder soapVersion(SoapVersion soapVersion) {
config.setSoapVersion(soapVersion);
return this;
}
}
......@@ -18,7 +18,7 @@
package org.ehealth_connector.security.communication.ch.ppq.config.impl;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfig;
import org.ehealth_connector.security.communication.config.impl.BaseSoapClientConfig;
import org.ehealth_connector.security.communication.config.impl.BaseSoapClientConfigImpl;
/**
* <!-- @formatter:off -->
......@@ -28,9 +28,12 @@ import org.ehealth_connector.security.communication.config.impl.BaseSoapClientCo
* <div class="it"></div>
* <!-- @formatter:on -->
*/
public class PpqClientConfigImpl extends BaseSoapClientConfig implements PpClientConfig {
public class PpClientConfigImpl extends BaseSoapClientConfigImpl implements PpClientConfig {
// There are no special methods defined, but the interface has to be
// declared for selection reasons.
protected PpClientConfigImpl() {
setSoapVersion(SoapVersion.SOAP_12);
}
}
......@@ -21,13 +21,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfig;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl;
import org.junit.Before;
import org.junit.Test;
public class PpqClientConfigBuilderImplTest {
private PpqClientConfigBuilderImpl builder;
private PpClientConfigBuilderImpl builder;
private String testEnpointUrl;
private String testPortName;
private String testPortNamespace;
......@@ -36,7 +36,7 @@ public class PpqClientConfigBuilderImplTest {
@Before
public void setUp() throws Exception {
builder = new PpqClientConfigBuilderImpl();
builder = new PpClientConfigBuilderImpl();
testEnpointUrl = "https://guguseli.ch/not/a/very/endpoint";
testPortName = "myPortName";
testPortNamespace = "urn:this.ist.my.namspace";
......@@ -46,7 +46,7 @@ public class PpqClientConfigBuilderImplTest {
/**
* Test method for
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl#portName(java.lang.String)}.
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl#portName(java.lang.String)}.
*/
@Test
public void testPortName() {
......@@ -57,7 +57,7 @@ public class PpqClientConfigBuilderImplTest {
/**
* Test method for
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl#portNamespace(java.lang.String)}.
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl#portNamespace(java.lang.String)}.
*/
@Test
public void testPortNamespace() {
......@@ -68,7 +68,7 @@ public class PpqClientConfigBuilderImplTest {
/**
* Test method for
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl#serviceName(java.lang.String)}.
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl#serviceName(java.lang.String)}.
*/
@Test
public void testServiceName() {
......@@ -79,7 +79,7 @@ public class PpqClientConfigBuilderImplTest {
/**
* Test method for
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl#serviceNamespace(java.lang.String)}.
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl#serviceNamespace(java.lang.String)}.
*/
@Test
public void testServiceNamespace() {
......@@ -90,7 +90,7 @@ public class PpqClientConfigBuilderImplTest {
/**
* Test method for
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl#url(java.lang.String)}.
* {@link org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl#url(java.lang.String)}.
*/
@Test
public void testUrl() {
......
......@@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull;
import org.ehealth_connector.security.communication.ch.clients.PpfClient;
import org.ehealth_connector.security.communication.ch.clients.PpqClient;
import org.ehealth_connector.security.communication.ch.ppq.config.PpClientConfig;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpqClientConfigBuilderImpl;
import org.ehealth_connector.security.communication.ch.ppq.config.impl.PpClientConfigBuilderImpl;
import org.junit.Before;
import org.junit.Test;
......@@ -40,7 +40,7 @@ public class ClientFactoryChTest {
@Before
public void setUp() throws Exception {
testPortName = "My Port Name";
testPpClientConfiguration = new PpqClientConfigBuilderImpl().portName(testPortName)
testPpClientConfiguration = new PpClientConfigBuilderImpl().portName(testPortName)
.create();
}
......
......@@ -27,6 +27,11 @@ package org.ehealth_connector.security.communication.config;
*/
public interface SoapClientConfig extends ClientConfig {
public enum SoapVersion {
SOAP_11, // http://schemas.xmlsoap.org/soap/envelope/
SOAP_12 // http://www.w3.org/2003/05/soap-envelope
}
/**
* <!-- @formatter:off -->
* <div class="en">Method to get the client keystore.</div>
......@@ -256,4 +261,22 @@ public interface SoapClientConfig extends ClientConfig {
*/
void setServiceNamespace(String serviceNamespace);
/**
*
* <!-- @formatter:off -->
* <div class="en">Method to set the soap version of the webservice.</div>
* <div class="de">Methode um die SOAP Version des Webservices zu setzen.</div>
* <div class="fr"></div>
* <div class="it"></div>
*
* @param version
* <div class="en">The version of the soap message to be set. Has influence on the namespace of the SOAP:ENV.</div>
* <div class="de">Die version die für die soap message gesetzt werden muss. Hat einen einfluss auf den Namespace des SOAP:ENV.</div>
* <div class="fr"></div>
* <div class="it"></div>
* <!-- @formatter:on -->
*/
void setSoapVersion(SoapVersion version);
SoapVersion getSoapVersion();
}
......@@ -17,6 +17,8 @@
*/
package org.ehealth_connector.security.communication.config;
import org.ehealth_connector.security.communication.config.SoapClientConfig.SoapVersion;
/**
* <!-- @formatter:off -->
* <div class="en">Interface describing the ClientConfigBuilder methods.</div>
......@@ -199,4 +201,26 @@ public interface SoapClientConfigBuilder extends ClientConfigBuilder {
*/
SoapClientConfigBuilder simple(boolean aSimple);
/**
*
* <!-- @formatter:off -->
* <div class="en">Method to set the SOAP version.</div>
* <div class="de">Method um die SOAP version zu setzen.</div>
* <div class="fr"></div>
* <div class="it"></div>
*
* @param soapVersion
* <div class="en">SoapVersion value to be set</div>
* <div class="de">SoapVersion Wert, der gesetzt werden soll</div>
* <div class="fr"></div>
* <div class="it"></div>
* @return
* <div class="en">the actual instance of this builder</div>
* <div class="de">die aktuelle Instanz des Builders</div>
* <div class="fr"></div>
* <div class="it"></div>
* <!-- @formatter:on -->
*/
SoapClientConfigBuilder soapVersion(SoapVersion soapVersion);
}
......@@ -66,6 +66,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.ehealth_connector.security.communication.config.SoapClientConfig;
import org.ehealth_connector.security.communication.config.SoapClientConfig.SoapVersion;
import org.ehealth_connector.security.communication.soap.impl.WsaHeaderValue;
import org.ehealth_connector.security.exceptions.ClientSendException;
import org.ehealth_connector.security.exceptions.SerializeException;
......@@ -97,8 +98,8 @@ public abstract class AbstractSoapClient<T> {
protected void createBody(Element aBodyElement, Element envelopElement)
throws SerializeException {
// create soap body
final Element soapBody = envelopElement.getOwnerDocument()
.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "Body");
final Element soapBody = envelopElement.getOwnerDocument().createElementNS(getSoapNs(),
"Body");
envelopElement.appendChild(soapBody);
// add authnrequest to soap body
......@@ -114,18 +115,29 @@ public abstract class AbstractSoapClient<T> {
final Document soapDoc = docBuilder.newDocument();
// create soap envelope
final Element envelopElement = soapDoc
.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "Envelope");
final String soapNs = getSoapNs();
final Element envelopElement = soapDoc.createElementNS(soapNs, "Envelope");
soapDoc.appendChild(envelopElement);
return envelopElement;
}
private String getSoapNs() {
if (SoapVersion.SOAP_12.equals(config.getSoapVersion())) {
return "http://www.w3.org/2003/05/soap-envelope";
} else {
return "http://schemas.xmlsoap.org/soap/envelope/";
}
}
protected void createHeader(Element aSecurityHeaderElement, WsaHeaderValue wsHeaders,
Element envelopElement) throws SerializeException {
// create soap header
final Element headerElement = envelopElement.getOwnerDocument()
.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "Header");
final Element headerElement = envelopElement.getOwnerDocument().createElementNS(getSoapNs(),
"Header");
envelopElement.appendChild(headerElement);
final Element headerWsaAction = envelopElement.getOwnerDocument()
......
......@@ -154,13 +154,14 @@ public class IdpSoapBindingClientByBasicAuth extends AbstractIdpClient {
final Document soapDoc = docBuilder.newDocument();
// create soap envelope
final Element envelopElement = soapDoc
.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "Envelope");
final Element envelopElement = soapDoc.createElementNS(getSoapNs(), "Envelope");
soapDoc.appendChild(envelopElement);
final Element soapHeader = soapDoc.createElementNS(getSoapNs(), "Header");
envelopElement.appendChild(soapHeader);
// create soap body
final Element soapBody = soapDoc
.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "Body");
final Element soapBody = soapDoc.createElementNS(getSoapNs(), "Body");
envelopElement.appendChild(soapBody);
// add authnrequest to soap body
......@@ -181,6 +182,10 @@ public class IdpSoapBindingClientByBasicAuth extends AbstractIdpClient {
return stringEntity;
}
private String getSoapNs() {
return "http://schemas.xmlsoap.org/soap/envelope/";
}
/**
*
* {@inheritDoc}
......
......@@ -27,7 +27,7 @@ import org.ehealth_connector.security.communication.config.SoapClientConfig;
* <div class="it"></div>
* <!-- @formatter:on -->
*/
public class BaseSoapClientConfig extends AbstractClientConfig implements SoapClientConfig {
public class BaseSoapClientConfigImpl extends AbstractClientConfig implements SoapClientConfig {
public String keyStoreFile;
public String keyStorePassword;
public String keyStoreType;
......@@ -38,6 +38,11 @@ public class BaseSoapClientConfig extends AbstractClientConfig implements SoapCl
public String serviceNamespace;
private boolean simple;
private SoapVersion version;
protected BaseSoapClientConfigImpl() {
version = SoapVersion.SOAP_12;
}
@Override
public String getKeyStore() {
......@@ -117,4 +122,14 @@ public class BaseSoapClientConfig extends AbstractClientConfig implements SoapCl
public void setSimple(boolean aSimple) {
simple = aSimple;
}
@Override
public void setSoapVersion(SoapVersion aVersion) {
version = aVersion;
}
@Override
public SoapVersion getSoapVersion() {
return version;
}
}
......@@ -52,5 +52,4 @@ public class IdpClientBasicAuthConfigImpl extends AbstractClientConfig implement
public void setBasicAuthUsername(String basicAuthUsername) {
this.basicAuthUsername = basicAuthUsername;
}
}
......@@ -17,6 +17,7 @@
*/
package org.ehealth_connector.security.communication.config.impl;
import org.ehealth_connector.security.communication.config.SoapClientConfig.SoapVersion;
import org.ehealth_connector.security.communication.config.XuaClientConfig;
import org.ehealth_connector.security.communication.config.XuaClientConfigBuilder;
......@@ -34,6 +35,7 @@ public class XuaClientConfigBuilderImpl implements XuaClientConfigBuilder {
public XuaClientConfigBuilderImpl() {
config = new XuaClientConfigImpl();
config.setSoapVersion(SoapVersion.SOAP_12);
}
@Override
......@@ -125,4 +127,10 @@ public class XuaClientConfigBuilderImpl implements XuaClientConfigBuilder {
return this;
}
@Override
public XuaClientConfigBuilder soapVersion(SoapVersion soapVersion) {
config.setSoapVersion(soapVersion);
return this;
}
}
......@@ -27,9 +27,10 @@ import org.ehealth_connector.security.communication.config.XuaClientConfig;
* <div class="it"></div>
* <!-- @formatter:on -->
*/
public class XuaClientConfigImpl extends BaseSoapClientConfig implements XuaClientConfig {
public class XuaClientConfigImpl extends BaseSoapClientConfigImpl implements XuaClientConfig {
protected XuaClientConfigImpl() {
setSoapVersion(SoapVersion.SOAP_12);
setSimple(true);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment