From 62a3115ce4d55a7a3b3fbf202bac0fff85dc412b Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Tue, 2 Aug 2022 14:18:37 +0200 Subject: YAGNI: PDF signer factory pattern --- .../java/at/asit/pdfover/signator/Signator.java | 86 ---------------------- .../main/java/at/asit/pdfover/signator/Signer.java | 48 ------------ .../at/asit/pdfover/signator/SignerFactory.java | 28 ------- 3 files changed, 162 deletions(-) delete mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java delete mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java delete mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java (limited to 'pdf-over-signator') diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java deleted file mode 100644 index 798788d2..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * 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://joinup.ec.europa.eu/software/page/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. - */ -package at.asit.pdfover.signator; - -//Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.util.EnumMap; -import java.util.Map; - -/** - * PDF Signator Interface - */ -public class Signator { - - /** - * SLF4J Logger instance - **/ - private static Logger log = LoggerFactory.getLogger(Signator.class); - - /** - * List of available PDF signing libraries - */ - public enum Signers { - /** - * PDF-AS 3 - */ - PDFAS, - /** - * PDF-AS 4 - */ - PDFAS4 - }; - - private static Map factoryMap; - - static { - factoryMap = new EnumMap(Signers.class); - - try { -// Class pdfAsClass = Class.forName("at.asit.pdfover.signer.pdfas.PDFASSignerFactory"); -// SignerFactory factory = (SignerFactory)pdfAsClass.newInstance(); -// registerSigner(Signers.PDFAS, factory); - Class pdfAs4Class = Class.forName("at.asit.pdfover.signer.pdfas.PdfAs4SignerFactory"); - SignerFactory factory = (SignerFactory)pdfAs4Class.getDeclaredConstructor().newInstance(); - registerSigner(Signers.PDFAS4, factory); - } catch (ClassNotFoundException e) { - log.error("PDF Signer Factory not found", e); - throw new RuntimeException("PDF Signer Factory not found", e); - } catch (InstantiationException | InvocationTargetException | NoSuchMethodException e) { - log.error("PDF Signer Factory could not be instantiated", e); - throw new RuntimeException("PDF Signer Factory could not be instantiated", e); - } catch (IllegalAccessException e) { - log.error("PDF Signer Factory could not accessed", e); - throw new RuntimeException("PDF Signer Factory could not accessed", e); - } - } - - private static void registerSigner(Signers signer, SignerFactory factory) { - factoryMap.put(signer, factory); - } - - /** - * Gets a PDF Signer according to the chosen signer library - * @param signer the chosen Signer type - * @return the PDF Signer - */ - public static Signer getSigner(Signers signer) { - return factoryMap.get(signer).createSigner(); - } -} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java deleted file mode 100644 index 5140f0e0..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * 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://joinup.ec.europa.eu/software/page/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. - */ -package at.asit.pdfover.signator; - -/** - * PDF Signer base Class - * This class should be extended to support libraries such as PDF-AS or PADES. - */ -public interface Signer { - - /** - * Prepare a signature - * Defines signature parameters, the pdf library prepares the pdf document to sign and - * creates a Security Layer Request. - * @param parameter The signature parameters - * @return The signing state (contains the prepared document and the signature request - * @throws SignatureException - */ - public SigningState prepare(SignatureParameter parameter) throws SignatureException; - - /** - * Adds the signature to the document. - * The SL Response has to be set in the state - * @param state The signing state - * @return The signature Result - * @throws SignatureException - */ - public SignResult sign(SigningState state) throws SignatureException; - - /** - * Creates new signing profile - * @return The new Profile - */ - public SignatureParameter newParameter(); -} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java deleted file mode 100644 index cde150f8..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * 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://joinup.ec.europa.eu/software/page/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. - */ -package at.asit.pdfover.signator; - -/** - * A Signer factory - * Creates Signer instances - */ -public abstract class SignerFactory { - /** - * Create a Signer - * @return the new Signer - */ - public abstract Signer createSigner(); -} -- cgit v1.2.3