diff options
Diffstat (limited to 'connector')
6 files changed, 369 insertions, 16 deletions
diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java index 81ab02ce..e3931afe 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java @@ -123,6 +123,7 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { final String absPath = FileUtils.makeAbsoluteUrl(staticResources, basicConfig .getConfigurationRootDirectory()); messageSource.setBasename(absPath); + messageSource.setFallbackToSystemLocale(false); } else { log.debug("No Ressourcefolder for dynamic Web content templates"); diff --git a/connector/src/main/resources/specific_eIDAS_connector.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.beans.xml index e7a46657..5cf0d5b8 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.beans.xml @@ -23,7 +23,7 @@ <bean id="MonitoringController" class="at.asitplus.eidas.specific.connector.controller.MonitoringController"> - <property name="pvpIDPCredentials"> + <property name="pvpIdpCredentials"> <ref bean="PVPEndPointCredentialProvider" /> </property> </bean> @@ -35,17 +35,17 @@ class="at.asitplus.eidas.specific.connector.builder.AuthenticationDataBuilder" /> <bean id="PVPEndPointConfiguration" - class="at.asitplus.eidas.specific.connector.config.PVPEndPointConfiguration" /> + class="at.asitplus.eidas.specific.connector.config.PvpEndPointConfiguration" /> <bean id="PVPEndPointCredentialProvider" - class="at.asitplus.eidas.specific.connector.provider.PVPEndPointCredentialProvider" /> + class="at.asitplus.eidas.specific.connector.provider.PvpEndPointCredentialProvider" /> <bean id="PVPMetadataConfigurationFactory" - class="at.asitplus.eidas.specific.connector.provider.PVPMetadataConfigurationFactory" /> + class="at.asitplus.eidas.specific.connector.provider.PvpMetadataConfigurationFactory" /> <bean id="PVP2XProtocol" - class="at.asitplus.eidas.specific.connector.controller.PVP2SProfileEndpoint"> - <property name="pvpIDPCredentials"> + class="at.asitplus.eidas.specific.connector.controller.Pvp2SProfileEndpoint"> + <property name="pvpIdpCredentials"> <ref bean="PVPEndPointCredentialProvider" /> </property> </bean> @@ -54,18 +54,18 @@ class="at.asitplus.eidas.specific.connector.verification.AuthnRequestValidator" /> <bean id="SAMLVerificationEngine" - class="at.gv.egiz.eaaf.modules.pvp2.impl.verification.SAMLVerificationEngine" /> + class="at.gv.egiz.eaaf.modules.pvp2.impl.verification.SamlVerificationEngine" /> <bean id="pvpMetadataService" class="at.gv.egiz.eaaf.modules.pvp2.idp.impl.MetadataAction"> - <property name="pvpIDPCredentials"> + <property name="pvpIdpCredentials"> <ref bean="PVPEndPointCredentialProvider" /> </property> </bean> <bean id="PVPAuthenticationRequestAction" class="at.gv.egiz.eaaf.modules.pvp2.idp.impl.AuthenticationAction"> - <property name="pvpIDPCredentials"> + <property name="pvpIdpCredentials"> <ref bean="PVPEndPointCredentialProvider" /> </property> </bean> @@ -79,22 +79,22 @@ class="at.gv.egiz.eaaf.core.impl.utils.SecurePendingRequestIdGenerationStrategy" /> <bean id="PVPMetadataProvider" - class="at.asitplus.eidas.specific.connector.provider.PVPMetadataProvider" /> + class="at.asitplus.eidas.specific.connector.provider.PvpMetadataProvider" /> <bean id="PVPSubjectNameGenerator" - class="at.asitplus.eidas.specific.connector.builder.PVPSubjectNameGenerator" /> + class="at.asitplus.eidas.specific.connector.builder.PvpSubjectNameGenerator" /> <bean id="LoALevelMapper" class="at.asitplus.eidas.specific.connector.mapper.LoALevelMapper" /> <bean id="GUIBuilderConfigurationFactory" - class="at.asitplus.eidas.specific.connector.gui.GUIBuilderConfigurationFactory" /> + class="at.asitplus.eidas.specific.connector.gui.GuiBuilderConfigurationFactory" /> <bean id="velocityGUIBuilderImpl" - class="at.asitplus.eidas.specific.connector.gui.DefaultVelocityGUIBuilderImpl" /> + class="at.asitplus.eidas.specific.connector.gui.DefaultVelocityGuiBuilderImpl" /> <bean id="mvcGUIBuilderImpl" - class="at.asitplus.eidas.specific.connector.gui.SpringMVCGUIFormBuilderImpl" /> + class="at.asitplus.eidas.specific.connector.gui.SpringMvcGuiFormBuilderImpl" /> <bean id="templateEngine" class="org.thymeleaf.spring5.SpringTemplateEngine"> diff --git a/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml index 9ee5cf88..08c7b672 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml @@ -18,10 +18,10 @@ /> --> <bean id="eIDASCacheTransactionStoreDecorator" - class="at.asitplus.eidas.specific.connector.storage.eIDASCacheTransactionStoreDecorator" /> + class="at.asitplus.eidas.specific.connector.storage.EidasCacheTransactionStoreDecorator" /> <bean id="CacheWitheIDASBackend" - class="at.asitplus.eidas.specific.connector.storage.CacheWitheIDASBackend"> + class="at.asitplus.eidas.specific.connector.storage.CacheWithEidasBackend"> <constructor-arg ref="msNodeCacheImpl" /> </bean> diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java new file mode 100644 index 00000000..44b54366 --- /dev/null +++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java @@ -0,0 +1,191 @@ +package at.asitplus.eidas.specific.connector.test.task; + +import java.io.UnsupportedEncodingException; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +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.test.context.web.WebAppConfiguration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import at.asitplus.eidas.specific.connector.MsEidasNodeConstants; +import at.asitplus.eidas.specific.connector.processes.tasks.EvaluateCountrySelectionTask; +import at.gv.egiz.eaaf.core.api.data.EaafConstants; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.AbstractLocaleAuthServletTask; +import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; +import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/applicationContext.xml", + "/specific_eIDAS_connector.beans.xml", + "/eaaf_core.beans.xml", + "/eaaf_pvp.beans.xml", + "/eaaf_pvp_idp.beans.xml", + "/spring/SpringTest-context_simple_storage.xml" }) +@WebAppConfiguration +public class EvaluateCountrySelectionTaskTest { + + @Autowired private EvaluateCountrySelectionTask task; + + private ExecutionContextImpl executionContext = new ExecutionContextImpl(); + private TestRequestImpl pendingReq; + private MockHttpServletRequest httpReq; + private MockHttpServletResponse httpResp; + + /** + * jUnit class initializer. + * + */ + @BeforeClass + public static void classInitializer() { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + "../basicConfig/default_config.properties"); + + } + + /** + * jUnit test set-up. + * + */ + @Before + public void initialize() { + httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + pendingReq = new TestRequestImpl(); + pendingReq.setAuthUrl("https://localhost/ms_connector"); + pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); + + LocaleContextHolder.resetLocaleContext(); + } + + @Test + public void withoutCountrySelection() throws TaskExecutionException, UnsupportedEncodingException { + + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelection() throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNotNull("no Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertEquals("Wrong country found", ccc, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironment() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNotNull("no Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertEquals("Wrong country found", ccc, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + + Assert.assertNotNull("No environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + Assert.assertEquals("Wrong environment-selection", environment, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironmentAndLangSelection() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + String lang = RandomStringUtils.randomAlphabetic(2); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + httpReq.setParameter(AbstractLocaleAuthServletTask.PROP_REQ_PARAM_LOCALE, lang); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", true, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironmentAndStopSelection() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + httpReq.setParameter(EaafConstants.PARAM_HTTP_STOP_PROCESS, "true"); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertTrue("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertTrue("wrong pendingReq stop flag", pendingReq.isAbortedByUser()); + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } +} diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java new file mode 100644 index 00000000..61d68774 --- /dev/null +++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java @@ -0,0 +1,146 @@ +package at.asitplus.eidas.specific.connector.test.task; + +import java.io.UnsupportedEncodingException; +import java.util.Locale; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +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.test.context.web.WebAppConfiguration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import at.asitplus.eidas.specific.connector.processes.tasks.GenerateCountrySelectionFrameTask; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; +import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/applicationContext.xml", + "/specific_eIDAS_connector.beans.xml", + "/eaaf_core.beans.xml", + "/eaaf_pvp.beans.xml", + "/eaaf_pvp_idp.beans.xml", + "/spring/SpringTest-context_simple_storage.xml" }) +@WebAppConfiguration +public class GenerateCountrySelectionFrameTaskTest { + + @Autowired private GenerateCountrySelectionFrameTask task; + + private ExecutionContextImpl executionContext = new ExecutionContextImpl(); + private TestRequestImpl pendingReq; + private MockHttpServletRequest httpReq; + private MockHttpServletResponse httpResp; + + /** + * jUnit class initializer. + * + */ + @BeforeClass + public static void classInitializer() { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + "../basicConfig/default_config.properties"); + + } + + /** + * jUnit test set-up. + * + */ + @Before + public void initialize() { + httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + pendingReq = new TestRequestImpl(); + pendingReq.setAuthUrl("https://localhost/ms_connector"); + pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); + + LocaleContextHolder.resetLocaleContext(); + } + + @Test + public void validHtmlResponseWithOutLocale() throws TaskExecutionException, UnsupportedEncodingException { + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + @Test + public void validHtmlResponseWithDE() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.GERMAN); + httpReq.addHeader("Accept-Language", "de"); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information zur Anmeldung über Europäische eIDs")); + + } + + @Test + public void validHtmlResponseWithEN() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.ENGLISH); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + @Test + public void validHtmlResponseWithFR() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.FRANCE); + httpReq.addHeader("Accept-Language", "fr"); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + private String doBasicValidation() throws UnsupportedEncodingException { + Assert.assertEquals("Wrong http StatusCode", 200, httpResp.getStatus()); + Assert.assertEquals("Wrong http ContentType", "text/html;charset=UTF-8", httpResp.getContentType()); + + String html = httpResp.getContentAsString(); + Assert.assertNotNull("html result is null", html); + Assert.assertFalse("html result is empty", html.isEmpty()); + Assert.assertTrue("No language selector with pendingRequestId", + html.contains("/myHomeCountry?pendingid=" + pendingReq.getPendingRequestId())); + Assert.assertTrue("No country-selection form", + html.contains("<form class=\"block\" method=\"post\" action=\"/myHomeCountry\">")); + + return html; + + } +} diff --git a/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml b/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml new file mode 100644 index 00000000..5ee3e0b8 --- /dev/null +++ b/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml @@ -0,0 +1,15 @@ +<?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"> + + <bean id="SimpleInMemoryTransactionStorage" + class="at.asitplus.eidas.specific.connector.storage.SimpleInMemoryTransactionStorage" /> + +</beans>
\ No newline at end of file |