diff options
Diffstat (limited to 'connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java')
-rw-r--r-- | connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java | 606 |
1 files changed, 0 insertions, 606 deletions
diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java deleted file mode 100644 index 9f62d41e..00000000 --- a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java +++ /dev/null @@ -1,606 +0,0 @@ -package at.asitplus.eidas.specific.connector.test; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; -import java.math.BigInteger; -import java.net.URISyntaxException; -import java.time.Instant; -import java.util.Map; -import java.util.Timer; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.TransformerException; - -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.ignite.Ignition; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.opensaml.core.config.InitializationException; -import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; -import org.opensaml.core.xml.io.MarshallingException; -import org.opensaml.core.xml.io.UnmarshallingException; -import org.opensaml.core.xml.util.XMLObjectSupport; -import org.opensaml.saml.metadata.resolver.impl.ResourceBackedMetadataResolver; -import org.opensaml.saml.saml2.core.RequestAbstractType; -import org.opensaml.saml.saml2.core.StatusResponseType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.core.io.ResourceLoader; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.util.Base64Utils; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import com.github.skjolber.mockito.soap.SoapServiceRule; - -import at.asitplus.eidas.specific.connector.controller.ProcessEngineSignalController; -import at.asitplus.eidas.specific.connector.controller.Pvp2SProfileEndpoint; -import at.asitplus.eidas.specific.connector.provider.PvpEndPointCredentialProvider; -import at.asitplus.eidas.specific.connector.provider.PvpMetadataProvider; -import at.asitplus.eidas.specific.connector.test.saml2.Pvp2SProfileEndPointTest; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.EidasSignalServlet; -import at.asitplus.eidas.specific.modules.core.eidas.EidasConstants; -import at.asitplus.eidas.specific.modules.core.eidas.service.EidasAttributeRegistry; -import at.gv.bmi.namespace.zmr_su.base._20040201.ResponseType; -import at.gv.bmi.namespace.zmr_su.base._20040201.WorkflowInfoServer; -import at.gv.bmi.namespace.zmr_su.base._20040201_.ServicePort; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasIdentitaetErgebnisType; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.NatuerlichePersonErgebnisType; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.NatuerlichePersonErgebnisType.PersonenName; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonErgebnisSatzType; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonErgebnisType; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenResponse; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.Personendaten; -import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonensuchergebnisType; -import at.gv.e_government.reference.namespace.persondata.de._20040201.IdentificationType; -import at.gv.egiz.components.spring.api.SpringBootApplicationContextInitializer; -import at.gv.egiz.eaaf.core.api.IStatusMessenger; -import at.gv.egiz.eaaf.core.api.data.EaafConstants; -import at.gv.egiz.eaaf.core.api.data.PvpAttributeDefinitions; -import at.gv.egiz.eaaf.core.exceptions.EaafException; -import at.gv.egiz.eaaf.core.impl.idp.controller.ProtocolFinalizationController; -import at.gv.egiz.eaaf.core.impl.logging.LogMessageProviderFactory; -import at.gv.egiz.eaaf.core.impl.utils.DomUtils; -import at.gv.egiz.eaaf.core.impl.utils.Random; -import at.gv.egiz.eaaf.modules.pvp2.exception.CredentialsNotAvailableException; -import at.gv.egiz.eaaf.modules.pvp2.exception.SamlSigningException; -import at.gv.egiz.eaaf.modules.pvp2.impl.opensaml.OpenSaml3ResourceAdapter; -import at.gv.egiz.eaaf.modules.pvp2.impl.opensaml.initialize.EaafOpenSaml3xInitializer; -import at.gv.egiz.eaaf.modules.pvp2.impl.utils.Saml2Utils; -import at.gv.egiz.eaaf.modules.pvp2.sp.impl.utils.AssertionAttributeExtractor; -import eu.eidas.auth.cache.IgniteInstanceInitializerSpecificCommunication; -import eu.eidas.auth.commons.attribute.AttributeDefinition; -import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; -import eu.eidas.auth.commons.light.ILightRequest; -import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; -import eu.eidas.auth.commons.tx.BinaryLightToken; -import eu.eidas.specificcommunication.SpecificCommunicationDefinitionBeanNames; -import eu.eidas.specificcommunication.exception.SpecificCommunicationException; -import eu.eidas.specificcommunication.protocol.SpecificCommunicationService; -import lombok.SneakyThrows; -import lombok.val; -import net.shibboleth.utilities.java.support.component.ComponentInitializationException; -import net.shibboleth.utilities.java.support.xml.XMLParserException; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import szrservices.GetIdentityLinkEidasResponse; -import szrservices.PersonInfoType; -import szrservices.SZR; -import szrservices.SZRException_Exception; -import szrservices.SignContentEntry; -import szrservices.SignContentResponseType; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest -@ContextConfiguration(initializers = { - org.springframework.boot.context.config.DelegatingApplicationContextInitializer.class, - SpringBootApplicationContextInitializer.class - }) -@TestPropertySource(locations = { "file:src/test/resources/config/junit_config_1_springboot.properties" }) -@DirtiesContext(classMode = ClassMode.AFTER_CLASS) -@ActiveProfiles(profiles = {"JUNIT", "jUnitTestMode"}) -public class FullStartUpAndProcessTest { - - private static final String FINAL_REDIRECT = "http://localhost/public/secure/finalizeAuthProtocol?pendingid="; - - @Autowired private WebApplicationContext wac; - @Autowired private PvpEndPointCredentialProvider credentialProvider; - @Autowired private PvpMetadataProvider metadataProvider; - @Autowired private ResourceLoader resourceLoader; - @Autowired private EidasAttributeRegistry attrRegistry; - - @Autowired private Pvp2SProfileEndpoint sProfile; - @Autowired private ProcessEngineSignalController signal; - @Autowired private EidasSignalServlet eidasSignal; - @Autowired private ProtocolFinalizationController finalize; - - @Autowired private IStatusMessenger messager; - - @Rule - public final SoapServiceRule soap = SoapServiceRule.newInstance(); - - private SZR szrMock; - private ServicePort zmrClient; - - private static MockWebServer mockWebServer; - - private String cc; - private String givenName; - private String familyName; - private String dateOfBirth; - private String personalId; - private String pseudonym; - private String vsz; - private String eidasBind; - - - - - - - /** - * jUnit class initializer. - * @throws InterruptedException In case of an error - * @throws ComponentInitializationException In case of an error - * @throws InitializationException In case of an error - * - */ - @BeforeClass - @SneakyThrows - public static void classInitializer() { - final String current = new java.io.File(".").toURI().toString(); - System.clearProperty("eidas.ms.configuration"); - - //eIDAS Ref. Impl. properties - System.setProperty("EIDAS_CONFIG_REPOSITORY", current.substring("file:".length()) - + "../basicConfig/eIDAS/"); - System.setProperty("SPECIFIC_CONNECTOR_CONFIG_REPOSITORY", current.substring("file:".length()) - + "../basicConfig/eIDAS/"); - System.setProperty("SPECIFIC_PROXY_SERVICE_CONFIG_REPOSITORY", current.substring("file:".length()) - + "../basicConfig/eIDAS/"); - - EaafOpenSaml3xInitializer.eaafInitialize(); - - // start ERnP mockup WebServer - mockWebServer = new MockWebServer(); - mockWebServer.start(1718); - - } - - /** - * Test shut-down. - * - * @throws Exception In case of an error - */ - @AfterClass - @SneakyThrows - public static void closeIgniteNode() { - System.out.println("Closiong Ignite Node ... "); - Ignition.stopAll(true); - - //set Ignite-node holder to 'null' because static holders are shared between different tests - final Field field = IgniteInstanceInitializerSpecificCommunication.class.getDeclaredField("instance"); - field.setAccessible(true); - field.set(null, null); - - // shut-down ERnP mock-up WebServer - mockWebServer.shutdown(); - - } - - /** - * jUnit test set-up. - * - * - */ - @Before - public void setup() throws IOException { - DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac); - @SuppressWarnings("rawtypes") - Map<String, FilterRegistrationBean> filters = wac.getBeansOfType(FilterRegistrationBean.class); - for (FilterRegistrationBean<?> filter : filters.values()) { - if (filter.isEnabled()) { - builder.addFilter(filter.getFilter(), "/*"); - - } - } - - LogMessageProviderFactory.setStatusMessager(messager); - - szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr"); - zmrClient = soap.mock(ServicePort.class, "http://localhost:1234/demozmr"); - - - cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); - pseudonym = RandomStringUtils.randomNumeric(64); - personalId = cc + "/AT/" + pseudonym; - familyName = RandomStringUtils.randomAlphabetic(10); - givenName = RandomStringUtils.randomAlphabetic(10); - dateOfBirth = "2015-10-12"; - - vsz = RandomStringUtils.randomNumeric(10); - eidasBind = RandomStringUtils.randomAlphanumeric(50); - - } - - @Test - public void userStopProcess() throws UnsupportedEncodingException, XMLParserException, UnmarshallingException, - TransformerException, IOException, MarshallingException, ComponentInitializationException, EaafException { - //start authentication process by sending a SAML2 Authn-Request - MockHttpServletRequest saml2Req = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - injectSaml2AuthnReq(saml2Req); - MockHttpServletResponse selectCountryResp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(saml2Req, selectCountryResp)); - - // send SAML2 AuthnRequest - sProfile.pvpIdpPostRequest(saml2Req, selectCountryResp); - - //check country-selection response - Assert.assertEquals("no country-selection page", 200, selectCountryResp.getStatus()); - Assert.assertEquals("cc-selection page", "text/html;charset=UTF-8", selectCountryResp.getContentType()); - String selectionPage = selectCountryResp.getContentAsString(); - Assert.assertNotNull("selectionPage is null", selectionPage); - Assert.assertFalse("selectionPage is empty", selectionPage.isEmpty()); - - String pendingReqId = extractRequestToken(selectionPage, - "<input type=\"hidden\" name=\"pendingid\" value=\""); - Assert.assertFalse("PendingReqId", pendingReqId.isEmpty()); - - - // set-up user-stop request - MockHttpServletRequest userStopReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - userStopReq.setParameter("pendingid", pendingReqId); - userStopReq.setParameter(EaafConstants.PARAM_HTTP_STOP_PROCESS, "true"); - - MockHttpServletResponse finalizeResp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(userStopReq, finalizeResp)); - - // send user-stop request - signal.performGenericAuthenticationProcess(userStopReq, finalizeResp); - - //validate state - Assert.assertEquals("forward to finalization", 302, finalizeResp.getStatus()); - Assert.assertNotNull("missing redirect header", finalizeResp.getHeader("Location")); - Assert.assertTrue("wrong redirect header", finalizeResp.getHeader("Location").startsWith(FINAL_REDIRECT)); - String finalPendingReqId = finalizeResp.getHeader("Location").substring(FINAL_REDIRECT.length()); - Assert.assertFalse("final pendingRequestId", finalPendingReqId.isEmpty()); - - //set-up finalization request - MockHttpServletRequest finalizationReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - finalizationReq.setParameter("pendingid", finalPendingReqId); - - MockHttpServletResponse saml2Resp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(finalizationReq, saml2Resp)); - - // exexcute finalization step - finalize.finalizeAuthProtocol(finalizationReq, saml2Resp); - - //validate state - Assert.assertEquals("forward to finalization", 200, saml2Resp.getStatus()); - Assert.assertEquals("forward to eIDAS Node page", "text/html;charset=UTF-8", saml2Resp.getContentType()); - String saml2RespPage = saml2Resp.getContentAsString(); - Assert.assertNotNull("selectionPage is null", saml2RespPage); - Assert.assertFalse("selectionPage is empty", saml2RespPage.isEmpty()); - - //validate SAML2 response - String saml2RespB64 = extractRequestToken(saml2RespPage, - "<input type=\"hidden\" name=\"SAMLResponse\" value=\""); - Assert.assertNotNull("SAML2 response", saml2RespB64); - - StatusResponseType saml2 = (StatusResponseType) XMLObjectSupport.unmarshallFromInputStream( - XMLObjectProviderRegistrySupport.getParserPool(), - new ByteArrayInputStream(Base64Utils.decodeFromString(saml2RespB64))); - Assert.assertEquals("SAML2 status", "urn:oasis:names:tc:SAML:2.0:status:Responder", - saml2.getStatus().getStatusCode().getValue()); - Assert.assertEquals("ms-connector status", "1005", - saml2.getStatus().getStatusCode().getStatusCode().getValue()); - - } - - @Test - public void fullSuccessProcess() throws EaafException, Exception { - //start authentication process by sending a SAML2 Authn-Request - MockHttpServletRequest saml2Req = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - injectSaml2AuthnReq(saml2Req); - MockHttpServletResponse selectCountryResp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(saml2Req, selectCountryResp)); - - // send SAML2 AuthnRequest - sProfile.pvpIdpPostRequest(saml2Req, selectCountryResp); - - //check country-selection response - Assert.assertEquals("no country-selection page", 200, selectCountryResp.getStatus()); - Assert.assertEquals("cc-selection page", "text/html;charset=UTF-8", selectCountryResp.getContentType()); - String selectionPage = selectCountryResp.getContentAsString(); - Assert.assertNotNull("selectionPage is null", selectionPage); - Assert.assertFalse("selectionPage is empty", selectionPage.isEmpty()); - - String pendingReqId = extractRequestToken(selectionPage, - "<input type=\"hidden\" name=\"pendingid\" value=\""); - Assert.assertFalse("PendingReqId", pendingReqId.isEmpty()); - - - // set-up country-selection request - MockHttpServletRequest selectCountryReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - selectCountryReq.setParameter("pendingid", pendingReqId); - selectCountryReq.setParameter("selectedCountry", cc); - - MockHttpServletResponse forwardEidasNodeResp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(selectCountryReq, forwardEidasNodeResp)); - - // send country-selection request - signal.performGenericAuthenticationProcess(selectCountryReq, forwardEidasNodeResp); - - //check forward to eIDAS node response - Assert.assertEquals("forward to eIDAS Node", 200, forwardEidasNodeResp.getStatus()); - Assert.assertEquals("forward to eIDAS Node page", "text/html;charset=UTF-8", forwardEidasNodeResp.getContentType()); - String forwardPage = forwardEidasNodeResp.getContentAsString(); - Assert.assertNotNull("forward to eIDAS Node is null", forwardPage); - Assert.assertFalse("forward to eIDAS Node is empty", forwardPage.isEmpty()); - - String eidasNodeReqToken = extractRequestToken(forwardPage, - "<input type=\"hidden\" name=\"token\" value=\""); - Assert.assertFalse("eidas req. token", eidasNodeReqToken.isEmpty()); - - //check eIDAS node request and build respose - String eidasRespToken = validateEidasNodeRequestAndBuildResponse(eidasNodeReqToken); - Assert.assertFalse("eidas resp. token", eidasRespToken.isEmpty()); - - - // set-up eIDAS-node response - MockHttpServletRequest eidasNodeRespReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - eidasNodeRespReq.setParameter("token", eidasRespToken); - - MockHttpServletResponse finalizeResp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(eidasNodeRespReq, finalizeResp)); - - // inject ZMR, ERnP and SZR responses for matching - injectZmrResponse(); - injectSzrResponse(); - mockWebServer.enqueue(new MockResponse().setResponseCode(200) - .setBody("{}") // empty response because we simulate result from ZMR - .setHeader("Content-Type", "application/json;charset=utf-8")); - - //excute eIDAS node response - eidasSignal.restoreEidasAuthProcess(eidasNodeRespReq, finalizeResp); - - //validate state - Assert.assertEquals("forward to finalization", 302, finalizeResp.getStatus()); - Assert.assertNotNull("missing redirect header", finalizeResp.getHeader("Location")); - Assert.assertTrue("wrong redirect header", finalizeResp.getHeader("Location").startsWith(FINAL_REDIRECT)); - String finalPendingReqId = finalizeResp.getHeader("Location").substring(FINAL_REDIRECT.length()); - Assert.assertFalse("final pendingRequestId", finalPendingReqId.isEmpty()); - - - //set-up finalization request - MockHttpServletRequest finalizationReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); - finalizationReq.setParameter("pendingid", finalPendingReqId); - - MockHttpServletResponse saml2Resp = new MockHttpServletResponse(); - RequestContextHolder.resetRequestAttributes(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(finalizationReq, saml2Resp)); - - // exexcute finalization step - finalize.finalizeAuthProtocol(finalizationReq, saml2Resp); - - //validate state - Assert.assertEquals("forward to finalization", 200, saml2Resp.getStatus()); - Assert.assertEquals("forward to eIDAS Node page", "text/html;charset=UTF-8", saml2Resp.getContentType()); - String saml2RespPage = saml2Resp.getContentAsString(); - Assert.assertNotNull("selectionPage is null", saml2RespPage); - Assert.assertFalse("selectionPage is empty", saml2RespPage.isEmpty()); - - //validate SAML2 response - String saml2RespB64 = extractRequestToken(saml2RespPage, - "<input type=\"hidden\" name=\"SAMLResponse\" value=\""); - Assert.assertNotNull("SAML2 response", saml2RespB64); - - StatusResponseType saml2 = (StatusResponseType) XMLObjectSupport.unmarshallFromInputStream( - XMLObjectProviderRegistrySupport.getParserPool(), - new ByteArrayInputStream(Base64Utils.decodeFromString(saml2RespB64))); - Assert.assertEquals("SAML2 status", EidasConstants.SUCCESS_URI, saml2.getStatus().getStatusCode().getValue()); - - final AssertionAttributeExtractor extractor = new AssertionAttributeExtractor(saml2); - - Assert.assertEquals("wrong resp attr. size", 7, extractor.getAllIncludeAttributeNames().size()); - Assert.assertEquals("Wrong attr: LoA ", "http://eidas.europa.eu/LoA/high", - extractor.getSingleAttributeValue("urn:oid:1.2.40.0.10.2.1.1.261.108")); - Assert.assertEquals("Wrong attr: PVP_VERSION ", "2.2", - extractor.getSingleAttributeValue("urn:oid:1.2.40.0.10.2.1.1.261.10")); - Assert.assertEquals("Wrong attr: EID_ISSUER_NATION ", cc, - extractor.getSingleAttributeValue("urn:oid:1.2.40.0.10.2.1.1.261.32")); - Assert.assertEquals("Wrong attr: eidasBind", eidasBind, - extractor.getSingleAttributeValue("urn:eidgvat:attributes.eidbind")); - Assert.assertNotNull("Wrong attr: authBlock", - extractor.getSingleAttributeValue("urn:eidgvat:attributes.authblock.signed")); - Assert.assertNotNull("Wrong attr: piiTras.Id ", - extractor.getSingleAttributeValue("urn:eidgvat:attributes.piiTransactionId")); - Assert.assertEquals("Wrong attr:EID_STATUS_LEVEL ", "http://eid.gv.at/eID/status/identity", - extractor.getSingleAttributeValue(PvpAttributeDefinitions.EID_IDENTITY_STATUS_LEVEL_NAME)); - - } - - private void injectSzrResponse() throws Exception { - when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz); - - val signContentResp = new SignContentResponseType(); - final SignContentEntry signContentEntry = new SignContentEntry(); - signContentEntry.setValue(eidasBind); - signContentResp.getOut().add(signContentEntry); - when(szrMock.signContent(any(), any(), any())).thenReturn(signContentResp); - - } - - private void injectZmrResponse() throws Exception { - ResponseType resp = new ResponseType(); - - WorkflowInfoServer workflow = new WorkflowInfoServer(); - workflow.setProzessInstanzID(new BigInteger(RandomStringUtils.randomNumeric(10))); - resp.setWorkflowInfoServer(workflow); - - PersonSuchenResponse persRespObj = new PersonSuchenResponse(); - PersonensuchergebnisType searchResult = new PersonensuchergebnisType(); - PersonErgebnisSatzType personInfoObj = new PersonErgebnisSatzType(); - resp.setPersonSuchenResponse(persRespObj); - persRespObj.setPersonensuchergebnis(searchResult); - - searchResult.setGefundeneSaetzeERnP(0); - searchResult.setGefundeneSaetze(1); - searchResult.getPersonErgebnisSatz().add(personInfoObj); - - PersonErgebnisType personInfo = new PersonErgebnisType(); - Personendaten personDataObj = new Personendaten(); - personInfoObj.setPersonendaten(personDataObj); - personDataObj.getPersonErgebnis().add(personInfo); - - EidasIdentitaetErgebnisType eidasPersonalIdentifier = new EidasIdentitaetErgebnisType(); - personInfo.getEidasIdentitaet().add(eidasPersonalIdentifier); - eidasPersonalIdentifier.setEidasWert(pseudonym); - eidasPersonalIdentifier.setEidasArt(EidasConstants.eIDAS_ATTRURN_PERSONALIDENTIFIER); - eidasPersonalIdentifier.setStaatscode2(cc); - - NatuerlichePersonErgebnisType natInfo = new NatuerlichePersonErgebnisType(); - IdentificationType bpk = new IdentificationType(); - PersonenName natName = new PersonenName(); - natInfo.getIdentification().add(bpk); - natInfo.setPersonenName(natName); - personInfo.setNatuerlichePerson(natInfo); - - bpk.setType(EaafConstants.URN_PREFIX_CDID + "ZP"); - bpk.setValue(RandomStringUtils.randomAlphabetic(10)); - natInfo.setGeburtsdatum(dateOfBirth); - natName.setFamilienname(familyName); - natName.setVorname(givenName); - - when(zmrClient.service(any(), any())).thenReturn(resp); - - } - - - private String validateEidasNodeRequestAndBuildResponse(String eidasNodeReqToken) - throws SpecificCommunicationException, URISyntaxException { - final SpecificCommunicationService springManagedSpecificConnectorCommunicationService = - (SpecificCommunicationService) wac.getBean( - SpecificCommunicationDefinitionBeanNames.SPECIFIC_CONNECTOR_COMMUNICATION_SERVICE.toString()); - - //read request and validate basic properties - ILightRequest req = springManagedSpecificConnectorCommunicationService.getAndRemoveRequest(eidasNodeReqToken, - attrRegistry.getCoreAttributeRegistry().getAttributes()); - - Assert.assertNotNull("eIDAS Node req", req); - Assert.assertEquals("Wrong CC", cc, req.getCitizenCountryCode()); - Assert.assertEquals("Wrong CC", EaafConstants.EIDAS_LOA_HIGH, req.getLevelOfAssurance()); - - - //set response from eIDAS node - BinaryLightToken respoToken = springManagedSpecificConnectorCommunicationService.putResponse( - buildDummyAuthResponse(EidasConstants.SUCCESS_URI, req.getId())); - return Base64Utils.encodeToString(respoToken.getTokenBytes()); - - } - - private AuthenticationResponse buildDummyAuthResponse(String statusCode, String reqId) throws URISyntaxException { - final AttributeDefinition<?> attributeDef = attrRegistry.getCoreAttributeRegistry().getByFriendlyName( - EidasConstants.eIDAS_ATTR_PERSONALIDENTIFIER).first(); - final AttributeDefinition<?> attributeDef2 = attrRegistry.getCoreAttributeRegistry().getByFriendlyName( - EidasConstants.eIDAS_ATTR_CURRENTFAMILYNAME).first(); - final AttributeDefinition<?> attributeDef3 = attrRegistry.getCoreAttributeRegistry().getByFriendlyName( - EidasConstants.eIDAS_ATTR_CURRENTGIVENNAME).first(); - final AttributeDefinition<?> attributeDef4 = attrRegistry.getCoreAttributeRegistry().getByFriendlyName( - EidasConstants.eIDAS_ATTR_DATEOFBIRTH).first(); - - final ImmutableAttributeMap attributeMap = ImmutableAttributeMap.builder() - .put(attributeDef, personalId) - .put(attributeDef2, familyName) - .put(attributeDef3, givenName) - .put(attributeDef4, dateOfBirth).build(); - - val b = new AuthenticationResponse.Builder(); - return b.id("_".concat(Random.nextHexRandom16())) - .issuer(RandomStringUtils.randomAlphabetic(10)) - .subject(RandomStringUtils.randomAlphabetic(10)) - .statusCode(statusCode) - .inResponseTo(reqId) - .subjectNameIdFormat("afaf") - .levelOfAssurance(EaafConstants.EIDAS_LOA_HIGH) - .attributes(attributeMap) - .build(); - - } - - private String extractRequestToken(String selectionPage, String selector) { - int start = selectionPage.indexOf(selector); - Assert.assertTrue("find no pendingReqId location start", start > 0); - int end = selectionPage.indexOf("\"", start + selector.length()); - Assert.assertTrue("find no pendingReqId location end", end > 0); - return selectionPage.substring(start + selector.length(), end); - - } - - private void injectSaml2AuthnReq(MockHttpServletRequest saml2Req) throws XMLParserException, UnmarshallingException, - SamlSigningException, CredentialsNotAvailableException, UnsupportedEncodingException, TransformerException, - IOException, MarshallingException, ComponentInitializationException { - final RequestAbstractType authnReq = (RequestAbstractType) XMLObjectSupport.unmarshallFromInputStream( - XMLObjectProviderRegistrySupport.getParserPool(), - Pvp2SProfileEndPointTest.class.getResourceAsStream("/data/pvp2_authn_1.xml")); - authnReq.setIssueInstant(Instant.now()); - RequestAbstractType signedAuthnReq = - Saml2Utils.signSamlObject(authnReq, credentialProvider.getMessageSigningCredential(), true); - String b64 = Base64Utils.encodeToString(DomUtils.serializeNode( - XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8")); - saml2Req.setParameter("SAMLRequest", b64); - - final org.springframework.core.io.Resource resource = resourceLoader.getResource( - "classpath:/data/metadata_valid_without_encryption.xml"); - Timer timer = new Timer("PVP metadata-resolver refresh"); - ResourceBackedMetadataResolver fileSystemResolver = - new ResourceBackedMetadataResolver(timer, new OpenSaml3ResourceAdapter(resource)); - fileSystemResolver.setId("test"); - fileSystemResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool()); - fileSystemResolver.initialize(); - metadataProvider.addMetadataResolverIntoChain(fileSystemResolver); - - } - - private void setSzrResponseIdentityLink(String responseXmlPath) throws JAXBException, SZRException_Exception { - final JAXBContext jaxbContext = JAXBContext - .newInstance(szrservices.ObjectFactory.class, org.w3._2001._04.xmldsig_more.ObjectFactory.class, - org.w3._2000._09.xmldsig.ObjectFactory.class, - at.gv.e_government.reference.namespace.persondata._20020228.ObjectFactory.class); - final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - final GetIdentityLinkEidasResponse szrResponse = (GetIdentityLinkEidasResponse) jaxbUnmarshaller - .unmarshal(this.getClass().getResourceAsStream(responseXmlPath)); - org.mockito.Mockito.when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse.getGetIdentityLinkReturn()); - - } - -} |