-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from walkIT-nl/feature/12-add-xua-x-service-pr…
…ovider-support implement #12 add-xua-x-service-provider-support
- Loading branch information
Showing
8 changed files
with
423 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/openehealth/app/xdstofhir/registry/common/Wss4jConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.openehealth.app.xdstofhir.registry.common; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.cxf.rt.security.SecurityConstants; | ||
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; | ||
import org.apache.wss4j.common.ConfigurationConstants; | ||
import org.apache.wss4j.common.crypto.CertificateStore; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class Wss4jConfigurator { | ||
public static Map<String, Object> createWss4jProperties(RegistryConfiguration.XuaConfiguration xua) { | ||
return Map.of(SecurityConstants.AUDIENCE_RESTRICTIONS, xua.getAudienceRestriction(), SecurityConstants.SIGNATURE_CRYPTO, | ||
new CertificateStore(xua.getTrustedIdentityProviderCertificates())); | ||
} | ||
|
||
public static WSS4JInInterceptor createWss4jInterceptor() { | ||
return new WSS4JInInterceptor(Map.of(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...est/java/org/openehealth/app/xdstofhir/registry/XdsToFhirApplicationWebServiceTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.openehealth.app.xdstofhir.registry; | ||
|
||
import jakarta.xml.ws.Dispatch; | ||
import jakarta.xml.ws.Service; | ||
import jakarta.xml.ws.soap.SOAPFaultException; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
import org.springframework.boot.test.system.OutputCaptureExtension; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import javax.xml.namespace.QName; | ||
import javax.xml.transform.Source; | ||
import javax.xml.transform.stream.StreamSource; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.springframework.test.util.AssertionErrors.assertEquals; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
@TestPropertySource(properties = {"xds.xua.enabled=true"}) | ||
@ExtendWith(OutputCaptureExtension.class) | ||
class XdsToFhirApplicationWebServiceTestIT { | ||
@LocalServerPort | ||
private int port; | ||
|
||
private void callWebServiceExpectingSoapFault(String testSoapMessageResource) throws MalformedURLException, URISyntaxException { | ||
URL wsdlURL = new URI(String.format("http://localhost:%d/services/registry/iti42?wsdl", port)).toURL(); | ||
Service service = Service.create(wsdlURL, new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_Service")); | ||
Dispatch<Source> dispatch = service.createDispatch(new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_Port_Soap12"), Source.class, Service.Mode.PAYLOAD); | ||
|
||
Source request = new StreamSource(getClass().getResourceAsStream(testSoapMessageResource)); | ||
|
||
SOAPFaultException soapFaultException = Assertions.assertThrowsExactly(SOAPFaultException.class, () -> { | ||
assertNull(dispatch.invoke(request)); | ||
}); | ||
|
||
assertEquals("should raise security error", "A security error was encountered when verifying the message", | ||
soapFaultException.getMessage()); | ||
} | ||
|
||
@Test | ||
void testShallRejectRequestsWithoutAssertion(CapturedOutput output) throws IOException, URISyntaxException { | ||
callWebServiceExpectingSoapFault("/messages/iti-42.xml"); | ||
|
||
assertThat(output.getOut(), containsString("An error was discovered processing the <wsse:Security> header")); | ||
} | ||
|
||
@Test | ||
void testShallRejectRequestsWithAssertionContainingInvalidCertAndSignature(CapturedOutput output) throws IOException, | ||
URISyntaxException { | ||
callWebServiceExpectingSoapFault("/messages/iti-42-invalid-token.xml"); | ||
|
||
assertThat(output.getOut(), containsString("Could not parse certificate: java.io.IOException: Empty input")); | ||
} | ||
} |
Oops, something went wrong.