/* * 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. * * 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/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence 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. * * 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.gv.egovernment.moa.id.auth.frontend.builder; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.lang.StringEscapeUtils; 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.impl.gui.AbstractGUIFormBuilderConfiguration; import at.gv.egovernment.moa.id.auth.frontend.utils.FormBuildUtils; import at.gv.egovernment.moa.id.commons.MOAIDAuthConstants; import at.gv.egovernment.moa.id.commons.api.IOAAuthParameters; import at.gv.egovernment.moa.id.commons.api.data.CPEPS; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; /** * @author tlenz * */ public abstract class AbstractServiceProviderSpecificGUIFormBuilderConfiguration extends AbstractGUIFormBuilderConfiguration implements IVelocityGUIBuilderConfiguration { public static final String VIEW_TEMPLATE_MAINGUI_DIRECTORY = "mainGUI/"; public static final String VIEW_BKUSELECTION = "loginFormFull.html"; public static final String VIEW_SENDASSERTION = "sendAssertionFormFull.html"; public static final String VIEW_TEMPLATE_CSS = "css_template.css"; public static final String VIEW_TEMPLATE_JS = "javascript_tempalte.js"; public static final String VIEW_TEMPLATE_BKUDETECTION_SP_SPECIFIC = "iframeLBKUdetectSPSpecific.html"; public static final String VIEW_TEMPLATE_BKUDETECTION_GENERIC = "iframeLBKUdetect.html"; public static final String PARAM_BKU_ONLINE = "bkuOnline"; public static final String PARAM_BKU_HANDY = "bkuHandy"; public static final String PARAM_BKU_LOCAL = "bkuLocal"; public static final String PARAM_BKU_URL_HANDY = "bkuURLHandy"; public static final String PARAM_BKU_URL_LOCAL = "bkuURLLocal"; public static final String PARAM_BKU_URL_THIRD = "bkuURLThird"; public static final String PARAM_OANAME = "OAName"; public static final String PARAM_COUNTRYLIST = "countryList"; public static final String PARAM_EIDAS_VISIBLE = "eIDASVisible"; protected IRequest pendingReq = null; protected String templateClasspahtDir = null; private Map customParameters = null; /** * @param authURL PublicURLPrefix of the IDP but never null * @param viewName Name of the template (with suffix) but never null * @param formSubmitEndpoint EndPoint on which the form should be submitted, * or null if the form must not submitted */ public AbstractServiceProviderSpecificGUIFormBuilderConfiguration(String authURL, String viewName, String formSubmitEndpoint) { super(authURL, viewName, formSubmitEndpoint); } /** * @param Current processed pending-request DAO but never null * @param viewName Name of the template (with suffix) but never null * @param formSubmitEndpoint EndPoint on which the form should be submitted, * or null if the form must not submitted */ public AbstractServiceProviderSpecificGUIFormBuilderConfiguration(IRequest pendingReq, String viewName, String formSubmitEndpoint) { super(pendingReq.getAuthURL(), viewName, formSubmitEndpoint); this.pendingReq = pendingReq; } /** * Add a key/value pair into Velocity context.
* Parameter values get escaped internally * * @param key velocity context key * @param value of this key */ public void putCustomParameter(String key, Object value) { if (customParameters == null) customParameters = new HashMap(); if (value instanceof String) customParameters.put(key, StringEscapeUtils.escapeHtml((String)value)); else customParameters.put(key, StringEscapeUtils.escapeHtml(value.toString())); } @Override protected final GroupDefinition getFromGroup() { return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.builder.IGUIBuilderConfiguration#getViewParameters() */ @Override public final void putSpecificViewParameters() { if (customParameters == null) customParameters = new HashMap(); setViewParameter(null, PARAM_BKU_ONLINE, IOAAuthParameters.THIRDBKU); setViewParameter(null, PARAM_BKU_HANDY, IOAAuthParameters.HANDYBKU); setViewParameter(null, PARAM_BKU_LOCAL, IOAAuthParameters.LOCALBKU); if (pendingReq != null) { setViewParameter(null, PARAM_PENDINGREQUESTID, StringEscapeUtils.escapeHtml(pendingReq.getPendingRequestId())); setViewParameter(null, PARAM_PENDINGREQUESTID_DEPRECATED, StringEscapeUtils.escapeHtml(pendingReq.getPendingRequestId())); //add service-provider specific GUI parameters IOAAuthParameters oaParam = pendingReq.getServiceProviderConfiguration(IOAAuthParameters.class); if (oaParam != null) { setViewParameter(null, PARAM_OANAME, StringEscapeUtils.escapeHtml(oaParam.getFriendlyName())); //set BKU URLs if (MiscUtil.isNotEmpty(oaParam.getBKUURL(IOAAuthParameters.LOCALBKU))) setViewParameter(null, PARAM_BKU_URL_LOCAL, oaParam.getBKUURL(IOAAuthParameters.LOCALBKU)); else setViewParameter(null, PARAM_BKU_URL_LOCAL, MOAIDAuthConstants.DEFAULT_BKU_HTTPS); if (MiscUtil.isNotEmpty(oaParam.getBKUURL(IOAAuthParameters.HANDYBKU))) setViewParameter(null, PARAM_BKU_URL_HANDY, oaParam.getBKUURL(IOAAuthParameters.HANDYBKU)); if (MiscUtil.isNotEmpty(oaParam.getBKUURL(IOAAuthParameters.THIRDBKU))) setViewParameter(null, PARAM_BKU_URL_THIRD, oaParam.getBKUURL(IOAAuthParameters.THIRDBKU)); //set eIDAS login information if requird if (oaParam.isShowStorkLogin()) { addCountrySelection(customParameters, oaParam); setViewParameter(null, PARAM_EIDAS_VISIBLE, ""); } else { setViewParameter(null, PARAM_COUNTRYLIST, ""); setViewParameter(null, PARAM_EIDAS_VISIBLE, FormBuildUtils.TEMPLATEUNVISIBLE); } FormBuildUtils.customiceLayoutBKUSelection(customParameters, oaParam); } else FormBuildUtils.defaultLayoutBKUSelection(customParameters); } else { //add default GUI parameters FormBuildUtils.defaultLayoutBKUSelection(customParameters); } //add additional custom parameters if (customParameters != null) { for (Entry el : customParameters.entrySet()) setViewParameter(null, el.getKey(), el.getValue()); } } /** * @param params * @param oaParam */ private void addCountrySelection(Map params, IOAAuthParameters oaParam) { String pepslist = ""; try { for (CPEPS current : oaParam.getPepsList()) { String countryName = null; if (MiscUtil.isNotEmpty(MOAIDAuthConstants.COUNTRYCODE_XX_TO_NAME.get(current.getFullCountryCode().toUpperCase()))) countryName = MOAIDAuthConstants.COUNTRYCODE_XX_TO_NAME.get(current.getFullCountryCode().toUpperCase()); else countryName = current.getFullCountryCode().toUpperCase(); pepslist += "\n"; } params.put(PARAM_COUNTRYLIST, pepslist); } catch (NullPointerException e) { Logger.warn("Can not at Countries to GUI. Msg:" + e.getMessage()); } } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.AbstractGUIFormBuilder#getClasspathTemplateDir() */ @Override public String getClasspathTemplateDir() { return templateClasspahtDir; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.AbstractGUIFormBuilder#getTemplate(java.lang.String) */ @Override public InputStream getTemplate(String viewName) { if (pendingReq != null && pendingReq.getServiceProviderConfiguration(IOAAuthParameters.class) != null) { byte[] oatemplate = null; if (VIEW_BKUSELECTION.equals(viewName)) oatemplate = pendingReq.getServiceProviderConfiguration(IOAAuthParameters.class).getBKUSelectionTemplate(); else if (VIEW_SENDASSERTION.equals(viewName)) oatemplate = pendingReq.getServiceProviderConfiguration(IOAAuthParameters.class).getSendAssertionTemplate(); // OA specific template requires a size of 8 bits minimum if (oatemplate != null && oatemplate.length > 7) return new ByteArrayInputStream(oatemplate); } return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.AbstractGUIFormBuilder#getDefaultContentType() */ @Override public String getDefaultContentType() { return null; } /** * Set a specific classPath directory for this template configuration. *
If the directory is null then the default directory /templates is used. * * @param templateClasspahtDir the templateClasspahtDir to set */ public void setTemplateClasspahtDir(String templateClasspahtDir) { this.templateClasspahtDir = templateClasspahtDir; } }