aboutsummaryrefslogtreecommitdiff
path: root/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-12-22 15:36:42 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-12-23 15:48:42 +0100
commit6b098e7070dedb5692325f6d330a20de696b9edc (patch)
tree3dfeb2568944dd586cc06a0f84b033763fca95de /connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java
parent9fd7ba09ba2a5a827ef8530967aa0bfefc412f42 (diff)
downloadNational_eIDAS_Gateway-6b098e7070dedb5692325f6d330a20de696b9edc.tar.gz
National_eIDAS_Gateway-6b098e7070dedb5692325f6d330a20de696b9edc.tar.bz2
National_eIDAS_Gateway-6b098e7070dedb5692325f6d330a20de696b9edc.zip
switch from Spring to Spring-Boot
Diffstat (limited to 'connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java')
-rw-r--r--connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java87
1 files changed, 48 insertions, 39 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 2a10031b..a1e953f1 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
@@ -24,6 +24,7 @@
package at.asitplus.eidas.specific.connector.config;
import java.net.MalformedURLException;
+import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -35,11 +36,11 @@ import org.springframework.context.support.ReloadableResourceBundleMessageSource
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.thymeleaf.templateresolver.FileTemplateResolver;
import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.logging.IMessageSourceLocation;
import at.gv.egiz.eaaf.core.impl.utils.FileUtils;
/**
@@ -90,43 +91,63 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
}
/**
- * Internal i18n message source.
- *
+ * Get a message source with only internal message properties.
+ *
+ * @param ressourceLocations List of source-locations
* @return
*/
@Bean
- public ReloadableResourceBundleMessageSource internalMessageSource() {
- final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
+ public ReloadableResourceBundleMessageSource internalMessageSource(
+ @Autowired(required = false) final List<IMessageSourceLocation> ressourceLocations) {
+ final ReloadableResourceBundleMessageSource messageSource =
+ new ReloadableResourceBundleMessageSource();
// add default message source
messageSource.setBasename(DEFAULT_MESSAGE_SOURCE);
+
+ if (ressourceLocations != null) {
+ // load more message sources
+ for (final IMessageSourceLocation el : ressourceLocations) {
+ if (el.getMessageSourceLocation() != null) {
+ for (final String source : el.getMessageSourceLocation()) {
+ messageSource.addBasenames(source);
+ log.debug("Add additional messageSources: {}", el.getMessageSourceLocation().toArray());
+
+ }
+ }
+ }
+ }
+
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
/**
- * External i18n message source.
- *
+ * Get full message source with internal and external message-properties files.
+ *
+ * @param ressourceLocations List of source-locations
* @return
*/
@Bean
- public ReloadableResourceBundleMessageSource messageSource() {
- final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
+ public ReloadableResourceBundleMessageSource messageSource(
+ @Autowired(required = false) final List<IMessageSourceLocation> ressourceLocations) {
+ final ReloadableResourceBundleMessageSource messageSource =
+ new ReloadableResourceBundleMessageSource();
messageSource.setDefaultEncoding("UTF-8");
- messageSource.setParentMessageSource(internalMessageSource());
+ messageSource.setParentMessageSource(internalMessageSource(ressourceLocations));
- final String staticResources = basicConfig.getBasicConfiguration(
- MsEidasNodeConstants.PROP_CONFIG_WEBCONTENT_PROPERTIES_PATH);
+ final String staticResources = basicConfig
+ .getBasicConfiguration(MsEidasNodeConstants.PROP_CONFIG_WEBCONTENT_PROPERTIES_PATH);
try {
if (StringUtils.isNotEmpty(staticResources)) {
- final String absPath = FileUtils.makeAbsoluteUrl(staticResources, basicConfig
- .getConfigurationRootDirectory());
+ final String absPath =
+ FileUtils.makeAbsoluteUrl(staticResources, basicConfig.getConfigurationRootDirectory());
messageSource.setBasename(absPath);
- messageSource.setFallbackToSystemLocale(false);
} else {
log.debug("No Ressourcefolder for dynamic Web content templates");
+
}
} catch (final MalformedURLException e) {
@@ -137,40 +158,28 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
return messageSource;
}
-
+
/**
- * Cookie based i18n language selector.
- *
- * @return
- */
- @Bean
- public CookieLocaleResolver localeResolver() {
- final CookieLocaleResolver localeResolver = new CookieLocaleResolver();
- localeResolver.setCookieName("currentLanguage");
- localeResolver.setCookieMaxAge(3600);
- return localeResolver;
- }
-
-
- /**
- * Thymeleaf based template resolver.
- *
+ * Get a Tyhmeleaf Template-Resolver with external configuration path.
+ *
* @return
*/
@Bean(name = "templateResolver")
public FileTemplateResolver templateResolver() {
- final String staticResources = basicConfig.getBasicConfiguration(
- MsEidasNodeConstants.PROP_CONFIG_WEBCONTENT_TEMPLATES_PATH);
+ final String staticResources = basicConfig
+ .getBasicConfiguration(MsEidasNodeConstants.PROP_CONFIG_WEBCONTENT_TEMPLATES_PATH);
try {
if (StringUtils.isNotEmpty(staticResources)) {
- String absPath = FileUtils.makeAbsoluteUrl(staticResources, basicConfig
- .getConfigurationRootDirectory());
+ String absPath =
+ FileUtils.makeAbsoluteUrl(staticResources, basicConfig.getConfigurationRootDirectory());
if (!absPath.endsWith("/")) {
absPath += "/";
+
}
if (absPath.startsWith("file:")) {
absPath = absPath.substring("file:".length());
+
}
final FileTemplateResolver viewResolver = new FileTemplateResolver();
@@ -179,11 +188,12 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
viewResolver.setTemplateMode("HTML");
viewResolver.setCacheable(false);
- log.info("Add Ressourcefolder: " + absPath + " for dynamic Web content templates");
+ log.info("Add Ressourcefolder: {} for dynamic Web content templates", absPath);
return viewResolver;
} else {
log.debug("No Ressourcefolder for dynamic Web content templates");
+
}
} catch (final MalformedURLException e) {
@@ -191,8 +201,7 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
}
- // TODO: implement some backup solution
- return null;
+ throw new RuntimeException("Can NOT initialize HTML template resolver");
}
}