/******************************************************************************* * 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.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import org.apache.commons.lang.StringEscapeUtils; import org.slf4j.Logger; 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.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.utils.FileUtils; public class StaticGuiBuilderConfiguration extends AbstractGUIFormBuilderConfiguration implements IVelocityGUIBuilderConfiguration, ModifyableGuiBuilderConfiguration { private static final Logger log = LoggerFactory.getLogger(StaticGuiBuilderConfiguration.class); private IRequest pendingReq = null; private IConfiguration basicConfig = null; public StaticGuiBuilderConfiguration(IConfiguration basicConfig, String authURL, String viewName, String formSubmitEndpoint) { super(authURL, viewName, formSubmitEndpoint); this.basicConfig = basicConfig; } public StaticGuiBuilderConfiguration(IConfiguration basicConfig, IRequest pendingReq, String viewName, String formSubmitEndpoint) { super(pendingReq.getAuthURL(), viewName, formSubmitEndpoint); this.pendingReq = pendingReq; this.basicConfig = basicConfig; } @Override public String getClasspathTemplateDir() { return MSeIDASNodeConstants.CLASSPATH_TEMPLATE_DIR; } @Override public String getDefaultContentType() { return null; } @Override public InputStream getTemplate(String viewName) { String templateURL = MSeIDASNodeConstants.FILESYSTEM_TEMPLATE_DIR + viewName; try { 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"); } else { log.debug("Load template URL for view: " + viewName + " from: " + absURL); URI uri = new URL(absURL).toURI(); return new FileInputStream(new File(uri)); } } catch (MalformedURLException | URISyntaxException | FileNotFoundException e) { log.info("Can can build filesytem path to template: " + templateURL + " Reason: " + e.getMessage()); } return null; } @Override public void putCustomParameterWithOutEscaption(GroupDefinition group, String key, Object value) { log.info("Add GUI-Template parameters WITHOUT escaption ARE NOT supported!!!!!"); } @Override public void putCustomParameter(GroupDefinition group, String key, String value) { setViewParameter(getFromGroup(), key, StringEscapeUtils.escapeHtml(value)); } @Override protected void putSpecificViewParameters() { if (pendingReq != null) { setViewParameter(getFromGroup(), PARAM_PENDINGREQUESTID, StringEscapeUtils.escapeHtml(pendingReq.getPendingRequestId())); setViewParameter(getFromGroup(), PARAM_PENDINGREQUESTID_DEPRECATED, StringEscapeUtils.escapeHtml(pendingReq.getPendingRequestId())); } } @Override protected GroupDefinition getFromGroup() { return null; } }