From 0224cdf7be78cf0778f0b832a42c18c480c4b784 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 9 Dec 2019 09:22:54 +0100 Subject: switch to EAAF-Components 1.1.0-SNAPSHOT --- .../specific/connector/MSeIDASNodeConstants.java | 4 +- .../config/BasicConfigurationProvider.java | 20 ++-- .../config/ServiceProviderConfiguration.java | 16 +-- .../gui/DefaultVelocityGUIBuilderImpl.java | 14 +-- .../gui/GUIBuilderConfigurationFactory.java | 55 ----------- .../gui/GuiBuilderConfigurationFactory.java | 55 +++++++++++ .../connector/gui/SpringMVCGUIFormBuilderImpl.java | 110 --------------------- .../connector/gui/SpringMvcGuiFormBuilderImpl.java | 110 +++++++++++++++++++++ .../gui/StaticGuiBuilderConfiguration.java | 10 +- 9 files changed, 197 insertions(+), 197 deletions(-) delete mode 100644 connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GUIBuilderConfigurationFactory.java create mode 100644 connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GuiBuilderConfigurationFactory.java delete mode 100644 connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMVCGUIFormBuilderImpl.java create mode 100644 connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMvcGuiFormBuilderImpl.java (limited to 'connector_lib/src/main') diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/MSeIDASNodeConstants.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/MSeIDASNodeConstants.java index 0835daf8..9e6c1a3b 100644 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/MSeIDASNodeConstants.java +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/MSeIDASNodeConstants.java @@ -27,7 +27,7 @@ package at.asitplus.eidas.specific.connector; import java.util.Arrays; import java.util.List; -import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants; +import at.gv.egiz.eaaf.core.api.data.EaafConfigConstants; public class MSeIDASNodeConstants { // ************ configuration properties ************ @@ -59,7 +59,7 @@ public class MSeIDASNodeConstants { public static final String PROP_EIDAS_REQUEST_LOA_MINIMUM_LEVEL = "auth.eIDAS.node_v2.loa.requested.minimum"; public static final String PROP_CONFIG_SP_LIST_PREFIX = "sp."; - public static final String PROP_CONFIG_SP_UNIQUEIDENTIFIER = EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER; + public static final String PROP_CONFIG_SP_UNIQUEIDENTIFIER = EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER; public static final String PROP_CONFIG_SP_FRIENDLYNAME = "friendlyName"; public static final String PROP_CONFIG_SP_PVP2_METADATA_URL = "pvp2.metadata.url"; public static final String PROP_CONFIG_SP_PVP2_METADATA_TRUSTSTORE = "pvp2.metadata.truststore"; diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java index 4793e085..4a9bc8e4 100644 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java @@ -34,9 +34,9 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; -import at.gv.egiz.eaaf.core.api.idp.ISPConfiguration; -import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException; -import at.gv.egiz.eaaf.core.exceptions.EAAFException; +import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration; +import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException; +import at.gv.egiz.eaaf.core.exceptions.EaafException; import at.gv.egiz.eaaf.core.impl.idp.conf.AbstractConfigurationImpl; import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils; @@ -44,15 +44,15 @@ import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils; public class BasicConfigurationProvider extends AbstractConfigurationImpl{ private static final Logger log = LoggerFactory.getLogger(BasicConfigurationProvider.class); - private Map spConfigCache = new HashMap(); + private Map spConfigCache = new HashMap(); - public BasicConfigurationProvider(String configPath) throws EAAFConfigurationException { + public BasicConfigurationProvider(String configPath) throws EaafConfigurationException { super(configPath); } @Override - public ISPConfiguration getServiceProviderConfiguration(String entityId) throws EAAFConfigurationException { + public ISpConfiguration getServiceProviderConfiguration(String entityId) throws EaafConfigurationException { if (!spConfigCache.containsKey(entityId)) { log.debug("SP: " + entityId + " is NOT cached. Starting load operation ... "); Map allSPs = getBasicConfigurationWithPrefix(MSeIDASNodeConstants.PROP_CONFIG_SP_LIST_PREFIX); @@ -84,8 +84,8 @@ public class BasicConfigurationProvider extends AbstractConfigurationImpl{ } @Override - public T getServiceProviderConfiguration(String entityId, Class decorator) throws EAAFConfigurationException { - ISPConfiguration spConfig = getServiceProviderConfiguration(entityId); + public T getServiceProviderConfiguration(String entityId, Class decorator) throws EaafConfigurationException { + ISpConfiguration spConfig = getServiceProviderConfiguration(entityId); if (spConfig != null && decorator != null) { if (decorator.isInstance(spConfig)) return (T)spConfig; @@ -99,12 +99,12 @@ public class BasicConfigurationProvider extends AbstractConfigurationImpl{ } @Override - public String validateIDPURL(URL url) throws EAAFException { + public String validateIdpUrl(URL url) throws EaafException { log.trace("Validate requested URL: " + url); String urlPrefixFromConfig = getBasicConfiguration(MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX); if (StringUtils.isEmpty(urlPrefixFromConfig)) { log.warn("Application config containts NO URL prefix"); - throw new EAAFConfigurationException("config.27", + throw new EaafConfigurationException("config.27", new Object[] {"Application config containts NO " + getApplicationSpecificKeyPrefix() + MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX }); diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/ServiceProviderConfiguration.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/ServiceProviderConfiguration.java index 7667c5f3..f5b52fa4 100644 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/ServiceProviderConfiguration.java +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/ServiceProviderConfiguration.java @@ -34,18 +34,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; -import at.gv.egiz.eaaf.core.api.data.EAAFConstants; +import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; -import at.gv.egiz.eaaf.core.exceptions.EAAFException; -import at.gv.egiz.eaaf.core.impl.idp.conf.SPConfigurationImpl; +import at.gv.egiz.eaaf.core.exceptions.EaafException; +import at.gv.egiz.eaaf.core.impl.idp.conf.SpConfigurationImpl; -public class ServiceProviderConfiguration extends SPConfigurationImpl { +public class ServiceProviderConfiguration extends SpConfigurationImpl { private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(ServiceProviderConfiguration.class); - private List minimumLoA = Arrays.asList(EAAFConstants.EIDAS_LOA_HIGH); + private List minimumLoA = Arrays.asList(EaafConstants.EIDAS_LOA_HIGH); private String bPKTargetIdentifier; - private String loaMachtingMode = EAAFConstants.EIDAS_LOA_MATCHING_MINIMUM; + private String loaMachtingMode = EaafConstants.EIDAS_LOA_MATCHING_MINIMUM; public ServiceProviderConfiguration(Map spConfig, IConfiguration authConfig) { super(spConfig, authConfig); @@ -139,7 +139,7 @@ public class ServiceProviderConfiguration extends SPConfigurationImpl { * @param bPKTargetIdentifier * @throws EAAFException If the bPKTargetIdentifier is NOT ALLOWED for this service provider */ - public void setbPKTargetIdentifier(String bPKTargetIdentifier) throws EAAFException { + public void setbPKTargetIdentifier(String bPKTargetIdentifier) throws EaafException { String allowedTargetIdentifierRegExPattern = getConfigurationValue( MSeIDASNodeConstants.PROP_CONFIG_SP_POLICY_ALLOWED_TARGETS, MSeIDASNodeConstants.POLICY_DEFAULT_ALLOWED_TARGETS); @@ -153,7 +153,7 @@ public class ServiceProviderConfiguration extends SPConfigurationImpl { } else { log.warn("Requested bPK-target: " + bPKTargetIdentifier + " does NOT match regex pattern."); - throw new EAAFException("auth.37", new Object[] {bPKTargetIdentifier, getUniqueIdentifier()}); + throw new EaafException("auth.37", new Object[] {bPKTargetIdentifier, getUniqueIdentifier()}); } diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/DefaultVelocityGUIBuilderImpl.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/DefaultVelocityGUIBuilderImpl.java index e618e68d..802a22ff 100644 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/DefaultVelocityGUIBuilderImpl.java +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/DefaultVelocityGUIBuilderImpl.java @@ -28,23 +28,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration; -import at.gv.egiz.eaaf.core.exceptions.GUIBuildException; -import at.gv.egiz.eaaf.core.impl.gui.AbstractVelocityGUIFormBuilderImpl; +import at.gv.egiz.eaaf.core.api.gui.IVelocityGuiBuilderConfiguration; +import at.gv.egiz.eaaf.core.exceptions.GuiBuildException; +import at.gv.egiz.eaaf.core.impl.gui.AbstractVelocityGuiFormBuilderImpl; @Service("DefaultVelocityGUIBuilderImpl") -public class DefaultVelocityGUIBuilderImpl extends AbstractVelocityGUIFormBuilderImpl { +public class DefaultVelocityGUIBuilderImpl extends AbstractVelocityGuiFormBuilderImpl { private static final Logger log = LoggerFactory.getLogger(DefaultVelocityGUIBuilderImpl.class); private static final String CLASSPATH_HTMLTEMPLATES_DIR = "templates/"; - public DefaultVelocityGUIBuilderImpl() throws GUIBuildException { + public DefaultVelocityGUIBuilderImpl() throws GuiBuildException { super(); } @Override - protected InputStream getInternalTemplate(IVelocityGUIBuilderConfiguration config) throws GUIBuildException { + protected InputStream getInternalTemplate(IVelocityGuiBuilderConfiguration config) throws GuiBuildException { String viewName = config.getViewName(); log.debug("GUI template:" + viewName + " is not found in configuration directory. " + " Load template from project library ... "); @@ -55,7 +55,7 @@ public class DefaultVelocityGUIBuilderImpl extends AbstractVelocityGUIFormBuilde } catch (Exception e1) { log.error("GUI template:" + pathLocation + " is NOT loadable from classpath!", e1); - throw new GUIBuildException("GUI template:" + pathLocation + " is NOT loadable from classpath!", e1); + throw new GuiBuildException("GUI template:" + pathLocation + " is NOT loadable from classpath!", e1); } } diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GUIBuilderConfigurationFactory.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GUIBuilderConfigurationFactory.java deleted file mode 100644 index e0ce6b3e..00000000 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GUIBuilderConfigurationFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright 2018 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.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 License is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * 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.gui; - -import java.net.MalformedURLException; -import java.net.URI; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; -import at.gv.egiz.eaaf.core.api.IRequest; -import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; -import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfigurationFactory; -import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration; -import at.gv.egiz.eaaf.core.api.idp.IConfiguration; - -@Service("GUIBuilderConfigurationFactory") -public class GUIBuilderConfigurationFactory implements IGUIBuilderConfigurationFactory { - @Autowired(required=true) private IConfiguration basicConfig; - - @Override - public IGUIBuilderConfiguration getDefaultErrorGUI(String authURL) { - return new StaticGuiBuilderConfiguration(basicConfig, authURL, MSeIDASNodeConstants.TEMPLATE_HTML_ERROR, null); - } - - @Override - public IVelocityGUIBuilderConfiguration getSPSpecificSAML2PostConfiguration(IRequest pendingReq, String viewName, URI configRootContextDir) - throws MalformedURLException { - return new StaticGuiBuilderConfiguration(basicConfig, pendingReq,MSeIDASNodeConstants.TEMPLATE_HTML_PVP_POSTBINDING , null); - } - -} diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GuiBuilderConfigurationFactory.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GuiBuilderConfigurationFactory.java new file mode 100644 index 00000000..14198892 --- /dev/null +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/GuiBuilderConfigurationFactory.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2018 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.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 License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * 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.gui; + +import java.net.MalformedURLException; +import java.net.URI; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; +import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.api.gui.IGuiBuilderConfiguration; +import at.gv.egiz.eaaf.core.api.gui.IGuiBuilderConfigurationFactory; +import at.gv.egiz.eaaf.core.api.gui.IVelocityGuiBuilderConfiguration; +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; + +@Service("GUIBuilderConfigurationFactory") +public class GuiBuilderConfigurationFactory implements IGuiBuilderConfigurationFactory { + @Autowired(required=true) private IConfiguration basicConfig; + + @Override + public IGuiBuilderConfiguration getDefaultErrorGui(String authURL) { + return new StaticGuiBuilderConfiguration(basicConfig, authURL, MSeIDASNodeConstants.TEMPLATE_HTML_ERROR, null); + } + + @Override + public IVelocityGuiBuilderConfiguration getSpSpecificSaml2PostConfiguration(IRequest pendingReq, String viewName, URI configRootContextDir) + throws MalformedURLException { + return new StaticGuiBuilderConfiguration(basicConfig, pendingReq,MSeIDASNodeConstants.TEMPLATE_HTML_PVP_POSTBINDING , null); + } + +} diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMVCGUIFormBuilderImpl.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMVCGUIFormBuilderImpl.java deleted file mode 100644 index 84218611..00000000 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMVCGUIFormBuilderImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -package at.asitplus.eidas.specific.connector.gui; - -import java.util.Locale; -import java.util.Map; - -import javax.annotation.Nullable; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.View; -import org.springframework.web.servlet.ViewResolver; - -import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; -import at.gv.egiz.eaaf.core.api.gui.ISpringMVCGUIFormBuilder; -import at.gv.egiz.eaaf.core.exceptions.GUIBuildException; - -public class SpringMVCGUIFormBuilderImpl implements ISpringMVCGUIFormBuilder { - private static final Logger log = LoggerFactory.getLogger(SpringMVCGUIFormBuilderImpl.class); - - private @Autowired(required=false) ViewResolver[] viewResolvers; - private @Autowired(required=false) LocaleResolver localeResolver; - - @Override - public void build(HttpServletRequest httpReq, HttpServletResponse httpResp, IGUIBuilderConfiguration config, - String loggerName) throws GUIBuildException { - build(httpReq, httpResp, config, null, loggerName); - - } - - @Override - public void build(HttpServletRequest httpReq, HttpServletResponse httpResp, IGUIBuilderConfiguration config, - String contentType, String loggerName) throws GUIBuildException { - try { - final ModelAndView mav = new ModelAndView(config.getViewName()); - if (config.getViewParameters() != null) - mav.addAllObjects(config.getViewParameters()); - - render(mav, httpReq, httpResp); - - } catch (final Exception e) { - log.info("Can NOT generate GUI for illustration", e); - throw new GUIBuildException(e.getMessage(), e); - - } - - } - - protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception { - // Determine locale for request and apply it to the response. - final Locale locale = - (this.localeResolver != null ? this.localeResolver.resolveLocale(request) : request.getLocale()); - response.setLocale(locale); - - View view; - final String viewName = mv.getViewName(); - if (viewName != null) { - // We need to resolve the view name. - view = resolveViewName(viewName, mv.getModelMap(), locale, request); - if (view == null) - throw new ServletException("Could not resolve view with name '" + mv.getViewName() + "' "); - - } else { - // No need to lookup: the ModelAndView object contains the actual View object. - view = mv.getView(); - if (view == null) - throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " + "View object "); - - } - - // Delegate to the View object for rendering. - if (log.isTraceEnabled()) - log.trace("Rendering view [" + view + "] "); - - try { - if (mv.getStatus() != null) - response.setStatus(mv.getStatus().value()); - - view.render(mv.getModelMap(), request, response); - - } catch (final Exception ex) { - if (log.isDebugEnabled()) - log.debug("Error rendering view [" + view + "]", ex); - - throw ex; - - } - - } - - protected View resolveViewName(String viewName, @Nullable Map model, - Locale locale, HttpServletRequest request) throws Exception { - if (viewResolvers != null) { - for (final ViewResolver viewResolver : this.viewResolvers) { - final View view = viewResolver.resolveViewName(viewName, locale); - if (view != null) - return view; - - } - } - - return null; - } - -} diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMvcGuiFormBuilderImpl.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMvcGuiFormBuilderImpl.java new file mode 100644 index 00000000..63028db2 --- /dev/null +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/SpringMvcGuiFormBuilderImpl.java @@ -0,0 +1,110 @@ +package at.asitplus.eidas.specific.connector.gui; + +import java.util.Locale; +import java.util.Map; + +import javax.annotation.Nullable; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.View; +import org.springframework.web.servlet.ViewResolver; + +import at.gv.egiz.eaaf.core.api.gui.IGuiBuilderConfiguration; +import at.gv.egiz.eaaf.core.api.gui.ISpringMvcGuiFormBuilder; +import at.gv.egiz.eaaf.core.exceptions.GuiBuildException; + +public class SpringMvcGuiFormBuilderImpl implements ISpringMvcGuiFormBuilder { + private static final Logger log = LoggerFactory.getLogger(SpringMvcGuiFormBuilderImpl.class); + + private @Autowired(required=false) ViewResolver[] viewResolvers; + private @Autowired(required=false) LocaleResolver localeResolver; + + @Override + public void build(HttpServletRequest httpReq, HttpServletResponse httpResp, IGuiBuilderConfiguration config, + String loggerName) throws GuiBuildException { + build(httpReq, httpResp, config, null, loggerName); + + } + + @Override + public void build(HttpServletRequest httpReq, HttpServletResponse httpResp, IGuiBuilderConfiguration config, + String contentType, String loggerName) throws GuiBuildException { + try { + final ModelAndView mav = new ModelAndView(config.getViewName()); + if (config.getViewParameters() != null) + mav.addAllObjects(config.getViewParameters()); + + render(mav, httpReq, httpResp); + + } catch (final Exception e) { + log.info("Can NOT generate GUI for illustration", e); + throw new GuiBuildException(e.getMessage(), e); + + } + + } + + protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception { + // Determine locale for request and apply it to the response. + final Locale locale = + (this.localeResolver != null ? this.localeResolver.resolveLocale(request) : request.getLocale()); + response.setLocale(locale); + + View view; + final String viewName = mv.getViewName(); + if (viewName != null) { + // We need to resolve the view name. + view = resolveViewName(viewName, mv.getModelMap(), locale, request); + if (view == null) + throw new ServletException("Could not resolve view with name '" + mv.getViewName() + "' "); + + } else { + // No need to lookup: the ModelAndView object contains the actual View object. + view = mv.getView(); + if (view == null) + throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " + "View object "); + + } + + // Delegate to the View object for rendering. + if (log.isTraceEnabled()) + log.trace("Rendering view [" + view + "] "); + + try { + if (mv.getStatus() != null) + response.setStatus(mv.getStatus().value()); + + view.render(mv.getModelMap(), request, response); + + } catch (final Exception ex) { + if (log.isDebugEnabled()) + log.debug("Error rendering view [" + view + "]", ex); + + throw ex; + + } + + } + + protected View resolveViewName(String viewName, @Nullable Map model, + Locale locale, HttpServletRequest request) throws Exception { + if (viewResolvers != null) { + for (final ViewResolver viewResolver : this.viewResolvers) { + final View view = viewResolver.resolveViewName(viewName, locale); + if (view != null) + return view; + + } + } + + return null; + } + +} diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/StaticGuiBuilderConfiguration.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/StaticGuiBuilderConfiguration.java index f3211598..db35c6e6 100644 --- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/StaticGuiBuilderConfiguration.java +++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/gui/StaticGuiBuilderConfiguration.java @@ -40,13 +40,13 @@ import org.slf4j.LoggerFactory; import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.gui.GroupDefinition; -import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration; +import at.gv.egiz.eaaf.core.api.gui.IVelocityGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; -import at.gv.egiz.eaaf.core.impl.gui.AbstractGUIFormBuilderConfiguration; +import at.gv.egiz.eaaf.core.impl.gui.AbstractGuiFormBuilderConfiguration; import at.gv.egiz.eaaf.core.impl.utils.FileUtils; -public class StaticGuiBuilderConfiguration extends AbstractGUIFormBuilderConfiguration implements IVelocityGUIBuilderConfiguration, ModifyableGuiBuilderConfiguration { +public class StaticGuiBuilderConfiguration extends AbstractGuiFormBuilderConfiguration implements IVelocityGuiBuilderConfiguration, ModifyableGuiBuilderConfiguration { private static final Logger log = LoggerFactory.getLogger(StaticGuiBuilderConfiguration.class); private IRequest pendingReq = null; @@ -58,7 +58,7 @@ public class StaticGuiBuilderConfiguration extends AbstractGUIFormBuilderConfigu } public StaticGuiBuilderConfiguration(IConfiguration basicConfig, IRequest pendingReq, String viewName, String formSubmitEndpoint) { - super(pendingReq.getAuthURL(), viewName, formSubmitEndpoint); + super(pendingReq.getAuthUrl(), viewName, formSubmitEndpoint); this.pendingReq = pendingReq; this.basicConfig = basicConfig; @@ -80,7 +80,7 @@ public class StaticGuiBuilderConfiguration extends AbstractGUIFormBuilderConfigu public InputStream getTemplate(String viewName) { String templateURL = MSeIDASNodeConstants.FILESYSTEM_TEMPLATE_DIR + viewName; try { - String absURL = FileUtils.makeAbsoluteURL(templateURL, this.basicConfig.getConfigurationRootDirectory()); + String absURL = FileUtils.makeAbsoluteUrl(templateURL, this.basicConfig.getConfigurationRootDirectory()); if (!absURL.startsWith("file:")) { log.warn("Path to template looks like NOT absolut: " + absURL + ". Template loading FAILED"); -- cgit v1.2.3