From 32988b1df31a0ed1a31275371b18201a10db88d7 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 10 Mar 2022 13:23:58 +0100 Subject: chore(core): add Spring based message source to MS-Connector --- .../connector/config/MsConnectorMessageSource.java | 21 +++++++ .../resources/specific_eIDAS_connector.beans.xml | 3 + .../test/config/MsConnectorMessageSourceTest.java | 71 ++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 connector/src/main/java/at/asitplus/eidas/specific/connector/config/MsConnectorMessageSource.java create mode 100644 connector/src/test/java/at/asitplus/eidas/specific/connector/test/config/MsConnectorMessageSourceTest.java (limited to 'connector') diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/config/MsConnectorMessageSource.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/MsConnectorMessageSource.java new file mode 100644 index 00000000..59df6375 --- /dev/null +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/MsConnectorMessageSource.java @@ -0,0 +1,21 @@ +package at.asitplus.eidas.specific.connector.config; + +import java.util.Arrays; +import java.util.List; + +import at.gv.egiz.eaaf.core.api.logging.IMessageSourceLocation; + +/** + * Inject eIDAS Connector specific messages into Spring based message-source. + * + * @author tlenz + * + */ +public class MsConnectorMessageSource implements IMessageSourceLocation { + + @Override + public List getMessageSourceLocation() { + return Arrays.asList("classpath:/properties/messages"); + } + +} diff --git a/connector/src/main/resources/specific_eIDAS_connector.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.beans.xml index e3db72f8..9861a7c6 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.beans.xml @@ -14,6 +14,9 @@ + + diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/config/MsConnectorMessageSourceTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/config/MsConnectorMessageSourceTest.java new file mode 100644 index 00000000..4c9d825d --- /dev/null +++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/config/MsConnectorMessageSourceTest.java @@ -0,0 +1,71 @@ +package at.asitplus.eidas.specific.connector.test.config; + +import java.security.cert.CertificateException; +import java.util.List; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opensaml.core.config.InitializationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +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.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import at.gv.egiz.eaaf.core.api.logging.IMessageSourceLocation; +import net.shibboleth.utilities.java.support.component.ComponentInitializationException; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/applicationContext.xml", + "/spring/SpringTest_connector.beans.xml", + "/eaaf_core.beans.xml", + "/eaaf_pvp.beans.xml", + "/eaaf_pvp_idp.beans.xml", + "/spring/SpringTest-context_simple_storage.xml" }) +@WebAppConfiguration +@DirtiesContext(classMode = ClassMode.BEFORE_CLASS) +@ActiveProfiles(profiles = {"deprecatedConfig"}) +public class MsConnectorMessageSourceTest { + + /** + * jUnit class initializer. + * @throws ComponentInitializationException In case of an error + * @throws InitializationException In case of an error + * @throws CertificateException + * + */ + @BeforeClass + public static void classInitializer() throws InitializationException, + ComponentInitializationException, CertificateException { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_1.properties"); + + } + + @Autowired + private ResourceLoader loader; + @Autowired(required = false) + private List messageSources; + + @Test + public void checkMessageSources() { + Assert.assertNotNull("No messageSource", messageSources); + + for (final IMessageSourceLocation messageSource : messageSources) { + Assert.assertNotNull("No sourcePath", messageSource.getMessageSourceLocation()); + + for (final String el : messageSource.getMessageSourceLocation()) { + final Resource messages = loader.getResource(el + ".properties"); + Assert.assertTrue("Source not exist", messages.exists()); + + } + } + } +} -- cgit v1.2.3