/*******************************************************************************
* 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.
******************************************************************************/
/*
* Copyright 2003 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.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import at.gv.egovernment.moa.id.auth.exception.BuildException;
import at.gv.egovernment.moa.id.auth.frontend.utils.FormBuildUtils;
import at.gv.egovernment.moa.id.commons.api.IOAAuthParameters;
import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants;
import at.gv.egovernment.moa.util.MiscUtil;
/**
* Builder for HTML form requesting the security layer implementation
* to get the identity link from smartcard by a <InfoboxReadRequest>
.
*
* @author Paul Ivancsics
* @version $Id$
*/
public class GetIdentityLinkFormBuilder extends Builder {
/** private static String NL contains the NewLine representation in Java*/
private static final String nl = "\n";
/** special tag in the HTML template to be substituted for the BKU URL */
private static final String BKU_TAG = "";
/** special tag in the HTML template to be substituted for the XML request */
private static final String XMLREQUEST_TAG = "";
/** special tag in the HTML template to be substituted for the data URL */
private static final String DATAURL_TAG = "";
// /** special tag in the HTML template to be substituted for certificate info XML request */
// private static final String CERTINFO_XMLREQUEST_TAG = "";
// /** special tag in the HTML template to be substituted for the certificate info data URL */
// private static final String CERTINFO_DATAURL_TAG = "";
/** special tag in the HTML template to be substituted for the infoboxes to be pushed from the BKU */
private static final String PUSHINFOBOX_TAG = "";
private static final String CONTEXTURL_TAG = "";
/** special tag in the HTML template to be substituted for the BKU URL */
/** private static int all contains the representation to replace all tags*/
private static final int ALL = -1;
private static final String COLOR_TAG = "";
private static final String REDIRECTTARGETTAG = "";
private static final String APPLETWIDTH_TAG = "";
private static final String APPLETHEIGHT_TAG = "";
/** default HTML template */
private static final String DEFAULT_HTML_TEMPLATE =
"" + nl +
"" + nl +
"" + nl +
"Anmeldung mit Bürgerkarte" + nl +
"" + nl +
"" + nl +
"" + nl +
// "" + nl +
"" + nl +
"";
/**
* Constructor for GetIdentityLinkFormBuilder.
*/
public GetIdentityLinkFormBuilder() {
super();
}
/**
* Builds the HTML form, including XML Request and data URL as parameters.
*
* @param htmlTemplate template to be used for the HTML form;
* may be null
, in this case a default layout will be produced
* @param xmlRequest XML Request to be sent as a parameter in the form
* @param bkuURL URL of the "Bürgerkartenumgebung" the form will be submitted to;
* may be null
, in this case the default URL will be used
* @param dataURL DataURL to be sent as a parameter in the form
* @param oaParam
* @param appletwidth
* @param appletheigth
*/
public String build(
String htmlTemplate,
String bkuURL,
String xmlRequest,
String dataURL,
String certInfoXMLRequest,
String certInfoDataURL,
String pushInfobox,
IOAAuthParameters oaParam,
String appletheigth,
String appletwidth,
String contextURL)
throws BuildException
{
String htmlForm = htmlTemplate == null ? DEFAULT_HTML_TEMPLATE : htmlTemplate;
htmlForm = replaceTag(htmlForm, BKU_TAG, bkuURL, true, ALL);
htmlForm = replaceTag(htmlForm, XMLREQUEST_TAG, encodeParameter(xmlRequest), true, ALL);
htmlForm = replaceTag(htmlForm, DATAURL_TAG, dataURL, true, ALL);
htmlForm = replaceTag(htmlForm, PUSHINFOBOX_TAG, pushInfobox, false, ALL);
htmlForm = replaceTag(htmlForm, CONTEXTURL_TAG, contextURL, false, ALL);
//new:wird oben mitreplaced htmlForm = replaceTag(htmlForm, BKU_TAG, bkuURL);
//set applet-background coller
if (oaParam != null && MiscUtil.isNotEmpty(oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_BACKGROUNDCOLOR)))
htmlForm = replaceTag(htmlForm, COLOR_TAG,
oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_BACKGROUNDCOLOR), false, ALL);
else
htmlForm = replaceTag(htmlForm, COLOR_TAG, FormBuildUtils.getDefaultMap().get(FormBuildUtils.PARAM_MAIN_BACKGROUNDCOLOR), false, ALL);
//set redirect target
if (oaParam != null && MiscUtil.isNotEmpty(oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETREDIRECTTARGET)))
htmlForm = replaceTag(htmlForm, REDIRECTTARGETTAG,
oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETREDIRECTTARGET), false, ALL);
else
htmlForm = replaceTag(htmlForm, REDIRECTTARGETTAG, FormBuildUtils.getDefaultMap().get(FormBuildUtils.PARAM_REDIRECTTARGET), false, ALL);
//set applet heigh
if (oaParam != null && MiscUtil.isNotEmpty(oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETHEIGHT)))
htmlForm = replaceTag(htmlForm, APPLETHEIGHT_TAG, oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETHEIGHT), false, ALL);
else if (MiscUtil.isNotEmpty(appletheigth))
htmlForm = replaceTag(htmlForm, APPLETHEIGHT_TAG, appletheigth, false, ALL);
else
htmlForm = replaceTag(htmlForm, APPLETHEIGHT_TAG, "160", false, ALL);
//set applet width
if (oaParam != null && MiscUtil.isNotEmpty(oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETWIDTH)))
htmlForm = replaceTag(htmlForm, APPLETWIDTH_TAG, oaParam.getConfigurationValue(MOAIDConfigurationConstants.SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_APPLETWIDTH), false, ALL);
else if (MiscUtil.isNotEmpty(appletwidth))
htmlForm = replaceTag(htmlForm, APPLETWIDTH_TAG, appletwidth, false, ALL);
else
htmlForm = replaceTag(htmlForm, APPLETWIDTH_TAG, "250", false, ALL);
return htmlForm;
}
/**
* Encodes a string for inclusion as a parameter in the form.
* Double quotes are substituted by """
.
* @param s the string to be encoded
* @return the string encoded
* @throws BuildException on any exception encountered
*/
public static String encodeParameter(String s) throws BuildException {
StringReader in = new StringReader(s);
StringWriter out = new StringWriter();
try {
for (int ch = in.read(); ch >= 0; ch = in.read()) {
if (ch == '"') {
out.write(""");
} else if (ch == '<') {
out.write("<");
} else if (ch == '>') {
out.write(">");
} else if (ch == 'ä') {
out.write("ä");
} else if (ch == 'ö') {
out.write("ö");
} else if (ch == 'ü') {
out.write("ü");
} else if (ch == 'Ä') {
out.write("Ä");
} else if (ch == 'Ö') {
out.write("Ö");
} else if (ch == 'Ü') {
out.write("Ü");
} else if (ch == 'ß') {
out.write("ß");
} else {
out.write(ch);
}
}
}
catch (IOException ex) {
throw new BuildException("builder.00", new Object[] {"GetIdentityLinkForm", ex.toString()});
}
return out.toString();
}
}