/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS 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.egiz.asic.xmlbind; import java.io.InputStream; import java.util.Date; import org.w3c.dom.Element; import at.gv.egiz.asic.api.ASiCFormat; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.api.SPSSFactory; import at.gv.egovernment.moa.spss.api.xmlbind.RequestParserUtils; import at.gv.egovernment.moaspss.util.Base64Utils; import at.gv.egovernment.moaspss.util.Constants; import at.gv.egovernment.moaspss.util.XPathUtils; /** * A parser to parse VerifyCMSSignatureRequest DOM trees into * VerifyCMSSignatureRequest API objects. * * @author Patrick Peck * @version $Id$ */ public class VerifyASICSignatureRequestParser { // // XPath expressions for selecting parts of the DOM message // private static final String MOA = Constants.MOA_PREFIX + ":"; private static final String DATE_TIME_XPATH = MOA + "DateTime"; private static final String EXTENDED_VALIDATION_XPATH = MOA + "ExtendedValidation"; private static final String ASIC_SIGNATURE_XPATH = MOA + "ASICSignature"; private static final String ASIC_EXTENSION_XPATH = MOA + "ASICExtension"; private static final String TRUST_PROFILE_ID_XPATH = MOA + "TrustProfileID"; /** The SPSSFactory for creating new API objects. */ private final SPSSFactory factory = SPSSFactory.getInstance(); /** * Parse a VerifyCMSSignatureRequest DOM element, as defined by the * MOA schema. * * @param requestElem The VerifyCMSSignatureRequest to parse. The * request must have been successfully parsed against the * schema for this method to succeed. * @return A VerifyCMSSignatureRequest API objects containing the * data from the DOM element. * @throws MOAApplicationException An error occurred parsing the request. */ public VerifyASiCRequest parseASIC(Element requestElem) throws MOAApplicationException { final Date dateTime = RequestParserUtils.parseDateTime(requestElem, DATE_TIME_XPATH); final boolean extendedValidation = RequestParserUtils.parseExtendedValidation(requestElem, EXTENDED_VALIDATION_XPATH, false); final String asicSignatureStr = XPathUtils.getElementValue(requestElem, ASIC_SIGNATURE_XPATH, ""); final String asicExtensionStr = XPathUtils.getElementValue(requestElem, ASIC_EXTENSION_XPATH, ""); final String trustProfileID = XPathUtils.getElementValue(requestElem, TRUST_PROFILE_ID_XPATH, null); // Logger.info("CMSSignature: " + cmsSignatureStr); final InputStream asicSignature = Base64Utils.decodeToStream(asicSignatureStr, true); ASiCFormat format = null; if ("asics".equalsIgnoreCase(asicExtensionStr) || "scs".equalsIgnoreCase(asicExtensionStr) || "application/vnd.etsi.asic-s+zip".equalsIgnoreCase(asicExtensionStr)) { format = ASiCFormat.ASiCS; } else if ("asice".equalsIgnoreCase(asicExtensionStr) || "sce".equalsIgnoreCase(asicExtensionStr) || "application/vnd.etsi.asic-e+zip".equalsIgnoreCase(asicExtensionStr)) { format = ASiCFormat.ASiCE; } return new VerifyASiCRequest(format, dateTime, asicSignature, trustProfileID, extendedValidation); } }