aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java157
1 files changed, 157 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java
new file mode 100644
index 000000000..b95cbbc16
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/GUILayoutBuilder.java
@@ -0,0 +1,157 @@
+/*
+ * 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.builder;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+
+import org.apache.commons.io.IOUtils;
+
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory;
+import at.gv.egovernment.moa.id.config.auth.IOAAuthParameters;
+import at.gv.egovernment.moa.id.moduls.IRequest;
+import at.gv.egovernment.moa.id.util.FormBuildUtils;
+import at.gv.egovernment.moa.logging.Logger;
+
+/**
+ * @author tlenz
+ *
+ */
+public class GUILayoutBuilder {
+ private static final String CSS_LAYOUTTEMPLATE = "css_template.css";
+ private static final String JS_LAYOUTTEMPLATE = "javascript_tempalte.js";
+ private static final String HTMLTEMPLATESDIR = "htmlTemplates/";
+
+ private static String CONTEXTPATH = "#CONTEXTPATH#";
+ private static String MOASESSIONID = "#SESSIONID#";
+ private static String AUTH_URL = "#AUTH_URL#";
+ private static String BKU_ONLINE = "#ONLINE#";
+ private static String BKU_HANDY = "#HANDY#";
+ private static String BKU_LOCAL = "#LOCAL#";
+
+
+ public static String buildCSS(IRequest pendingReq, String authURL) {
+ return buildForm(pendingReq, authURL, CSS_LAYOUTTEMPLATE);
+
+ }
+
+ public static String buildJS(IRequest pendingReq, String authURL) {
+ return buildForm(pendingReq, authURL, JS_LAYOUTTEMPLATE);
+
+ }
+
+
+
+ private static String getTemplate(String templateName) {
+ String pathLocation;
+ InputStream input = null;
+ try {
+ String rootconfigdir = AuthConfigurationProviderFactory.getInstance().getRootConfigFileDir();
+ pathLocation = rootconfigdir + HTMLTEMPLATESDIR + templateName;
+
+ try {
+ File file = new File(new URI(pathLocation));
+ input = new FileInputStream(file);
+
+ } catch (FileNotFoundException e) {
+ Logger.warn("No LoginFormTempaltes found. Use Generic Templates from package.");
+ pathLocation = "resources/templates/" + templateName;
+ input = Thread.currentThread()
+ .getContextClassLoader()
+ .getResourceAsStream(pathLocation);
+
+ }
+
+ return getTemplate(input);
+
+ } catch (Exception e) {
+ return null;
+
+ } finally {
+ try {
+ if (input != null)
+ input.close();
+
+ } catch (IOException e) {
+ Logger.warn("SendAssertionTemplate inputstream can not be closed.", e);
+
+ }
+ }
+ }
+
+ private static String getTemplate(InputStream input) {
+ String template = null;
+ try {
+
+ StringWriter writer = new StringWriter();
+ IOUtils.copy(input, writer);
+ template = writer.toString();
+
+ } catch (Exception e) {
+ Logger.error("Failed to read template", e);
+
+ }
+ return template;
+ }
+
+ private static String buildForm(IRequest pendingReq, String authURL, String templateName) {
+ //load default GUI-Layout template template
+ String value = getTemplate(templateName);
+
+ if (pendingReq != null) {
+ IOAAuthParameters oaParam = pendingReq.getOnlineApplicationConfiguration();
+
+ if(value != null) {
+ //only for BKU-Selection step and JavaScript generation
+ value = value.replace(AUTH_URL, LoginFormBuilder.SERVLET);
+
+ value = value.replace(CONTEXTPATH, pendingReq.getAuthURL());
+ value = value.replace(MOASESSIONID, pendingReq.getRequestID());
+
+ value = value.replace(BKU_ONLINE, IOAAuthParameters.ONLINEBKU);
+ value = value.replace(BKU_HANDY, IOAAuthParameters.HANDYBKU);
+ value = value.replace(BKU_LOCAL, IOAAuthParameters.LOCALBKU);
+
+
+ value = FormBuildUtils.customiceLayoutBKUSelection(value,
+ oaParam.isShowMandateCheckBox(),
+ oaParam.isOnlyMandateAllowed(),
+ oaParam.getFormCustomizaten(),
+ oaParam.isShowStorkLogin());
+ }
+
+ } else {
+ value = FormBuildUtils.defaultLayoutBKUSelection(value);
+ value = value.replace(CONTEXTPATH, authURL);
+
+ }
+
+ return value;
+ }
+
+}