package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.math.BigInteger; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.namespace.QName; import org.apache.commons.lang3.RandomStringUtils; import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; 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.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 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.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient.ErnpRegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.IErnpClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.IZmrClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient.ZmrRegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MatchedPersonResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcessingException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPreProcessingException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasAttributeException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.CountrySpecificDetailSearchProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.GenericEidProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.log.statistic.DetailedMatchtingStatistic; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidProcessingService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterOperationStatus; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.AlternativeSearchTask; import at.asitplus.eidas.specific.modules.auth.eidas.v2.test.clients.ZmrClientTest; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.asitplus.eidas.specific.modules.core.eidas.EidasConstants; import at.gv.bmi.namespace.zmr_su.base._20040201.RequestType; import at.gv.bmi.namespace.zmr_su.base._20040201.ResponseType; import at.gv.bmi.namespace.zmr_su.base._20040201_.ServicePort; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasIdentitaetAnlageType; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasSuchdatenType; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.IRequestStorage; 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.EaafStorageException; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper; import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; import eu.eidas.auth.commons.attribute.AttributeDefinition; import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; import eu.eidas.auth.commons.attribute.PersonType; import eu.eidas.auth.commons.light.impl.LightRequest; import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; import lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/SpringTest-context_tasks_test.xml", "/SpringTest-context_basic_mapConfig.xml", "/SpringTest-context_ccSearchProcessor_test.xml" }) @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) public class AlternativeSearchTaskWithRegisterTest { @Rule public SoapServiceRule soap = SoapServiceRule.newInstance(); @Mock private IErnpClient ernpClient; @Autowired private IZmrClient zmrClient; @Autowired private List handlers; @Autowired(required = true) protected IRequestStorage requestStoreage; private RegisterSearchService registerSearchService; private ServicePort zmrMock = null; private final ICcSpecificEidProcessingService eidPostProcessor = createEidPostProcessor(); private AlternativeSearchTask task; final ExecutionContext executionContext = new ExecutionContextImpl(); private TestRequestImpl pendingReq; private static JAXBContext jaxbContext; /** * Initialize jUnit class. */ @BeforeClass @SneakyThrows public static void classInitializer() { jaxbContext = JAXBContext.newInstance( at.gv.bmi.namespace.zmr_su.zmr._20040201.ObjectFactory.class, at.gv.bmi.namespace.zmr_su.gis._20070725.ObjectFactory.class, at.gv.bmi.namespace.zmr_su.base._20040201.ObjectFactory.class); } /** * jUnit test set-up. */ @Before public void setUp() throws URISyntaxException, EaafStorageException { if (zmrMock == null) { zmrMock = soap.mock(ServicePort.class, "http://localhost:1234/demozmr"); } registerSearchService = new RegisterSearchService(handlers, zmrClient, ernpClient); task = new AlternativeSearchTask(registerSearchService, eidPostProcessor); task.setRequestStoreage(requestStoreage); MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); MockHttpServletResponse httpResp = new MockHttpServletResponse(); RequestContextHolder.resetRequestAttributes(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); pendingReq = new TestRequestImpl(); } @Test @SneakyThrows public void missingStateInfoFirstEidasData() { // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults(null, Arrays.asList(RegisterResult.builder() .bpk("") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); assertEquals("wrong errorparam 1", "step11", ((EaafException) exception.getOriginalException()).getParams()[0]); assertTrue("Wrong flag 'step11'", ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); assertEquals("wrong errorparam 1", "No initial eIDAS authn data", ((EaafException) exception.getOriginalException()).getParams()[1]); } @Test @SneakyThrows public void missingStateInfoIntermediateMatchingState() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .build()); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); assertEquals("wrong errorparam 1", "step11", ((EaafException) exception.getOriginalException()).getParams()[0]); assertTrue("Wrong flag 'step11'", ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); assertEquals("wrong errorparam 1", "No intermediate matching-state", ((EaafException) exception.getOriginalException()).getParams()[1]); } @Test @SneakyThrows public void countryCodeNotMatch() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults(null, Arrays.asList(RegisterResult.builder() .bpk("") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "EE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // execute task task.execute(pendingReq, executionContext); // validate state assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); assertNull("final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq)); assertEquals("wrong executionContextFlag 'alternative eIDAS result'", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED)); assertEquals("failed reason", "module.eidasauth.matching.26", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON)); } @Test @SneakyThrows public void mdsNoMatch() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults(null, Arrays.asList(RegisterResult.builder() .bpk("") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXClaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1995-12-31")); // execute task task.execute(pendingReq, executionContext); // validate state assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); assertNull("final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq)); assertEquals("wrong executionContextFlag 'alternative eIDAS result'", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED)); assertEquals("failed reason", "module.eidasauth.matching.26", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON)); } @Test @SneakyThrows public void seachPersonalIdMoreThanOneResult() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); assertEquals("wrong errorparam 1", "searchWithPersonalIdentifier", ((EaafException) exception.getOriginalException()).getParams()[0]); assertTrue("Wrong flag 'step11'", ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); checkBasicRequestParameters(zmrReq.getValue(), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkEidasDocumentResult(zmrReq.getValue().getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); } @Test @SneakyThrows public void seachPersonalIdNoBpkMatchWithIntermediateResults() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults(null, Arrays.asList(RegisterResult.builder() .bpk("notExists") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-8_search_with_personalId_only_resp.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier(any(), any())) .thenReturn(emptyErnpRegisterResult()); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); assertEquals("wrong errorparam 1", "step7bKittProcess", ((EaafException) exception.getOriginalException()).getParams()[0]); assertFalse("Wrong flag 'step11'", ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); assertEquals("wrong errorparam 1", "Register result from alternativ authentication does not fit into intermediate state", ((EaafException) exception.getOriginalException()).getParams()[1]); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkEidasDocumentResult(zmrReq.getValue().getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); } @Test @SneakyThrows public void seachPersonalIdSuccess() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-8_search_with_personalId_only_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-4_kitt_get_latest_version_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-6_kitt_update_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-8_kitt_get_latest_version_resp.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier(any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchWithMds(any(), any(), any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); // execute task task.execute(pendingReq, executionContext); // validate state //INFO: has to be the old givenName because ZMR allows no update of MDS information checkMatchingSuccessState(pendingReq, "UgeknNsc26lVuB7U/uYGVmWtnnA=", "XXXvon Brandenburg", "XXXClaus - Maria", "1994-12-31", "DE"); assertNull("wrong executionContextFlag 'alternative eIDAS result'", executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); // validate request assertEquals("wrong number of req.", 4, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(0), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(0).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); assertNotNull("Personensuche KITT req.", zmrReq.getAllValues().get(1).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(1), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertNotNull("PersonAender KITT req.", zmrReq.getAllValues().get(2).getPersonAendernRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(2), ZmrClientTest.PROCESS_TASK_UPDATE, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertEquals("wrong number of eIDAS Docs to Add", 4, zmrReq.getAllValues().get(2).getPersonAendernRequest().getEidasIdentitaetAnlage().size()); checkEidasDocumentAdd(zmrReq.getAllValues().get(2).getPersonAendernRequest().getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/DateOfBirth", "DE", "1994-12-31"); checkEidasDocumentAdd(zmrReq.getAllValues().get(2).getPersonAendernRequest().getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentGivenName", "DE", "XXXKlaus - Maria"); checkEidasDocumentAdd(zmrReq.getAllValues().get(2).getPersonAendernRequest().getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName", "DE", "XXXvon Brandenburg"); assertNotNull("Personensuche KITT req.", zmrReq.getAllValues().get(3).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(3), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); DetailedMatchtingStatistic entry = MatchingTaskUtils.getDetailedMatchingStatistic(pendingReq); assertNotNull("statisticLogEntry", entry); assertEquals("use eIDAS count", 1, entry.getEidasLoginUsed()); } @Test @SneakyThrows public void seachCcSpecificSuccess() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31", null, "Hintergigritzpotschn", "XXXvon Heuburg")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-8_search_with_personalId_only_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-4_kitt_get_latest_version_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-6_kitt_update_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-8_kitt_get_latest_version_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_3-10_kitt_update_resp.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier(any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchCountrySpecific(any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchWithMds(any(), any(), any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); // execute task task.execute(pendingReq, executionContext); // validate state //INFO: has to be the old givenName because ZMR allows no update of MDS information checkMatchingSuccessState(pendingReq, "UgeknNsc26lVuB7U/uYGVmWtnnA=", "XXXvon Brandenburg", "XXXClaus - Maria", "1994-12-31", "DE"); assertNull("wrong executionContextFlag 'alternative eIDAS result'", executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); // validate request assertEquals("wrong number of req.", 6, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(0), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(0).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); assertNotNull("Personensuche CC-specific req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(1), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", "DE", "Hintergigritzpotschn"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", "DE", "XXXvon Heuburg"); assertNotNull("Personensuche KITT req.", zmrReq.getAllValues().get(2).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(2), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertNotNull("PersonAender KITT req.", zmrReq.getAllValues().get(3).getPersonAendernRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(3), ZmrClientTest.PROCESS_TASK_UPDATE, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertNotNull("Personensuche KITT req.", zmrReq.getAllValues().get(4).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(4), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); assertNotNull("PersonAender KITT req.", zmrReq.getAllValues().get(5).getPersonAendernRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(5), ZmrClientTest.PROCESS_TASK_UPDATE, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); } @Test @SneakyThrows public void seachCcSpecificNotPossible() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("EE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "EE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31", null, "Hintergigritzpotschn", "XXXvon Heuburg")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier(any(), any())) .thenReturn(emptyErnpRegisterResult()); // execute task task.execute(pendingReq, executionContext); // validate state assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); assertNull("final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq)); assertEquals("wrong executionContextFlag 'alternative eIDAS result'", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(0), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(0).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "EE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); } @Test @SneakyThrows public void seachCcSpecificMoreThanOneResult() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31", null, "Hintergigritzpotschn", "XXXvon Heuburg")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenReturn(loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier(any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchWithMds(any(), any(), any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); assertEquals("wrong errorparam 1", "searchWithCountrySpecifics", ((EaafException) exception.getOriginalException()).getParams()[0]); assertTrue("Wrong flag 'step11'", ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); // validate request assertEquals("wrong number of req.", 2, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(0), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(0).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); assertNotNull("Personensuche CC-specific req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(1), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", "DE", "Hintergigritzpotschn"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", "DE", "XXXvon Heuburg"); } @Test @SneakyThrows public void seachCcSpecificEmptyResult() { //inject initial eIDAS data MatchingTaskUtils.storeInitialEidasData(pendingReq, SimpleEidasData.builder() .personalIdentifier("DE/AT/7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .pseudonym("cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .citizenCountryCode("DE") .build()); // inject matching intermediate state RegisterStatusResults matchingState = new RegisterStatusResults( new RegisterOperationStatus(new BigInteger(RandomStringUtils.randomNumeric(5)), true), Arrays.asList(RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .givenName("XXXKlaus - Maria") .familyName("XXXvon Brandenburg") .dateOfBirth("1994-12-31") .pseudonym(Arrays.asList("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build()), Collections.emptyList()); MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, matchingState ); //inject alternative eIDAS data pendingReq.getSessionData(AuthProcessDataWrapper.class).setGenericDataToSession( Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, buildDummyAuthResponse("XXXKlaus - Maria", "XXXvon Brandenburg", "DE/AT/7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "1994-12-31", null, "Hintergigritzpotschn", "XXXvon Heuburg")); // inject response final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenThrow(new RuntimeException("This request is not needed any more")); Mockito.when(ernpClient.searchWithPersonIdentifier("7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", "DE")) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchCountrySpecific(any(), any())) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); // execute task task.execute(pendingReq, executionContext); // validate state assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); assertNull("final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq)); assertEquals("wrong executionContextFlag 'alternative eIDAS result'", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK)); assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED)); assertEquals("failed reason", "module.eidasauth.matching.25", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON)); // validate request assertEquals("wrong number of req.", 2, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(0), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(0).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", "DE", "7cEYasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"); assertNotNull("Personensuche CC-specific req.", zmrReq.getAllValues().get(0).getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getAllValues().get(1), ZmrClientTest.PROCESS_TASK_SEARCH, matchingState.getOperationStatus().getZmrProcessId(), "jUnit123456"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", "DE", "Hintergigritzpotschn"); checkEidasDocumentResult(zmrReq.getAllValues().get(1).getPersonSuchenRequest().getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", "DE", "XXXvon Heuburg"); } @NotNull private ICcSpecificEidProcessingService createEidPostProcessor() { return new ICcSpecificEidProcessingService() { private final GenericEidProcessor genericEidProcessor = new GenericEidProcessor(); @Override public SimpleEidasData postProcess(Map eidasAttrMap) throws EidPostProcessingException, EidasAttributeException { return genericEidProcessor.postProcess(eidasAttrMap); } @Override public void preProcess(String selectedCC, IRequest pendingReq, LightRequest.Builder authnRequestBuilder) throws EidPreProcessingException { genericEidProcessor.preProcess(pendingReq, authnRequestBuilder, selectedCC); } }; } @NotNull private ZmrRegisterResult zmrRegisterResult(RegisterResult registerResult, BigInteger processId) { return new ZmrRegisterResult(Collections.singletonList(registerResult), processId); } @NotNull private ZmrRegisterResult zmrRegisterResult(RegisterResult registerResult) { return zmrRegisterResult(registerResult, generateRandomProcessId()); } private BigInteger generateRandomProcessId() { return new BigInteger(RandomStringUtils.randomNumeric(10)); } private void checkMatchingSuccessState(IRequest pendingReq, String bpk, String familyName, String givenName, String birhday, String countryCode) { assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); MatchedPersonResult personInfo = MatchingTaskUtils.getFinalMatchingResult(pendingReq); assertNotNull("no final matching result", personInfo); assertEquals("wrong bpk", bpk, personInfo.getBpk()); assertEquals("wrong givenName", givenName, personInfo.getGivenName()); assertEquals("wrong familyName", familyName, personInfo.getFamilyName()); assertEquals("wrong dateOfBirth", birhday, personInfo.getDateOfBirth()); assertEquals("wrong countryCode", countryCode, personInfo.getCountryCode()); } @NotNull private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier, String dateOfBirth) throws URISyntaxException { return buildDummyAuthResponse(givenName, familyName, identifier, dateOfBirth, null, null, null); } @NotNull private AuthenticationResponse buildDummyAuthResponseDE(String givenName, String familyName, String identifier, String dateOfBirth, String placeOfBirth, String birthName) throws URISyntaxException { return buildDummyAuthResponse(givenName, familyName, identifier, dateOfBirth, null, placeOfBirth, birthName); } @NotNull private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier, String dateOfBirth, String taxNumber, String placeOfBirth, String birthName) throws URISyntaxException { ImmutableAttributeMap.Builder builder = ImmutableAttributeMap.builder() .put(generateStringAttribute(EidasConstants.eIDAS_ATTR_PERSONALIDENTIFIER, randomAlphabetic(2), randomAlphabetic(2)), identifier) .put(generateStringAttribute(EidasConstants.eIDAS_ATTR_CURRENTFAMILYNAME, randomAlphabetic(3), randomAlphabetic(3)), familyName) .put(generateStringAttribute(EidasConstants.eIDAS_ATTR_CURRENTGIVENNAME, randomAlphabetic(4), randomAlphabetic(4)), givenName) .put(generateDateTimeAttribute(EidasConstants.eIDAS_ATTR_DATEOFBIRTH, randomAlphabetic(5), randomAlphabetic(5)), dateOfBirth); if (taxNumber != null) { builder.put(generateStringAttribute(EidasConstants.eIDAS_ATTR_TAXREFERENCE, randomAlphabetic(6), randomAlphabetic(6)), taxNumber); } if (birthName != null) { builder.put(generateStringAttribute(EidasConstants.eIDAS_ATTR_BIRTHNAME, randomAlphabetic(7), randomAlphabetic(7)), birthName); } if (placeOfBirth != null) { builder.put(generateStringAttribute(EidasConstants.eIDAS_ATTR_PLACEOFBIRTH, randomAlphabetic(8), randomAlphabetic(8)), placeOfBirth); } final ImmutableAttributeMap attributeMap = builder.build(); return new AuthenticationResponse.Builder().id(randomAlphabetic(5)) .issuer(randomAlphabetic(5)).subject(randomAlphabetic(5)).statusCode("200") .inResponseTo(randomAlphabetic(5)).subjectNameIdFormat(randomAlphabetic(5)) .attributes(attributeMap).build(); } private AttributeDefinition generateStringAttribute(String friendlyName, String fragment, String prefix) throws URISyntaxException { return generateAttribute(friendlyName, fragment, prefix, "eu.eidas.auth.commons.attribute.impl" + ".LiteralStringAttributeValueMarshaller"); } @SuppressWarnings("SameParameterValue") private AttributeDefinition generateDateTimeAttribute(String friendlyName, String fragment, String prefix) throws URISyntaxException { return generateAttribute(friendlyName, fragment, prefix, "eu.eidas.auth.commons.attribute.impl" + ".DateTimeAttributeValueMarshaller"); } private AttributeDefinition generateAttribute(String friendlyName, String fragment, String prefix, String marshaller) throws URISyntaxException { return AttributeDefinition.builder() .friendlyName(friendlyName).nameUri(new URI("ad", "sd", fragment)) .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", prefix)) .attributeValueMarshaller(marshaller).build(); } private ResponseType loadResponseFromFile(String filepath) throws JAXBException { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement resp = (JAXBElement) unmarshaller.unmarshal(ZmrClientTest.class.getResourceAsStream( filepath)); return (ResponseType) resp.getValue(); } private void checkBasicRequestParameters(RequestType requestType, String vorgangName, BigInteger processId, String behoerdennummer) { assertNotNull("no workflow infos", requestType.getWorkflowInfoClient()); assertEquals("processName", ZmrClientTest.PROCESS_GENERAL, requestType.getWorkflowInfoClient().getProzessName()); assertEquals("vorgangsName", vorgangName, requestType.getWorkflowInfoClient().getVorgangName()); if (processId != null) { assertEquals("processId", processId, requestType.getWorkflowInfoClient().getProzessInstanzID()); } else { assertNull("processId", requestType.getWorkflowInfoClient().getProzessInstanzID()); } assertNotNull("no client infos", requestType.getClientInfo()); assertEquals("behoerdennummer", behoerdennummer, requestType.getClientInfo().getOrganisation() .getBehoerdenNr()); } private void checkEidasDocumentResult(List list, String type, String cc, String value) { Optional eidasDoc = list.stream() .filter(el -> type.equals(el.getEidasArt())) .findFirst(); assertTrue("eidas doc: " + type, eidasDoc.isPresent()); assertEquals("eIDAS docType", type, eidasDoc.get().getEidasArt()); assertEquals("eIDAS docValue", value, eidasDoc.get().getEidasWert()); assertEquals("eIDAS docCC", cc, eidasDoc.get().getStaatscode2()); } private void checkEidasDocumentAdd(List list, String type, String cc, String value) { Optional eidasDoc = list.stream() .filter(el -> type.equals(el.getEidasArt())) .findFirst(); assertTrue("eidas doc: " + type, eidasDoc.isPresent()); assertEquals("eIDAS docType", type, eidasDoc.get().getEidasArt()); assertEquals("eIDAS docValue", value, eidasDoc.get().getEidasWert()); assertEquals("eIDAS docCC", cc, eidasDoc.get().getStaatscode2()); } @NotNull private ErnpRegisterResult emptyErnpRegisterResult() { return new ErnpRegisterResult(Collections.emptyList()); } }