diff options
14 files changed, 1743 insertions, 95 deletions
diff --git a/id/server/modules/moa-id-module-ehvd_integration/pom.xml b/id/server/modules/moa-id-module-ehvd_integration/pom.xml index 05b2d0daa..6f9463710 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/pom.xml +++ b/id/server/modules/moa-id-module-ehvd_integration/pom.xml @@ -22,13 +22,20 @@ </exclusion> </exclusions> </dependency> - + <dependency> <groupId>MOA.id.server</groupId> <artifactId>moa-id-lib</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.springframework</groupId> @@ -52,6 +59,63 @@ <scope>test</scope> <type>test-jar</type> </dependency> - + <dependency> + <groupId>com.github.skjolber</groupId> + <artifactId>mockito-soap-cxf</artifactId> + <version>1.2.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-codegen-plugin</artifactId> + <version>3.4.1</version> + <dependencies> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.2.5</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-xjc</artifactId> + <version>2.2.5</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>generate-sources</id> + <phase>generate-sources</phase> + <configuration> + <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> + <wsdlOptions> + <wsdlOption> + <wsdl>${basedir}/src/main/resources/wsdl/eHVD.wsdl</wsdl> + <packagenames> + <packagename>eHVD=at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl</packagename> + </packagenames> + <extraargs> + <extraarg>-verbose </extraarg> + </extraargs> + </wsdlOption> + </wsdlOptions> + </configuration> + <goals> + <goal>wsdl2java</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </project> diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/ConfigurationProperties.java b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/ConfigurationProperties.java index fd7d1b013..07d65f2f5 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/ConfigurationProperties.java +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/ConfigurationProperties.java @@ -22,26 +22,23 @@ */ package at.gv.egovernment.moa.id.auth.modules.ehvd; -import java.util.Collection; - -import com.google.common.collect.Sets; - import at.gv.egiz.eaaf.core.api.data.EAAFConstants; -import at.gv.egiz.eaaf.core.api.data.PVPAttributeDefinitions; public class ConfigurationProperties { // configuration properties private static final String MODULE_PREFIX = "modules.ehvd."; - + public static final String PROP_MODULE_ENABLED = MODULE_PREFIX + "enabled"; public static final String PROP_MODULE_SP_PREFIX = MODULE_PREFIX + "sp"; - + public static final String PROP_MODULE_SERVICE_TARGET = MODULE_PREFIX + "service.bpk.target"; - - - public static final String DEFAULT_EHVD_SERVICE_TARGET = EAAFConstants.URN_PREFIX_CDID + "GH"; - + public static final String PROP_MODULE_SERVICE_ENDPOINT = MODULE_PREFIX + "service.url"; + + public static final String PROP_MODULE_PROXY_SOCKS_PORT = MODULE_PREFIX + "proxy.socks.port"; + + public static final String DEFAULT_EHVD_SERVICE_TARGET = EAAFConstants.URN_PREFIX_CDID + "GH"; + private ConfigurationProperties() { // hide constructor or static class } diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/exception/EhvdException.java b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/exception/EhvdException.java new file mode 100644 index 000000000..daab154bc --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/exception/EhvdException.java @@ -0,0 +1,19 @@ +package at.gv.egovernment.moa.id.auth.modules.ehvd.exception; + +import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; + +public class EhvdException extends AuthenticationException{ + + private static final long serialVersionUID = 380654627005502948L; + + public EhvdException(String messageId, Object[] parameters) { + super(messageId, parameters); + + } + + public EhvdException(String messageId, Object[] parameters, Throwable e) { + super(messageId, parameters, e); + + } + +} diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java index f0e2069a1..ab4a70751 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java @@ -1,69 +1,213 @@ package at.gv.egovernment.moa.id.auth.modules.ehvd.service; +import java.net.URL; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.PostConstruct; +import javax.xml.ws.BindingProvider; +import javax.xml.ws.handler.Handler; +import javax.xml.ws.soap.SOAPFaultException; +import org.apache.commons.lang3.StringUtils; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.ProxyServerType; import org.springframework.beans.factory.annotation.Autowired; +import at.gv.egiz.eaaf.core.api.data.PVPAttributeDefinitions; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; import at.gv.egiz.eaaf.core.exceptions.EAAFBuilderException; +import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException; import at.gv.egiz.eaaf.core.impl.data.Pair; import at.gv.egiz.eaaf.core.impl.idp.auth.builder.BPKBuilder; import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; import at.gv.egovernment.moa.id.auth.modules.ehvd.ConfigurationProperties; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.EHVD; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.EHVDService; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaDescriptor; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaIndexResponse; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GetGdaDescriptors; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.InstanceIdentifier; +import at.gv.egovernment.moa.id.auth.modules.ehvd.exception.EhvdException; import at.gv.egovernment.moa.logging.Logger; +import at.gv.util.LoggingHandler; /** * Implement interaction with EHVD service to get GDA information. - * + * * @author tlenz * */ public class EhvdCommunicationService implements IEhvdCommunication { - @Autowired IConfiguration config; - + private static final String GDA_RESP_STATUS_ACTIVE = "Aktiv"; + + private static final String ERROR_EHVD_00 = "ehvd.00"; + private static final String ERROR_EHVD_01 = "ehvd.01"; + private static final String ERROR_EHVD_02 = "ehvd.02"; + private static final String ERROR_CONFIG_05 = "config.05"; + + @Autowired + IConfiguration config; + private String ehvdBpkTarget; - + + private EHVD ehvdClient; + /** * Get user's GDA roles from EHVD Service. - * + * * @param identityLink IdentityLink of the user * @return {@link List} of Roles that are received from EHVD * @throws AuthenticationException In case of an EHVD communication error - * @throws EAAFBuilderException In case of a bPK generation error + * @throws EAAFBuilderException In case of a bPK generation error */ @Override @Nonnull - public List<String> getRoles(IIdentityLink identityLink) throws AuthenticationException, EAAFBuilderException { - + public List<String> getRoles(IIdentityLink identityLink) throws AuthenticationException, + EAAFBuilderException { + // get bPK for EHVD request - Pair<String, String> ehvdBpk = BPKBuilder.generateAreaSpecificPersonIdentifier( - identityLink.getIdentificationValue(), - identityLink.getIdentificationType(), + final Pair<String, String> ehvdBpk = BPKBuilder.generateAreaSpecificPersonIdentifier( + identityLink.getIdentificationValue(), + identityLink.getIdentificationType(), ehvdBpkTarget); - - - //TODO: request EHVD and handle errors - - //TODO: parse roles from response - - + + // request EHVD and handle errors + final GdaIndexResponse gdaResp = requestingGda(ehvdBpk.getFirst()); + + // parse roles from response + return parseGdaResponse(gdaResp); + + } + + @Nonnull + private GdaIndexResponse requestingGda(String bpk) throws EhvdException { + try { + final GetGdaDescriptors gdaReq = buildGdaRequest(bpk); + Logger.debug("Requesting EHVD to get GDA status ... "); + final GdaIndexResponse gdaResp = ehvdClient.getGDA(gdaReq); + Logger.debug("Receive GDA status. Starting response validation ... "); + return gdaResp; + + } catch (final SOAPFaultException e) { + // extract reason for this error + String errorMsg = e.getFault() != null + ? StringUtils.isNotEmpty(e.getFault().getFaultString()) ? e.getFault().getFaultString() : e.getMessage() + : e.getMessage(); + + Logger.warn("EHVD communication failed with SOAP response: " + errorMsg, e); + throw new EhvdException(ERROR_EHVD_02, new Object[] {errorMsg}, e); + + } catch (final Exception e) { + Logger.error("EHVD communication failed with generic error: " + e.getMessage(), e); + throw new EhvdException(ERROR_EHVD_01, new Object[] {}, e); + + } + + } + + private List<String> parseGdaResponse(GdaIndexResponse ehvdResp) throws EhvdException { + if (ehvdResp.getGda() != null) { + final GdaDescriptor gdaInfo = ehvdResp.getGda(); + if (GDA_RESP_STATUS_ACTIVE.equals(gdaInfo.getStatus().getEhvdstatus())) { + Logger.debug("Find #" + gdaInfo.getRoles().getRole().size() + " roles"); + return gdaInfo.getRoles().getRole(); + + } else { + Logger.info("GDA is marked as 'inactive'. Stopping process with an error ... "); + throw new EhvdException(ERROR_EHVD_00, null); + + } + + } else { + Logger.debug("Receive empty GDA response"); + // TODO: what we to in case of empty response? + + } + return Collections.emptyList(); - + + } + + private GetGdaDescriptors buildGdaRequest(String bPK) { + final GetGdaDescriptors req = new GetGdaDescriptors(); + final InstanceIdentifier gdaIdentifier = new InstanceIdentifier(); + gdaIdentifier.setOidIssuingAuthority(PVPAttributeDefinitions.BPK_OID); + gdaIdentifier.setId(bPK); + req.setHcIdentifier(gdaIdentifier); + return req; + } @PostConstruct - private void initialize() { - ehvdBpkTarget = config.getBasicConfiguration( - ConfigurationProperties.PROP_MODULE_SERVICE_TARGET, - ConfigurationProperties.DEFAULT_EHVD_SERVICE_TARGET); - Logger.info("Initialize EHVD Client with bPK target: " + ehvdBpkTarget); + private void initialize() throws EAAFConfigurationException { + if (config.getBasicConfigurationBoolean(ConfigurationProperties.PROP_MODULE_ENABLED, false)) { + initializeEhvdClient(); + + ehvdBpkTarget = config.getBasicConfiguration( + ConfigurationProperties.PROP_MODULE_SERVICE_TARGET, + ConfigurationProperties.DEFAULT_EHVD_SERVICE_TARGET); + Logger.info("Set-up EHVD Client with bPK target: " + ehvdBpkTarget); + + } else { + Logger.info("Skipping EHVD client because it's not active"); + + } + } + + private void initializeEhvdClient() throws EAAFConfigurationException { + Logger.debug("Initializing EHVD client ... "); + final URL url = EhvdCommunicationService.class.getResource("/wsdl/eHVD.wsdl"); + final EHVDService service = new EHVDService(url); + ehvdClient = service.getEHVDPort12(); + + // load service end-point URL from configuration + final String ehvdEndpointUrl = config.getBasicConfiguration( + ConfigurationProperties.PROP_MODULE_SERVICE_ENDPOINT); + if (StringUtils.isEmpty(ehvdEndpointUrl)) { + Logger.error("Missing configuration for EHVD WebService endpoint. " + + "(Property: " + ConfigurationProperties.PROP_MODULE_SERVICE_ENDPOINT + ")"); + throw new EAAFConfigurationException(ERROR_CONFIG_05, + new Object[] { ConfigurationProperties.PROP_MODULE_SERVICE_ENDPOINT }); + + } + + // inject service end-point URL + final Map<String, Object> requestContext = ((BindingProvider) ehvdClient).getRequestContext(); + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ehvdEndpointUrl); + + // inject Logging handler + List<Handler> handlerList = ((BindingProvider) ehvdClient).getBinding().getHandlerChain(); + if (handlerList == null) { + handlerList = new ArrayList<>(); + + } + + handlerList.add(new LoggingHandler()); + ((BindingProvider) ehvdClient).getBinding().setHandlerChain(handlerList); + + Logger.info("Initialize EHVD Client with service end-point: " + ehvdEndpointUrl); + + + // these code is only for local testing + String socksPort = config.getBasicConfiguration(ConfigurationProperties.PROP_MODULE_PROXY_SOCKS_PORT); + if (StringUtils.isNotEmpty(socksPort)) { + Logger.warn("Injecting SOCKS5 Proxy for service communication!"); + final Client client = ClientProxy.getClient(ehvdClient); + final HTTPConduit http = (HTTPConduit) client.getConduit(); + http.getClient().setProxyServerType(ProxyServerType.SOCKS); + http.getClient().setProxyServer("127.0.0.1"); + http.getClient().setProxyServerPort(Integer.valueOf(socksPort)); + + } } - + } diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/id_messages.properties b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/id_messages.properties index 89fd19362..104342a9d 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/id_messages.properties +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/id_messages.properties @@ -1,2 +1,5 @@ -ehvd.00=GDA Status inaktiv +ehvd.00=Für den abgefragtem GDA liegt keine Berechtigung vor +ehvd.01=Technischer Fehler bei der Abfrage von GDA Informationen. Ursache: {0} +ehvd.02=Fehler bei der Abfrage von GDA Informationen. Ursache: {0} + ehvd.99=Allgemeiner Fehler bei der Abfrage des EHVD Service diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/protocol_response_statuscodes.properties b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/protocol_response_statuscodes.properties index fca8fa8cd..400994330 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/protocol_response_statuscodes.properties +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/resources/properties/protocol_response_statuscodes.properties @@ -1,2 +1,7 @@ test.01=aabbccdd -test.02=zzzyyyxxx
\ No newline at end of file +test.02=zzzyyyxxx + +ehvd.00=7000 +ehvd.01=7001 +ehvd.02=7001 +ehvd.99=7099
\ No newline at end of file diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/wsdl/eHVD.wsdl b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/wsdl/eHVD.wsdl new file mode 100644 index 000000000..a1138f068 --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/resources/wsdl/eHVD.wsdl @@ -0,0 +1,220 @@ +<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="eHVD" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:mime="http://www.w3.org/2003/01/wsdl/mime" targetNamespace="eHVD"> + + <wsdl:documentation> + Service: eHVD + Version: 2 + Owner: BRZ + </wsdl:documentation> + + <wsdl:types> + <xs:schema xmlns:ehvd="eHVD" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0" elementFormDefault="qualified" targetNamespace="eHVD" version="1.0"> + <xs:annotation> + <xs:appinfo> + <jaxb:globalBindings> + <jaxb:serializable uid="1"/> + </jaxb:globalBindings> + </xs:appinfo> + </xs:annotation> + + <xs:complexType name="InstanceIdentifier"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="0" name="oidIssuingAuthority" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="id" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="InstanceIdentifierSearch"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="0" name="firstname" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="surname" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="rolecode" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="postcode" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="streetNumber" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="streetName" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="city" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="state" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="maxResults" type="xs:integer"/> + <xs:element maxOccurs="1" minOccurs="0" name="ehvdstatus" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="elgastatus" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="description" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GDAStatus"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="1" name="ehvdstatus" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="elgastatus" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GDARoles"> + <xs:sequence> + <xs:element maxOccurs="unbounded" minOccurs="0" name="role" type="xs:string"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="elgaRole" type="xs:string"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="specialisation" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GdaAddress"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="0" name="streetNumber" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="streetName" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="city" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="state" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="zip" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="country" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GDARelationship"> + <xs:sequence> + <xs:element maxOccurs="unbounded" minOccurs="0" name="memberof" type="xs:string"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="ownerof" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GDADBTimestamps"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="0" name="add" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="modify" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="GdaDescriptor"> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="1" name="id" type="ehvd:InstanceIdentifier"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="otherID" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="status" type="ehvd:GDAStatus"/> + <xs:element maxOccurs="1" minOccurs="0" name="firstname" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="surname" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="gender" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="title" type="xs:string"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="knownname" type="xs:string"/> + <xs:element maxOccurs="unbounded" minOccurs="0" name="address" type="ehvd:GdaAddress"/> + <xs:element maxOccurs="unbounded" minOccurs="1" name="description" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="roles" type="ehvd:GDARoles"/> + <xs:element maxOccurs="1" minOccurs="0" name="relations" type="ehvd:GDARelationship"/> + <xs:element maxOccurs="1" minOccurs="0" name="tel" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="fax" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="web" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="0" name="mail" type="xs:string"/> + <xs:element maxOccurs="1" minOccurs="1" name="timestamps" type="ehvd:GDADBTimestamps"/> + </xs:sequence> + </xs:complexType> + + <xs:element name="GetGdaSearch"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="1" name="hcIdentifierSearch" type="ehvd:InstanceIdentifierSearch"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="GetGdaDescriptors"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="1" name="hcIdentifier" type="ehvd:InstanceIdentifier"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="GdaIndexResponse"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="1" minOccurs="0" name="gda" type="ehvd:GdaDescriptor"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="GdaIndexResponseList"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="unbounded" minOccurs="0" name="gda" type="ehvd:GdaDescriptor"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + </xs:schema> + </wsdl:types> + + <wsdl:message name="GetGdaDescriptors"> + <wsdl:part element="tns:GetGdaDescriptors" name="GetGdaDescriptors"> + </wsdl:part> + </wsdl:message> + + <wsdl:message name="GetGdaSearch"> + <wsdl:part element="tns:GetGdaSearch" name="GetGdaSearch"> + </wsdl:part> + </wsdl:message> + + + <wsdl:message name="GdaIndexResponse"> + <wsdl:part element="tns:GdaIndexResponse" name="GdaIndexResponse"> + </wsdl:part> + </wsdl:message> + + <wsdl:message name="GdaIndexResponseList"> + <wsdl:part element="tns:GdaIndexResponseList" name="GdaIndexResponseList"> + </wsdl:part> + </wsdl:message> + + <wsdl:portType name="eHVD"> + + <wsdl:documentation>eHVD Service Interfaces + </wsdl:documentation> + + <wsdl:operation name="GetGDA"> + <wsdl:input message="tns:GetGdaDescriptors" name="GetGdaDescriptors"> + </wsdl:input> + <wsdl:output message="tns:GdaIndexResponse" name="GdaIndexResponse"> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="GdaSearch"> + <wsdl:input message="tns:GetGdaSearch" name="GetGdaSearch"> + </wsdl:input> + <wsdl:output message="tns:GdaIndexResponseList" name="GdaIndexResponseList"> + </wsdl:output> + </wsdl:operation> + + </wsdl:portType> + + <wsdl:binding name="eHVDSOAPBinding12" type="tns:eHVD"> + <wsdl:documentation>SOAP 1.2 Binding</wsdl:documentation> + + <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> + + <wsdl:operation name="GetGDA"> + <soap12:operation soapAction="eHVD/GetGDA"/> + <wsdl:input name="GetGdaDescriptors"> + <mime:content type="application/soap+xml"/> + <soap12:body use="literal"/> + </wsdl:input> + <wsdl:output name="GdaIndexResponse"> + <soap12:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="GdaSearch"> + <soap12:operation soapAction="eHVD/GdaSearch"/> + <wsdl:input name="GetGdaSearch"> + <mime:content type="application/soap+xml"/> + <soap12:body use="literal"/> + </wsdl:input> + <wsdl:output name="GdaIndexResponseList"> + <soap12:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="eHVDService"> + <wsdl:documentation>eHVD Service</wsdl:documentation> + + <wsdl:port name="eHVDPort12" binding="tns:eHVDSOAPBinding12"> + <soap12:address location="https://ehvdws.gesundheit.gv.at"/> + </wsdl:port> + + </wsdl:service> + +</wsdl:definitions>
\ No newline at end of file diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/InjectEhvdIdentityInformationTaskTest.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationQsSystemTest.java index 45f7a8fc4..585083a77 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/InjectEhvdIdentityInformationTaskTest.java +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationQsSystemTest.java @@ -1,131 +1,141 @@ -package at.gv.egovernment.moa.id.auth.modules.ehvd.test; +package at.gv.egovernment.moa.id.auth.modules.ehvd.test.tasks; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; -import java.io.IOException; -import java.security.PublicKey; +import java.net.SocketTimeoutException; +import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; import java.util.Map; -import javax.xml.transform.TransformerException; +import javax.xml.namespace.QName; +import javax.xml.soap.Detail; +import javax.xml.soap.Name; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.ws.soap.SOAPFaultException; import org.apache.commons.lang3.RandomStringUtils; import org.junit.Before; -import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.annotation.IfProfileValue; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import org.w3c.dom.Element; +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.TypeInfo; +import org.w3c.dom.UserDataHandler; + +import com.github.skjolber.mockito.soap.Soap12EndpointRule; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.IRequestStorage; import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants; import at.gv.egiz.eaaf.core.api.data.EAAFConstants; import at.gv.egiz.eaaf.core.api.idp.ISPConfiguration; -import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EAAFException; import at.gv.egiz.eaaf.core.exceptions.EAAFParserException; import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; -import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser; import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration; import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; import at.gv.egovernment.moa.id.auth.data.AuthenticationSessionWrapper; import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.EHVD; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GDARoles; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GDAStatus; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaDescriptor; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaIndexResponse; import at.gv.egovernment.moa.id.auth.modules.ehvd.task.InjectEhvdInformationTask; import at.gv.egovernment.moa.id.auth.modules.ehvd.test.dummy.DummyAuthConfigMap; import at.gv.egovernment.moa.id.auth.modules.ehvd.test.dummy.TestUtils; +import at.gv.egovernment.moa.id.protocols.pvp2x.PVPConstants; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ - "/test_ehvd_service_auth.beans.xml" }) -public class InjectEhvdIdentityInformationTaskTest { + "/test_ehvd_qs_service_auth.beans.xml" }) +@IfProfileValue(name = "spring.profiles.active", value = "devEnvironment") +public class InjectEhvdIdentityInformationQsSystemTest { + + @Autowired + InjectEhvdInformationTask task; + @Autowired + DummyAuthConfigMap config; + @Autowired + IRequestStorage storage; - @Autowired InjectEhvdInformationTask task; - @Autowired DummyAuthConfigMap config; - @Autowired IRequestStorage storage; - protected MockHttpServletRequest httpReq; protected MockHttpServletResponse httpResp; private ExecutionContext context; private TestRequestImpl pendingReq; private Map<String, String> spConfigMap; - + @Before public void initialize() throws EAAFParserException { httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); httpResp = new MockHttpServletResponse(); RequestContextHolder.resetRequestAttributes(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); - + context = new ExecutionContextImpl(); spConfigMap = new HashMap<>(); spConfigMap.put(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER, RandomStringUtils.randomAlphanumeric(10)); - - ISPConfiguration spConfig = new DummySPConfiguration(spConfigMap, config); + + final ISPConfiguration spConfig = new DummySPConfiguration(spConfigMap, config); pendingReq = new TestRequestImpl(); pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); pendingReq.setSpConfig(spConfig); - + // re-set config config.putConfigValue("modules.dummyauth.enabled", String.valueOf(true)); - - //inject identityLink - final AuthenticationSessionWrapper moaSession = pendingReq.getSessionData( - AuthenticationSessionWrapper.class); - moaSession.setIdentityLink(TestUtils.generateDummyIdl( - RandomStringUtils.randomAlphanumeric(10), - EAAFConstants.URN_PREFIX_BASEID)); - - } - @Test - public void noIdentityLinkInSession() { - final AuthenticationSessionWrapper moaSession = pendingReq.getSessionData( - AuthenticationSessionWrapper.class); - moaSession.setIdentityLink(null); - - try { - task.execute(pendingReq, context); - fail("wrong state not detected"); - - } catch (TaskExecutionException e) { - Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion"); - assertEquals("wrong errorCode", "process.04", ((EAAFException) e.getOriginalException()).getErrorId()); - - } } - @Test public void validateState() throws TaskExecutionException, PendingReqIdValidationException { + // inject identityLink + final AuthenticationSessionWrapper moaSession = pendingReq.getSessionData( + AuthenticationSessionWrapper.class); + moaSession.setIdentityLink(TestUtils.generateDummyIdl( + RandomStringUtils.randomAlphanumeric(10), + EAAFConstants.URN_PREFIX_BASEID)); task.execute(pendingReq, context); - + // validate state - IRequest storedReq = storage.getPendingRequest(pendingReq.getPendingRequestId()); + final IRequest storedReq = storage.getPendingRequest(pendingReq.getPendingRequestId()); assertNotNull("pendingReq not stored", storedReq); - - final AuthenticationSessionWrapper moaSession = storedReq.getSessionData( + + final AuthenticationSessionWrapper moaSessionStored = storedReq.getSessionData( AuthenticationSessionWrapper.class); + + assertFalse("foreign", moaSessionStored.isForeigner()); + assertFalse("mandate", moaSessionStored.isMandateUsed()); + assertEquals("missing attributes", 1, moaSessionStored.getGenericSessionDataStorage().size()); + assertNotNull("no Role attr", moaSessionStored.getGenericDataFromSession(PVPConstants.ROLES_NAME)); - assertFalse("foreign", moaSession.isForeigner()); - assertFalse("mandate", moaSession.isMandateUsed()); - assertEquals("missing attributes", 1, moaSession.getGenericSessionDataStorage().size()); - - } - + } } diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java new file mode 100644 index 000000000..0c84a7bcf --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java @@ -0,0 +1,961 @@ +package at.gv.egovernment.moa.id.auth.modules.ehvd.test.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.net.SocketTimeoutException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.soap.Detail; +import javax.xml.soap.Name; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.ws.soap.SOAPFaultException; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.Assert; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.TypeInfo; +import org.w3c.dom.UserDataHandler; + +import com.github.skjolber.mockito.soap.Soap12EndpointRule; + +import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.api.IRequestStorage; +import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants; +import at.gv.egiz.eaaf.core.api.data.EAAFConstants; +import at.gv.egiz.eaaf.core.api.idp.ISPConfiguration; +import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; +import at.gv.egiz.eaaf.core.exceptions.EAAFException; +import at.gv.egiz.eaaf.core.exceptions.EAAFParserException; +import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration; +import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; +import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; +import at.gv.egovernment.moa.id.auth.data.AuthenticationSessionWrapper; +import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.EHVD; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GDARoles; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GDAStatus; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaDescriptor; +import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.GdaIndexResponse; +import at.gv.egovernment.moa.id.auth.modules.ehvd.task.InjectEhvdInformationTask; +import at.gv.egovernment.moa.id.auth.modules.ehvd.test.dummy.DummyAuthConfigMap; +import at.gv.egovernment.moa.id.auth.modules.ehvd.test.dummy.TestUtils; +import at.gv.egovernment.moa.id.protocols.pvp2x.PVPConstants; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/test_ehvd_service_auth.beans.xml" }) +public class InjectEhvdIdentityInformationTaskTest { + + @Autowired + InjectEhvdInformationTask task; + @Autowired + DummyAuthConfigMap config; + @Autowired + IRequestStorage storage; + + @Rule + public final Soap12EndpointRule soap = Soap12EndpointRule.newInstance(); + + protected MockHttpServletRequest httpReq; + protected MockHttpServletResponse httpResp; + private ExecutionContext context; + private TestRequestImpl pendingReq; + private Map<String, String> spConfigMap; + + private EHVD ehvdService; + + @Before + public void initialize() throws EAAFParserException { + httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + context = new ExecutionContextImpl(); + + spConfigMap = new HashMap<>(); + spConfigMap.put(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER, RandomStringUtils.randomAlphanumeric(10)); + + final ISPConfiguration spConfig = new DummySPConfiguration(spConfigMap, config); + pendingReq = new TestRequestImpl(); + pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); + pendingReq.setSpConfig(spConfig); + + // re-set config + config.putConfigValue("modules.dummyauth.enabled", String.valueOf(true)); + + // inject identityLink + final AuthenticationSessionWrapper moaSession = pendingReq.getSessionData( + AuthenticationSessionWrapper.class); + moaSession.setIdentityLink(TestUtils.generateDummyIdl( + RandomStringUtils.randomAlphanumeric(10), + EAAFConstants.URN_PREFIX_BASEID)); + + // mock EHVD service + ehvdService = soap.mock(EHVD.class, "http://localhost:1234/ehvd"); + + } + + @Test + public void noIdentityLinkInSession() { + final AuthenticationSessionWrapper moaSession = pendingReq.getSessionData( + AuthenticationSessionWrapper.class); + moaSession.setIdentityLink(null); + + try { + task.execute(pendingReq, context); + fail("wrong state not detected"); + + } catch (final TaskExecutionException e) { + Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion"); + assertEquals("wrong errorCode", "process.04", ((EAAFException) e.getOriginalException()).getErrorId()); + + } + } + + @Test + public void noActiveGda() throws TaskExecutionException, PendingReqIdValidationException { + // set-up EHVD response + String role1 = RandomStringUtils.randomAlphabetic(10); + when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(false, Arrays.asList(role1))); + + try { + task.execute(pendingReq, context); + fail("wrong state not detected"); + + } catch (final TaskExecutionException e) { + Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion"); + assertEquals("wrong errorCode", "ehvd.00", ((EAAFException) e.getOriginalException()).getErrorId()); + + } + } + + @Test + public void gdaGenericServiceError() throws TaskExecutionException, PendingReqIdValidationException { + // set-up EHVD response + when(ehvdService.getGDA(any())).thenThrow(new RuntimeException("No anwser from Service")); + + try { + task.execute(pendingReq, context); + fail("wrong state not detected"); + + } catch (final TaskExecutionException e) { + Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion"); + assertEquals("wrong errorCode", "ehvd.02", ((EAAFException) e.getOriginalException()).getErrorId()); + + } + } + + @Test + public void gdaServiceError() throws TaskExecutionException, PendingReqIdValidationException { + // set-up EHVD response + String msg = RandomStringUtils.randomAlphabetic(10); + SOAPFault fault = generateSoaFault(msg); + SOAPFaultException error = new SOAPFaultException(fault ); + when(ehvdService.getGDA(any())).thenThrow(error); + + try { + task.execute(pendingReq, context); + fail("wrong state not detected"); + + } catch (final TaskExecutionException e) { + Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion"); + assertEquals("wrong errorCode", "ehvd.02", ((EAAFException) e.getOriginalException()).getErrorId()); + + } + } + + @Test + public void validateState() throws TaskExecutionException, PendingReqIdValidationException { + // set-up EHVD response + String role1 = RandomStringUtils.randomAlphabetic(10); + String role2 = RandomStringUtils.randomAlphabetic(10); + when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(true, Arrays.asList(role1, role2))); + + task.execute(pendingReq, context); + + // validate state + final IRequest storedReq = storage.getPendingRequest(pendingReq.getPendingRequestId()); + assertNotNull("pendingReq not stored", storedReq); + + final AuthenticationSessionWrapper moaSession = storedReq.getSessionData( + AuthenticationSessionWrapper.class); + + assertFalse("foreign", moaSession.isForeigner()); + assertFalse("mandate", moaSession.isMandateUsed()); + assertEquals("missing attributes", 1, moaSession.getGenericSessionDataStorage().size()); + assertNotNull("no Role attr", moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME)); + assertEquals("wrong role attr", + role1 + ";" + role2, + moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME, String.class)); + + } + + private GdaIndexResponse generateGdaResponse(boolean isActive, List<String> roles) { + GdaIndexResponse resp = new GdaIndexResponse(); + GdaDescriptor gda = new GdaDescriptor(); + resp.setGda(gda); + + GDAStatus status = new GDAStatus(); + gda.setStatus(status); + status.setEhvdstatus(isActive ? "Aktiv" : "Inaktiv"); + + GDARoles gdaRoles = new GDARoles(); + gda.setRoles(gdaRoles); + gdaRoles.getRole().addAll(roles); + + return resp; + } + + private SOAPFault generateSoaFault(String msg) { + return new SOAPFault() { + + @Override + public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void setIdAttribute(String name, boolean isId) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Attr setAttributeNode(Attr newAttr) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void setAttribute(String name, String value) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public Attr removeAttributeNode(Attr oldAttr) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void removeAttributeNS(String namespaceURI, String localName) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void removeAttribute(String name) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasAttribute(String name) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String getTagName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public TypeInfo getSchemaTypeInfo() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeList getElementsByTagName(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Attr getAttributeNode(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAttributeNS(String namespaceURI, String localName) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAttribute(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object setUserData(String key, Object data, UserDataHandler handler) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setTextContent(String textContent) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void setPrefix(String prefix) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public void setNodeValue(String nodeValue) throws DOMException { + // TODO Auto-generated method stub + + } + + @Override + public Node replaceChild(Node newChild, Node oldChild) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node removeChild(Node oldChild) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void normalize() { + // TODO Auto-generated method stub + + } + + @Override + public String lookupPrefix(String namespaceURI) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String lookupNamespaceURI(String prefix) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isSupported(String feature, String version) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isSameNode(Node other) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isEqualNode(Node arg) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isDefaultNamespace(String namespaceURI) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Node insertBefore(Node newChild, Node refChild) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasChildNodes() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasAttributes() { + // TODO Auto-generated method stub + return false; + } + + @Override + public Object getUserData(String key) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getTextContent() throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getPreviousSibling() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPrefix() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getParentNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Document getOwnerDocument() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getNodeValue() throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public short getNodeType() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getNodeName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getNextSibling() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getNamespaceURI() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getLocalName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getLastChild() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getFirstChild() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getFeature(String feature, String version) { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeList getChildNodes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getBaseURI() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NamedNodeMap getAttributes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public short compareDocumentPosition(Node other) throws DOMException { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Node cloneNode(boolean deep) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node appendChild(Node newChild) throws DOMException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + + @Override + public void setParentElement(SOAPElement parent) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void recycleNode() { + // TODO Auto-generated method stub + + } + + @Override + public String getValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement getParentElement() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void detachNode() { + // TODO Auto-generated method stub + + } + + @Override + public void setEncodingStyle(String encodingStyle) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public SOAPElement setElementQName(QName newName) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean removeNamespaceDeclaration(String prefix) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void removeContents() { + // TODO Auto-generated method stub + + } + + @Override + public boolean removeAttribute(QName qname) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean removeAttribute(Name name) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Iterator getVisibleNamespacePrefixes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getNamespaceURI(String prefix) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getNamespacePrefixes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getEncodingStyle() { + // TODO Auto-generated method stub + return null; + } + + @Override + public QName getElementQName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Name getElementName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getChildElements(QName qname) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getChildElements(Name name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getChildElements() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAttributeValue(QName qname) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAttributeValue(Name name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getAllAttributesAsQNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getAllAttributes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public QName createQName(String localName, String prefix) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addTextNode(String text) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addNamespaceDeclaration(String prefix, String uri) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(String localName, String prefix, String uri) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(String localName, String prefix) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(SOAPElement element) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(String localName) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(QName qname) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addChildElement(Name name) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addAttribute(QName qname, String value) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SOAPElement addAttribute(Name name, String value) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setFaultString(String faultString, Locale locale) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultString(String faultString) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultRole(String uri) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultNode(String uri) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultCode(String faultCode) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultCode(QName faultCodeQName) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultCode(Name faultCodeQName) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void setFaultActor(String faultActor) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void removeAllFaultSubcodes() { + // TODO Auto-generated method stub + + } + + @Override + public boolean hasDetail() { + // TODO Auto-generated method stub + return false; + } + + @Override + public Iterator getFaultSubcodes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Locale getFaultStringLocale() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFaultString() { + return msg; + + } + + @Override + public String getFaultRole() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getFaultReasonTexts() throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFaultReasonText(Locale locale) throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Iterator getFaultReasonLocales() throws SOAPException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFaultNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public QName getFaultCodeAsQName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Name getFaultCodeAsName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFaultCode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFaultActor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Detail getDetail() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void appendFaultSubcode(QName subcode) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public void addFaultReasonText(String text, Locale locale) throws SOAPException { + // TODO Auto-generated method stub + + } + + @Override + public Detail addDetail() throws SOAPException { + // TODO Auto-generated method stub + return null; + } + }; + + } + +} diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/utils/MoaStatusMessagerTest.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/utils/MoaStatusMessagerTest.java index 399980dbf..387aca540 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/utils/MoaStatusMessagerTest.java +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/utils/MoaStatusMessagerTest.java @@ -39,7 +39,7 @@ public class MoaStatusMessagerTest { @Test public void checkErrorMessages() { assertEquals("new error msg", - "GDA Status inaktiv", messager.getMessage("ehvd.00", null)); + "Für den abgefragtem GDA liegt keine Berechtigung vor", messager.getMessage("ehvd.00", null)); assertEquals("new error msg", "Allgemeiner Fehler bei der Abfrage des EHVD Service", messager.getMessage("ehvd.99", null)); diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/com/github/skjolber/mockito/soap/Soap12EndpointRule.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/com/github/skjolber/mockito/soap/Soap12EndpointRule.java new file mode 100644 index 000000000..547401cc3 --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/com/github/skjolber/mockito/soap/Soap12EndpointRule.java @@ -0,0 +1,195 @@ +package com.github.skjolber.mockito.soap; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.ws.soap.SOAPBinding; +import javax.xml.ws.spi.Provider; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.EndpointException; +import org.apache.cxf.endpoint.ServerImpl; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.jaxws.JaxWsServerFactoryBean; +import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean; +import org.apache.cxf.service.ServiceImpl; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.transport.ChainInitiationObserver; +import org.apache.cxf.transport.Destination; +import org.apache.cxf.transport.DestinationFactory; +import org.apache.cxf.transport.DestinationFactoryManager; + + +/** + * Fork of {@link SoapEndpointRule} that set <i>endpoint.setBindingUri(SOAPBinding.SOAP12HTTP_BINDING)</i> + * into {@link EndpointImpl}. + * + * @author tlenz + * + */ +public class Soap12EndpointRule extends SoapServerRule { + private static final int PORT_RANGE_START = 1024 + 1; + private static final int PORT_RANGE_END = PortManager.PORT_RANGE_MAX; + + public static Soap12EndpointRule newInstance() { + return new Soap12EndpointRule(); + } + + private final Map<String, EndpointImpl> endpoints = new HashMap<>(); + + private PortManager<Destination> portManager; + + public Soap12EndpointRule() { + this(PORT_RANGE_START, PORT_RANGE_END); + } + + public Soap12EndpointRule(String... portNames) { + this(PORT_RANGE_START, PORT_RANGE_END, portNames); + } + + public Soap12EndpointRule(int portRangeStart, int portRangeEnd, String... portNames) { + portManager = new PortManager<Destination>(portRangeStart, portRangeEnd) { + @Override + public Destination reserve(int port) throws Exception { + return createDestination(port); + } + + @Override + public void release(Destination destination) { + destination.shutdown(); + } + }; + + portManager.add(portNames); + } + + /** + * Returns the port number that was reserved for the given name. + * + * @param portName port name + * @return a valid port number if the port has been reserved, -1 otherwise + */ + public int getPort(String portName) { + return portManager.getPort(portName); + } + + /** + * Returns all port names and respective port numbers. + * + * @return a map of port name and port value (a valid port number if the port + * has been reserved, or -1 otherwise) + */ + public Map<String, Integer> getPorts() { + return portManager.getPorts(); + } + + /** + * Attempt to reserve a port by starting a server. + * + * @param port port to reserve + * @return destination if successful + * @throws IOException + * @throws EndpointException + */ + private Destination createDestination(int port) throws IOException, EndpointException { + final JaxWsServiceFactoryBean jaxWsServiceFactoryBean = new JaxWsServiceFactoryBean(); + + final JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean(jaxWsServiceFactoryBean); + final Bus bus = serverFactoryBean.getBus(); + + final String address = "http://localhost:" + port; + serverFactoryBean.setAddress(address); + + final DestinationFactory destinationFactory = bus.getExtension(DestinationFactoryManager.class) + .getDestinationFactoryForUri(address); + + final EndpointInfo ei = new EndpointInfo(null, Integer.toString(port)); + ei.setAddress(address); + + final Destination destination = destinationFactory.getDestination(ei, bus); + + final ServiceImpl serviceImpl = new ServiceImpl(); + + final org.apache.cxf.endpoint.Endpoint endpoint = new org.apache.cxf.endpoint.EndpointImpl(bus, + serviceImpl, ei); + destination.setMessageObserver(new ChainInitiationObserver(endpoint, bus)); + return destination; + } + + @Override + public <T> void proxy(T target, Class<T> port, String address, String wsdlLocation, + List<String> schemaLocations, Map<String, Object> properties) { + assertValidParams(target, port, address); + + if (endpoints.containsKey(address)) { + throw new IllegalArgumentException("Endpoint " + address + " already exists"); + } + + final T serviceInterface = SoapServiceProxy.newInstance(target); + + final EndpointImpl endpoint = (EndpointImpl) Provider.provider().createEndpoint(null, serviceInterface); + endpoint.setBindingUri(SOAPBinding.SOAP12HTTP_BINDING); + + if (wsdlLocation != null) { + endpoint.setWsdlLocation(wsdlLocation); + } + + if (schemaLocations != null) { + endpoint.setSchemaLocations(schemaLocations); + } + + endpoint.setProperties(processProperties(properties, wsdlLocation, schemaLocations)); + + final Destination destination = portManager.getData(parsePort(address)); + if (destination != null) { + final ServerImpl server = endpoint.getServer(); + server.setDestination(destination); + } + + endpoint.publish(address); + + endpoints.put(address, endpoint); + } + + @Override + protected void before() { + // reserve all ports + portManager.start(); + } + + @Override + protected void after() { + destroy(); + } + + /** + * Stop and remove endpoints, keeping port reservations. + */ + public void clear() { + endpoints.values().forEach(EndpointImpl::stop); + endpoints.clear(); + } + + @Override + public void destroy() { + endpoints.values().forEach(endpoint -> { + endpoint.stop(); + endpoint.getBus().shutdown(true); + }); + endpoints.clear(); + portManager.stop(); + } + + @Override + public void stop() { + endpoints.values().forEach(endpoint -> endpoint.getServer().stop()); + } + + @Override + public void start() { + // republish + endpoints.values().forEach(endpoint -> endpoint.getServer().start()); + } +} diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config1.properties b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config1.properties index bc71dc6ab..43e900f4b 100644 --- a/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config1.properties +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config1.properties @@ -3,3 +3,6 @@ modules.ehvd.sp.1=aaabbccddeeffgg modules.ehvd.sp.2=yyasdfasfsa2323 modules.ehvd.sp.3= modules.ehvd.sp.4=435344534egewgegf + +modules.ehvd.service.url=http://localhost:1234/ehvd +#modules.ehvd.service.url=https://ehvdwsqs.gesundheit.gv.at diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config_qs_service.properties b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config_qs_service.properties new file mode 100644 index 000000000..13ecdab2b --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/config/config_qs_service.properties @@ -0,0 +1,8 @@ +modules.ehvd.enabled=true +modules.ehvd.sp.1=aaabbccddeeffgg +modules.ehvd.sp.2=yyasdfasfsa2323 +modules.ehvd.sp.3= +modules.ehvd.sp.4=435344534egewgegf + +modules.ehvd.service.url=https://ehvdwsqs.gesundheit.gv.at +modules.ehvd.proxy.socks.port=12345 diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/test_ehvd_qs_service_auth.beans.xml b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/test_ehvd_qs_service_auth.beans.xml new file mode 100644 index 000000000..0595d4eb4 --- /dev/null +++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/resources/test_ehvd_qs_service_auth.beans.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:aop="http://www.springframework.org/schema/aop" + xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + <import resource="classpath:/SpringTest-context_authManager.xml" /> + <import resource="classpath:/moaid_ehvd_service_auth.beans.xml" /> + + <bean id="dummyConfig" class="at.gv.egovernment.moa.id.auth.modules.ehvd.test.dummy.DummyAuthConfigMap"> + <constructor-arg name="path" value="/config/config_qs_service.properties" /> + </bean> + +</beans>
\ No newline at end of file |