diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2016-02-25 14:31:49 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2016-02-25 14:31:49 +0100 |
commit | afe6acdbabf17194cf2deb7df47c70399f9d23ab (patch) | |
tree | 7ed4e8c502bf94326c603767fd0c34fcff45a331 /id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder | |
parent | 19f91c16f69b97c70ffe9a290305737bd351aae8 (diff) | |
download | moa-id-spss-afe6acdbabf17194cf2deb7df47c70399f9d23ab.tar.gz moa-id-spss-afe6acdbabf17194cf2deb7df47c70399f9d23ab.tar.bz2 moa-id-spss-afe6acdbabf17194cf2deb7df47c70399f9d23ab.zip |
generate CSS und JS for GUI dynamically.
Now all html templates must not include it's on CSS and JS as inline code
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder')
2 files changed, 158 insertions, 3 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; + } + +} 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 4bcda3517..e1aa41ce2 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 @@ -47,8 +47,6 @@ public class LoginFormBuilder { private static final String HTMLTEMPLATEFULL = "loginFormFull.html"; private static String AUTH_URL = "#AUTH_URL#"; - private static String MODUL = "#MODUL#"; - private static String ACTION = "#ACTION#"; private static String OANAME = "#OAName#"; private static String BKU_ONLINE = "#ONLINE#"; private static String BKU_HANDY = "#HANDY#"; @@ -57,7 +55,7 @@ public class LoginFormBuilder { private static String MOASESSIONID = "#SESSIONID#"; private static String PEPSLIST = "#PEPSLIST#"; - private static String SERVLET = CONTEXTPATH+"/GenerateIframeTemplate"; + public static String SERVLET = CONTEXTPATH+"/GenerateIframeTemplate"; private static String getTemplate() { String pathLocation =""; |