aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java111
1 files changed, 74 insertions, 37 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java
index a80fcfa25..0746d1be1 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/LoginFormBuilder.java
@@ -1,27 +1,51 @@
+/*******************************************************************************
+ * 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 java.net.URISyntaxException;
import org.apache.commons.io.IOUtils;
-import at.gv.egovernment.moa.id.auth.servlet.GenerateIFrameTemplateServlet;
-import at.gv.egovernment.moa.id.config.OAParameter;
+import at.gv.egovernment.moa.id.config.ConfigurationException;
import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
import at.gv.egovernment.moa.id.config.auth.OAAuthParameter;
import at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol;
+import at.gv.egovernment.moa.id.util.FormBuildUtils;
import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
public class LoginFormBuilder {
private static final String HTMLTEMPLATESDIR = "htmlTemplates/";
private static final String HTMLTEMPLATEFULL = "loginFormFull.html";
- private static final String HTMLTEMPLATEIFRAME = "loginFormIFrame.html";
-
+
private static String AUTH_URL = "#AUTH_URL#";
private static String MODUL = "#MODUL#";
private static String ACTION = "#ACTION#";
@@ -29,40 +53,42 @@ public class LoginFormBuilder {
private static String BKU_ONLINE = "#ONLINE#";
private static String BKU_HANDY = "#HANDY#";
private static String BKU_LOCAL = "#LOCAL#";
- private static String CONTEXTPATH = "#CONTEXTPATH#";
+ public static String CONTEXTPATH = "#CONTEXTPATH#";
private static String MOASESSIONID = "#SESSIONID#";
-
+
private static String SERVLET = CONTEXTPATH+"/GenerateIframeTemplate";
- private static String getTemplate(boolean isIFrame) {
+ public static String getTemplate() {
+ String pathLocation ="";
+ InputStream input = null;
+
+ try {
+ String rootconfigdir = AuthConfigurationProvider.getInstance().getRootConfigFileDir();
+ pathLocation = rootconfigdir + HTMLTEMPLATESDIR + HTMLTEMPLATEFULL;
+ File file = new File(new URI(pathLocation));
+ input = new FileInputStream(file);
+
+ } catch (ConfigurationException e) {
+ Logger.warn("MOA-ID configuration can not be loaded.");
+
+ } catch (Exception e) {
+
+ }
+
+ return getTemplate(input);
+
+ }
+
+ public static String getTemplate(InputStream input) {
String template = null;
-
- try {
- String pathLocation;
-
- InputStream input;
-
- String rootconfigdir = AuthConfigurationProvider.getInstance().getRootConfigFileDir();
- if (isIFrame)
- pathLocation = rootconfigdir + HTMLTEMPLATESDIR + HTMLTEMPLATEIFRAME;
- else
- pathLocation = rootconfigdir + HTMLTEMPLATESDIR + HTMLTEMPLATEFULL;
-
- try {
- File file = new File(new URI(pathLocation));
- input = new FileInputStream(file);
-
- } catch (FileNotFoundException e) {
+ try {
+ if (input == null) {
Logger.warn("No LoginFormTempaltes found. Use Generic Templates from package.");
- if (isIFrame)
- pathLocation = "resources/templates/" + HTMLTEMPLATEIFRAME;
- else
- pathLocation = "resources/templates/" + HTMLTEMPLATEFULL;
-
+ String pathLocation = "resources/templates/" + HTMLTEMPLATEFULL;
input = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(pathLocation);
@@ -76,17 +102,23 @@ public class LoginFormBuilder {
template = template.replace(BKU_ONLINE, OAAuthParameter.ONLINEBKU);
template = template.replace(BKU_HANDY, OAAuthParameter.HANDYBKU);
template = template.replace(BKU_LOCAL, OAAuthParameter.LOCALBKU);
-
- input.close();
-
+
} catch (Exception e) {
Logger.error("Failed to read template", e);
+
+ } finally {
+ try {
+ input.close();
+
+ } catch (IOException e) {
+ Logger.warn("SendAssertionTemplate inputstream can not be closed.", e);
+ }
}
return template;
}
-
- public static String buildLoginForm(String modul, String action, String oaname, String contextpath, boolean isIFrame, String moaSessionID) {
- String value = getTemplate(isIFrame);
+
+ public static String buildLoginForm(String modul, String action, OAAuthParameter oaParam, String contextpath, String moaSessionID) {
+ String value = getTemplate();
if(value != null) {
if(modul == null) {
@@ -97,11 +129,16 @@ public class LoginFormBuilder {
}
value = value.replace(MODUL, modul);
value = value.replace(ACTION, action);
- value = value.replace(OANAME, oaname);
+ value = value.replace(OANAME, oaParam.getFriendlyName());
value = value.replace(CONTEXTPATH, contextpath);
value = value.replace(MOASESSIONID, moaSessionID);
+
+ value = FormBuildUtils.customiceLayoutBKUSelection(value,
+ oaParam.isShowMandateCheckBox(),
+ oaParam.isOnlyMandateAllowed(),
+ oaParam.getFormCustomizaten());
+
}
return value;
}
-
}