/* * Copyright 2003 Federal Chancellery Austria * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package at.gv.egovernment.moa.id.auth.builder; import java.text.MessageFormat; import java.util.Calendar; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.config.TargetToSectorNameMapper; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.util.Constants; import at.gv.egovernment.moa.util.DateTimeUtils; import at.gv.egovernment.moa.util.StringUtils; /** * Builder for the <CreateXMLSignatureRequest> structure * used for requesting a signature under the authentication block from the * security layer implementation. * * @author Paul Ivancsics * @version $Id$ */ public class CreateXMLSignatureRequestBuilder implements Constants { /** private static String nl contains the NewLine representation in Java*/ private static final String nl = "\n"; /** * XML template for the <moa:CreateXMLSignatureRequest> to be built */ private static final String CREATE_XML_SIGNATURE_REQUEST = "" + nl + "<{3}:CreateXMLSignatureRequest xmlns:dsig=''" + DSIG_NS_URI + "'' {5}>" + nl + " <{3}:KeyboxIdentifier>{1}" + nl + " <{3}:DataObjectInfo Structure=''detached''>" + nl + " <{4}:DataObject Reference=''''/>" + nl + "{2}" + " " + nl + " <{3}:SignatureInfo>" + nl + " <{3}:SignatureEnvironment>" + nl + " <{4}:XMLContent>{0}" + nl + " " + nl + " <{3}:SignatureLocation xmlns:saml=''" + SAML_NS_URI + "'' Index=''2''>/saml:Assertion" + nl + " " + nl + ""; /** * Constructor for CreateXMLSignatureRequestBuilder. */ public CreateXMLSignatureRequestBuilder() { super(); } /** * Builds the <CreateXMLSignatureRequest>. * * @param authBlock String representation of XML authentication block * @param keyBoxIdentifier the key box identifier which will be used (e.g. CertifiedKeypair) * @param slVersion12 specifies whether the Security Layer version number is 1.2 or not * @return String representation of <CreateXMLSignatureRequest> */ public String build(String authBlock, String keyBoxIdentifier, String[] dsigTransformInfos, boolean slVersion12) { String sl10Prefix; String sl11Prefix; String slNsDeclaration; String dsigTransformInfosString = ""; for (int i = 0; i < dsigTransformInfos.length; i++) { dsigTransformInfosString += dsigTransformInfos[i]; } if (slVersion12) { // replace the SecurityLayer namespace prefixes and URIs within the transforms dsigTransformInfosString = StringUtils.changeSLVersion(dsigTransformInfosString, SL10_PREFIX, SL12_PREFIX, SL10_NS_URI, SL12_NS_URI); sl10Prefix = SL12_PREFIX; sl11Prefix = SL12_PREFIX; slNsDeclaration = "xmlns:" + SL12_PREFIX + "='" + SL12_NS_URI + "'"; } else { sl10Prefix = SL10_PREFIX; sl11Prefix = SL11_PREFIX; slNsDeclaration = "xmlns:" + sl10Prefix + "='" + SL10_NS_URI + "' xmlns:" + sl11Prefix + "='" + SL11_NS_URI + "'"; } String request = MessageFormat.format( CREATE_XML_SIGNATURE_REQUEST, new Object[] { authBlock, keyBoxIdentifier, dsigTransformInfosString, sl11Prefix, sl10Prefix, slNsDeclaration }); return request; } /** * Builds the <CreateXMLSignatureRequest> for a foreign ID. * * @param subject the subject of the foreign certificate * @param oaParam parameter for the OA * @param session current session * @return String representation of <CreateXMLSignatureRequest> */ public String buildForeignID(String subject, OAAuthParameter oaParam, AuthenticationSession session) { String target = session.getTarget(); String sectorName = TargetToSectorNameMapper.getSectorNameViaTarget(target); Calendar cal = Calendar.getInstance(); String date = DateTimeUtils.buildDate(cal); String time = DateTimeUtils.buildTime(cal); String request = ""; request += ""; request += "SecureSignatureKeypair"; request += ""; request += ""; request += ""; request += ""; request += ""; request += "Signatur der Anmeldedaten"; request += ""; // request += ""; request += ""; request += ""; request += "

Authentication Data:

"; request += "

Personal Data

"; request += ""; request += ""; request += ""; request += ""; request += ""; request += "
Name:"; request += subject; request += "
"; request += "

Application Data

"; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += "
Name:"; // friendlyname from OA request += StringUtils.isEmpty(oaParam.getFriendlyName()) ? "" : oaParam.getFriendlyName(); request += "
Country:Austria
"; request += "

Technical Parameters

"; request += ""; request += ""; request += ""; request += ""; request += ""; boolean business = oaParam.getBusinessService(); if (business) { // OA is businessservice String identifierType = oaParam.getIdentityLinkDomainIdentifierType(); String identifier = oaParam.getIdentityLinkDomainIdentifier(); request += ""; request += ""; request += ""; request += ""; } else { // OA is publicservice request += ""; request += ""; request += ""; request += ""; } request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += ""; request += "
URL:"; //public URL prefix from OA request += oaParam.getPublicURLPrefix(); request += "
"; request += identifierType + ":"; request += ""; request += identifier; request += "
"; request += "Sector:"; request += target + " (" + sectorName + ")"; request += "
Date:"; request += date; request += "
Time:"; request += time; request += "
"; request += "

I hereby request to access this e-government application by using my " + "domestic electronic identity.
" + "I further affirm that I am not yet registered with the Austrian Central " + "Residents Registry and that I am not obliged to register with the Austrian " + "Central Residents Registry according to Austrian law.
" + "In the event I am not yet registered with the Supplementary Register, I " + "explicitly grant to do so according to §6 (5) E-Government Act (EGovG, idF: " + "BGBl. I Nr. 7/2008 und BGBl. I Nr. 59/2008).

"; request += ""; request += ""; request += "
"; request += "
"; request += ""; request += ""; request += "application/xhtml+xml"; request += ""; request += ""; request += "
"; request += "
"; return request; } }