aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2013-01-09 15:41:29 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2013-01-09 15:41:29 +0000
commit535a04fa05f739ec16dd81666e3b0f82dfbd442d (patch)
tree0804f301c1a9ceb303a8441b7b29244fc8eb7ff0 /src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
parent1efaf6fd5619dfa95c9d7e8c71eda4c2ffba4998 (diff)
downloadpdf-as-3-535a04fa05f739ec16dd81666e3b0f82dfbd442d.tar.gz
pdf-as-3-535a04fa05f739ec16dd81666e3b0f82dfbd442d.tar.bz2
pdf-as-3-535a04fa05f739ec16dd81666e3b0f82dfbd442d.zip
pdf-as-lib maven project files moved to pdf-as-lib
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/pdf-as/trunk@926 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java284
1 files changed, 0 insertions, 284 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java b/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
deleted file mode 100644
index ee2166e..0000000
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/**
- * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
- * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
- * joint initiative of the Federal Chancellery Austria 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.pdfas.impl.api;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters;
-import at.gv.egiz.pdfas.api.commons.Constants;
-import at.gv.egiz.pdfas.api.io.DataSource;
-import at.gv.egiz.pdfas.api.sign.SignParameters;
-import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
-import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
-import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
-import at.gv.egiz.pdfas.api.verify.VerifyParameters;
-import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
-import at.gv.egiz.pdfas.impl.api.sign.SignatureDetailInformationImpl;
-import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
-import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
-import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
-
-/**
- * Contains check methods frequently used by the {@link PdfAsObject} to check
- * input parameters.
- *
- * @author wprinz
- *
- */
-public final class CheckHelper
-{
- /**
- * The log.
- */
- private static Log log = LogFactory.getLog(CheckHelper.class);
-
- /**
- * Hidden default constructor.
- */
- private CheckHelper()
- {
- // empty block
- }
-
- /**
- * Checks the SignParameters for integrity.
- * This is a shortcut to {@link CheckHelper#checkSignParameters(SignParameters, false)}
- *
- * @param sp
- * The {@link SignParameters}
- */
- public static void checkSignParameters(SignParameters sp){
- checkSignParameters(sp, false);
- }
-
- /**
- * Checks the SignParameters for integrity.
- *
- * @param sp
- * The {@link SignParameters}
- * @param allowAllDevices if true, no check for non local BKUs will be done
- */
- public static void checkSignParameters(SignParameters sp, boolean allowAllDevices)
- {
- if (sp == null)
- {
- throw new IllegalArgumentException("The signParameters must not be null.");
- }
-
- checkDocument(sp.getDocument());
- if (sp.getOutput() == null)
- {
- throw new IllegalArgumentException("The output DataSink must not be null.");
- }
- checkSignatureType(sp.getSignatureType());
- if (!allowAllDevices)
- checkSignatureDevice(sp.getSignatureDevice());
- if (sp.getSignatureProfileId() != null)
- {
- checkProfileId(sp.getSignatureProfileId());
- }
- if (sp.getSignaturePositioning() != null)
- {
- checkSignaturePositioning(sp.getSignaturePositioning());
- }
- checkSignatureKeyIdentifier(sp.getSignatureKeyIdentifier(), sp.getSignatureDevice());
- checkTimestampHandler(sp);
- }
-
- /**
- * Checks the VerifyParameters for integrity.
- *
- * @param vp
- * The {@link VerifyParameters}
- */
- public static void checkVerifyParameters(VerifyParameters vp)
- {
- if (vp == null)
- {
- throw new IllegalArgumentException("The verifyParameters must not be null.");
- }
-
- checkDocument(vp.getDocument());
- checkVerifyMode(vp.getVerifyMode());
- checkSignatureDevice(vp.getSignatureDevice());
- if (vp.getSignatureToVerify() < Constants.VERIFY_ALL)
- {
- throw new IllegalArgumentException("The signatureToVerify parameter is incorrect. " + vp.getSignatureToVerify());
- }
- }
-
- /**
- * Checks the AnalyzeParameters for integrity.
- *
- * @param ap
- * The {@link AnalyzeParameters}
- */
- public static void checkAnalyzeParameters(AnalyzeParameters ap)
- {
- if (ap == null)
- {
- throw new IllegalArgumentException("The analyzeParameters must not be null.");
- }
-
- checkDocument(ap.getDocument());
- checkVerifyMode(ap.getVerifyMode());
- }
-
- /**
- * Checks the VerifyAfterAnalysisParameters for integrity.
- *
- * @param vaap
- * The {@link VerifyAfterAnalysisParameters}
- */
- public static void checkVerifyAfterAnalysisParameters(VerifyAfterAnalysisParameters vaap)
- {
- if (vaap == null)
- {
- throw new IllegalArgumentException("The analyzeParameters must not be null.");
- }
-
- if (vaap.getAnalyzeResult() == null)
- {
- throw new IllegalArgumentException("The analyzeResult must not be null.");
- }
- checkSignatureDevice(vaap.getSignatureDevice());
- }
-
- protected static void checkDocument(DataSource document)
- {
- if (document == null)
- {
- throw new IllegalArgumentException("The document DataSource must not be null.");
- }
- }
-
- protected static void checkSignatureType(String signatureType)
- {
- if (signatureType == null)
- {
- throw new IllegalArgumentException("The signatureType must not be null.");
- }
- if (!(signatureType.equals(Constants.SIGNATURE_TYPE_BINARY) || signatureType.equals(Constants.SIGNATURE_TYPE_TEXTUAL) || signatureType.equals(Constants.SIGNATURE_TYPE_DETACHEDTEXTUAL)))
- {
- throw new IllegalArgumentException("The signatureType must be one of the Constants.SIGNATURE_TYPE_* constants. " + signatureType);
- }
- }
-
- protected static void checkTimestampHandler(SignParameters params) {
- if (params.getTimeStamperImpl() != null && !Constants.SIGNATURE_TYPE_BINARY.equals(params.getSignatureType())) {
- throw new IllegalArgumentException("timestamping is only allowed for binary signatures ");
- }
- }
-
- protected static void checkProfileId(String profileId)
- {
- if (profileId == null)
- {
- throw new IllegalArgumentException("The profileId must not be null.");
- }
- try
- {
- if (!SignatureTypes.getInstance().getSignatureTypes().contains(profileId))
- {
- throw new IllegalArgumentException("The profileId \"" + profileId + "\" must be defined (code or configuration file.)");
- }
- }
- catch (SignatureTypesException e)
- {
- String msg = "Error while checking the profileId parameter - cannot get list of valid profiles. " + profileId;
- log.error(msg, e);
- throw new IllegalArgumentException(msg);
- }
- }
-
- protected static void checkSignaturePositioning(SignaturePositioning signaturePositioning)
- {
- if (signaturePositioning == null)
- {
- throw new IllegalArgumentException("The signaturePosition must not be null.");
- }
- try
- {
- PosHelper.formTablePos(signaturePositioning);
- }
- catch (PDFDocumentException e)
- {
- String msg = "The signaturePosition is not valid. Please check the provided parameters.";
- log.error(msg, e);
- throw new IllegalArgumentException(msg);
- }
- }
-
- protected static void checkSignatureKeyIdentifier (String signatureKeyIdentifier, String signatureDevice)
- {
- if (signatureKeyIdentifier != null && !Constants.SIGNATURE_DEVICE_MOA.equals(signatureDevice))
- {
- log.warn("A signatureKeyIdentifier (" + signatureKeyIdentifier + ") was provided although the signatureDevice (" + signatureDevice + ") is not moa. Currently only the moa signature device evaluates the signatureKeyIdentifier parameter.");
- }
- }
-
- protected static void checkVerifyMode(String verifyMode)
- {
- if (verifyMode == null)
- {
- throw new IllegalArgumentException("The verifyMode must not be null.");
- }
- if (!(verifyMode.equals(Constants.VERIFY_MODE_BINARY_ONLY) || verifyMode.equals(Constants.VERIFY_MODE_SEMI_CONSERVATIVE) || verifyMode.equals(Constants.VERIFY_MODE_FULL_CONSERVATIVE)))
- {
- throw new IllegalArgumentException("The verifyMode must be one of the Constants.VERIFY_MODE_* constants. " + verifyMode);
- }
- }
-
- protected static void checkSignatureDevice(String signatureDevice)
- {
- if (signatureDevice == null)
- {
- throw new IllegalArgumentException("The signatureDevice must not be null.");
- }
- if (!(signatureDevice.equals(Constants.SIGNATURE_DEVICE_BKU) || signatureDevice.equals(Constants.SIGNATURE_DEVICE_MOA)))
- {
- throw new IllegalArgumentException("The signatureDevice must be one of the Constants.SIGNATURE_DEVICE_* constants. " + signatureDevice);
- }
- }
-
- protected static void checkSignParametersForSignAfterPrepare(SignParameters signParameters, boolean allowAllDevices) {
- checkSignParameters(signParameters, allowAllDevices);
- checkProfileId(signParameters.getSignatureProfileId());
- }
-
- public static void checkSignatorInformation(SignatorInformation signatorInfo) {
- if (signatorInfo.getSignSignatureObject() == null)
- {
- throw new IllegalArgumentException("The signatorInformation.getSignSignatureObject() must not be null.");
- }
- }
-
- public static void checkSignatureDetailInformation(SignatureDetailInformation signatureDetailInformation) {
- if (!(signatureDetailInformation instanceof SignatureDetailInformationImpl)){
- throw new IllegalArgumentException("SignatureDetailInformation is of unsupported type. Must be " + SignatureDetailInformationImpl.class.getName());
- }
-
- }
-}