/*
* 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 at.gv.egiz.asic.api.ASiCVerificationResult;
import at.gv.egovernment.moa.spss.MOAApplicationException;
import at.gv.egovernment.moa.spss.MOAException;
import at.gv.egovernment.moa.spss.MOASystemException;
import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse;
import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponseElement;
import at.gv.egovernment.moa.spss.api.common.CheckResult;
import at.gv.egovernment.moa.spss.api.common.SignerInfo;
import at.gv.egovernment.moa.spss.api.xmlbind.ResponseBuilderUtils;
import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureResponseBuilder;
import at.gv.egovernment.moa.spss.api.xmlverify.AdESFormResults;
import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureResponseBuilder;
import at.gv.egovernment.moaspss.util.Constants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Iterator;
import java.util.List;
/**
* Convert a VerifyCMSSignatureResponse
API object into its
* XML representation, according to the MOA XML schema.
*
* @author Patrick Peck
* @version $Id$
*/
public class VerifyASICSignatureResponseBuilder {
/** The XML document containing the response element. */
private Document responseDoc;
/** The response VerifyCMSSignatureResponse
DOM element. */
private Element responseElem;
/**
* Create a new VerifyCMSSignatureResponseBuilder
:
*
* @throws MOASystemException An error occurred setting up the resulting
* XML document.
*/
public VerifyASICSignatureResponseBuilder() throws MOASystemException {
responseDoc =
ResponseBuilderUtils.createResponse("VerifyASICSignatureResponse");
responseElem = responseDoc.getDocumentElement();
}
/**
* Build a document containing a VerifyCMSSignatureResponse
* DOM element being the XML representation of the given
* VerifyCMSSignatureResponse
API object.
*
* @param response The VerifyCMSSignatureResponse
to convert
* to XML.
* @return A document containing the VerifyCMSSignatureResponse
* DOM element.
* @throws MOAApplicationException An error occurred building the response.
*/
public Document build(List results)
throws MOAException {
Iterator iter = results.iterator();
while(iter.hasNext()) {
ASiCVerificationResult aSiCVerificationResult = iter.next();
addASiCResultElement(aSiCVerificationResult);
}
return responseDoc;
}
private void addASiCResultElement(ASiCVerificationResult aSiCVerificationResult)
throws MOAException {
Element asiCSignatureResultElem = responseDoc.createElementNS(Constants.MOA_NS_URI, "ASiCSignatureResult");
Iterator signedFiles = aSiCVerificationResult.getSignedFiles().iterator();
while (signedFiles.hasNext()) {
String signedFile = signedFiles.next();
Element signedFilesElem = responseDoc.createElementNS(Constants.MOA_NS_URI, "signedFiles");
signedFilesElem.setTextContent(signedFile);
asiCSignatureResultElem.appendChild(signedFilesElem);
}
if(aSiCVerificationResult.getXmlResult() != null) {
VerifyXMLSignatureResponseBuilder verifyXMLSignatureResponseBuilder = new VerifyXMLSignatureResponseBuilder(this.responseDoc, "XMLSignatureResult", true);
asiCSignatureResultElem.appendChild(verifyXMLSignatureResponseBuilder.buildElement(aSiCVerificationResult.getXmlResult()));
} else if(aSiCVerificationResult.getCmsResult() != null) {
VerifyCMSSignatureResponseBuilder verifyCMSSignatureResponseBuilder = new VerifyCMSSignatureResponseBuilder(this.responseDoc, "CMSSignatureResult", true);
asiCSignatureResultElem.appendChild(verifyCMSSignatureResponseBuilder.buildElement(aSiCVerificationResult.getCmsResult()));
}
responseElem.appendChild(asiCSignatureResultElem);
}
/**
* Add an element to the response.
*
* @param responseElement The element to add to the response.
* @throws MOAApplicationException An error occurred adding the element.
*/
private void addResponseElement(VerifyCMSSignatureResponseElement responseElement)
throws MOAApplicationException {
SignerInfo signerInfo = responseElement.getSignerInfo();
CheckResult signatureCheck = responseElement.getSignatureCheck();
CheckResult certCheck = responseElement.getCertificateCheck();
ResponseBuilderUtils.addSignerInfo(
responseDoc,
responseElem,
signerInfo.getSignerCertificate(),
signerInfo.isQualifiedCertificate(),
signerInfo.getQCSource(),
signerInfo.isPublicAuthority(),
signerInfo.getPublicAuhtorityID(),
signerInfo.isSSCD(),
signerInfo.getSSCDSource(),
signerInfo.getIssuerCountryCode(),
signerInfo.getTslInfos());
ResponseBuilderUtils.addCodeInfoElement(
responseDoc,
responseElem,
"SignatureCheck",
signatureCheck.getCode(),
signatureCheck.getInfo());
ResponseBuilderUtils.addCodeInfoElement(
responseDoc,
responseElem,
"CertificateCheck",
certCheck.getCode(),
certCheck.getInfo());
if (responseElement.getAdESFormResults() != null) {
Iterator formIterator = responseElement.getAdESFormResults().iterator();
while (formIterator.hasNext()) {
AdESFormResults adESFormResult = (AdESFormResults) formIterator.next();
// add the CertificateCheck
ResponseBuilderUtils.addFormCheckElement(responseDoc, responseElem, "FormCheckResult",
adESFormResult.getCode().intValue(), adESFormResult.getName());
}
}
if(responseElement.getExtendedCertificateCheck() != null) {
ResponseBuilderUtils.addExtendendResult(responseDoc, responseElem, responseElement.getExtendedCertificateCheck());
}
}
}