From 8d10b11ffa05104fabf242474cc35bc456744ace Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 5 Aug 2019 12:22:31 +0200 Subject: refactor to eIDAS-Node v2.3.0 and use Apache Ignite as new cache implementation refactor to multi-language support --- .../config/StaticResourceConfiguration.java | 110 ++++++++++++++++++--- .../tasks/EvaluateCountrySelectionTask.java | 47 ++++----- .../tasks/GenerateCountrySelectionFrameTask.java | 4 +- .../connector/storage/CacheWitheIDASBackend.java | 43 ++++---- .../eIDASCacheTransactionStoreDecorator.java | 15 ++- 5 files changed, 142 insertions(+), 77 deletions(-) (limited to 'connector/src/main/java/at/asitplus/eidas/specific') 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 9367c69f..34b9d2fa 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 @@ -1,25 +1,25 @@ -/* - * Copyright 2014 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. +/******************************************************************************* + * Copyright 2019 A-SIT Plus GmbH + * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, + * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ + * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "License"); + * You may not use this work except in compliance with the License. + * You may obtain a copy of the License at: + * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, + * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. + * See the License for the specific language governing permissions and + * limitations under the License. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. - */ + *******************************************************************************/ package at.asitplus.eidas.specific.connector.config; import java.net.MalformedURLException; @@ -28,10 +28,14 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +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.WebMvcConfigurerAdapter; +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; @@ -49,6 +53,8 @@ public class StaticResourceConfiguration extends WebMvcConfigurerAdapter { "/" }; + private static final String DEFAULT_MESSAGE_SOURCE = "classpath:properties/status_messages"; + @Autowired private IConfiguration basicConfig; @@ -73,7 +79,83 @@ public class StaticResourceConfiguration extends WebMvcConfigurerAdapter { } registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS); + + } + + @Bean + public ReloadableResourceBundleMessageSource internalMessageSource(){ + final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); + + //add default message source + messageSource.setBasename(DEFAULT_MESSAGE_SOURCE); + messageSource.setDefaultEncoding("UTF-8"); + return messageSource; + + } + + @Bean + public ReloadableResourceBundleMessageSource messageSource(){ + final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); + messageSource.setDefaultEncoding("UTF-8"); + messageSource.setParentMessageSource(internalMessageSource()); + + final String staticResources = basicConfig.getBasicConfiguration(MSeIDASNodeConstants.PROP_CONFIG_WEBCONTENT_PROPERTIES_PATH); + try { + if (StringUtils.isNotEmpty(staticResources)) { + final String absPath = FileUtils.makeAbsoluteURL(staticResources , basicConfig.getConfigurationRootDirectory()); + messageSource.setBasename(absPath); + + } else + log.debug("No Ressourcefolder for dynamic Web content templates"); + + } catch (final MalformedURLException e) { + log.warn("Can NOT initialize ressourcefolder for dynamic Web content templates", e); + + } + + return messageSource; + + } + + @Bean + public CookieLocaleResolver localeResolver(){ + final CookieLocaleResolver localeResolver = new CookieLocaleResolver(); + localeResolver.setCookieName("currentLanguage"); + localeResolver.setCookieMaxAge(3600); + return localeResolver; + } - + @Bean(name="templateResolver") + public FileTemplateResolver templateResolver() { + final String staticResources = basicConfig.getBasicConfiguration(MSeIDASNodeConstants.PROP_CONFIG_WEBCONTENT_TEMPLATES_PATH); + try { + if (StringUtils.isNotEmpty(staticResources)) { + 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(); + viewResolver.setPrefix(absPath); + viewResolver.setSuffix(".html"); + viewResolver.setTemplateMode("HTML5"); + viewResolver.setCacheable(false); + + log.info("Add Ressourcefolder: " + absPath + " for dynamic Web content templates"); + return viewResolver ; + + } else + log.debug("No Ressourcefolder for dynamic Web content templates"); + + } catch (final MalformedURLException e) { + log.warn("Can NOT initialize ressourcefolder for dynamic Web content templates", e); + + } + + //TODO: implement some backup solution + return null; + } } diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/EvaluateCountrySelectionTask.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/EvaluateCountrySelectionTask.java index 8e32f00e..91cf6515 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/EvaluateCountrySelectionTask.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/EvaluateCountrySelectionTask.java @@ -33,51 +33,42 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import at.asitplus.eidas.specific.connector.MSConnectorEventCodes; import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; import at.gv.egiz.eaaf.core.api.data.EAAFConstants; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; -import at.gv.egiz.eaaf.core.impl.idp.auth.modules.AbstractAuthServletTask; +import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.AbstractLocaleAuthServletTask; /** * @author tlenz * */ @Component("EvaluateCountrySelectionTask") -public class EvaluateCountrySelectionTask extends AbstractAuthServletTask { +public class EvaluateCountrySelectionTask extends AbstractLocaleAuthServletTask { private static final Logger log = LoggerFactory.getLogger(EvaluateCountrySelectionTask.class); @Override - public void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) + public void executeWithLocale(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException { try { - - String stopAuthFlag = request.getParameter(MSeIDASNodeConstants.REQ_PARAM_STOP_PROCESS); - if (StringUtils.isNotEmpty(stopAuthFlag) && Boolean.parseBoolean(stopAuthFlag)) { - log.info("Authentication process WAS stopped by entity. Stopping auth. process ... "); - revisionsLogger.logEvent(pendingReq, MSConnectorEventCodes.PROCESS_STOPPED_BY_USER); - pendingReq.setAbortedByUser(true); - pendingReq.setAuthenticated(false); - - } else { - // set parameter execution context - Enumeration reqParamNames = request.getParameterNames(); - while(reqParamNames.hasMoreElements()) { - String paramName = reqParamNames.nextElement(); - if (StringUtils.isNotEmpty(paramName) && - !EAAFConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName)) { - for (String el : MSeIDASNodeConstants.COUNTRY_SELECTION_PARAM_WHITELIST) { - if (el.equalsIgnoreCase(paramName)) - executionContext.put(paramName, - StringEscapeUtils.escapeHtml(request.getParameter(paramName))); - } + + // set parameter execution context + Enumeration reqParamNames = request.getParameterNames(); + while(reqParamNames.hasMoreElements()) { + String paramName = reqParamNames.nextElement(); + if (StringUtils.isNotEmpty(paramName) && + !EAAFConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName)) { + for (String el : MSeIDASNodeConstants.COUNTRY_SELECTION_PARAM_WHITELIST) { + if (el.equalsIgnoreCase(paramName)) + executionContext.put(paramName, + StringEscapeUtils.escapeHtml(request.getParameter(paramName))); } - } - log.info("Country selection finished. Starting auth. process for country ... "); - - } + } + } + + log.info("Country selection finished. Starting auth. process for country ... "); + } catch (Exception e) { log.warn("EvaluateBKUSelectionTask has an internal error", e); diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/GenerateCountrySelectionFrameTask.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/GenerateCountrySelectionFrameTask.java index a707c827..49dd6b02 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/GenerateCountrySelectionFrameTask.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/processes/tasks/GenerateCountrySelectionFrameTask.java @@ -34,7 +34,7 @@ import at.asitplus.eidas.specific.connector.MSConnectorEventCodes; import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; import at.asitplus.eidas.specific.connector.gui.StaticGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; -import at.gv.egiz.eaaf.core.api.gui.IGUIFormBuilder; +import at.gv.egiz.eaaf.core.api.gui.ISpringMVCGUIFormBuilder; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EAAFException; @@ -50,7 +50,7 @@ import at.gv.egiz.eaaf.core.impl.idp.auth.modules.AbstractAuthServletTask; public class GenerateCountrySelectionFrameTask extends AbstractAuthServletTask { private static final Logger log = LoggerFactory.getLogger(GenerateCountrySelectionFrameTask.class); - @Autowired IGUIFormBuilder guiBuilder; + @Autowired ISpringMVCGUIFormBuilder guiBuilder; @Autowired IConfiguration basicConfig; @Override diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/CacheWitheIDASBackend.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/CacheWitheIDASBackend.java index 560ae592..4bcced82 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/CacheWitheIDASBackend.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/CacheWitheIDASBackend.java @@ -22,34 +22,29 @@ *******************************************************************************/ package at.asitplus.eidas.specific.connector.storage; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; +import eu.eidas.auth.commons.cache.ConcurrentCacheService; +import eu.eidas.auth.commons.tx.AbstractCache; -import eu.eidas.auth.commons.cache.ConcurrentMapService; -import eu.eidas.auth.commons.tx.AbstractCorrelationMap; +public class CacheWitheIDASBackend extends AbstractCache { -public class CacheWitheIDASBackend extends AbstractCorrelationMap { - - protected CacheWitheIDASBackend(ConcurrentMapService concurrentMapService) { + protected CacheWitheIDASBackend(ConcurrentCacheService concurrentMapService) { super(concurrentMapService); } - public List clean(Date now, long dataTimeOut) { - List result = new ArrayList(); - Iterator iterator = map.keySet().iterator(); - while (iterator.hasNext()) { - String key = iterator.next(); - if (map.containsKey(key)) { - TransactionStoreElement element = map.get(key); - if (now.getTime() - element.getCreated().getTime() > dataTimeOut) - result.add(key); - } - } - - return result; - - } +// public List clean(Date now, long dataTimeOut) { +// List result = new ArrayList(); +// Iterator iterator = map.keySet().iterator(); +// while (iterator.hasNext()) { +// String key = iterator.next(); +// if (map.containsKey(key)) { +// TransactionStoreElement element = map.get(key); +// if (now.getTime() - element.getCreated().getTime() > dataTimeOut) +// result.add(key); +// } +// } +// +// return result; +// +// } } diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/eIDASCacheTransactionStoreDecorator.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/eIDASCacheTransactionStoreDecorator.java index 04a8f6fd..270d0e31 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/eIDASCacheTransactionStoreDecorator.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/storage/eIDASCacheTransactionStoreDecorator.java @@ -22,6 +22,7 @@ *******************************************************************************/ package at.asitplus.eidas.specific.connector.storage; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -43,6 +44,7 @@ public class eIDASCacheTransactionStoreDecorator implements ITransactionStorage{ if (containsKey(oldKey)) { TransactionStoreElement el = storage.get(oldKey); el.setKey(newKey); + el.setData(value); storage.put(newKey, el); storage.remove(oldKey); @@ -53,19 +55,14 @@ public class eIDASCacheTransactionStoreDecorator implements ITransactionStorage{ @Override public List clean(Date now, long dataTimeOut) { - return storage.clean(now, dataTimeOut); + log.info("Clean is NOT implemented, because its not needed"); + return Arrays.asList(); } @Override - public boolean containsKey(String key) { - if (key != null) { - if (storage.get(key) != null) - return true; - - } - - return false; + public boolean containsKey(String key) { + return storage.containsKey(key); } -- cgit v1.2.3