diff options
author | emusic <emina.music@egiz.gv.at> | 2018-03-21 13:06:24 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2018-03-21 13:34:05 +0100 |
commit | e49eb5e433767386a09732f5942b6425098b511b (patch) | |
tree | 43fb29542b0ce702a0dbfbed8b4ead25f7872ac2 /pdf-as-lib/src/main/java/at/gv | |
parent | f60b607e56700bb6b3130c2ad549b0b1c14267a4 (diff) | |
download | pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.tar.gz pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.tar.bz2 pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.zip |
changes regarding protection, bug fix, thread safe
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv')
4 files changed, 53 insertions, 58 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 713948ba..3c560142 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -54,7 +54,7 @@ public interface IConfigurationConstants { public static final String CONFIG_BKU_URL = "bku.sign.url"; /*Protect PDF content*/ - public static final String DEFAULT_CONFIG_PROTECT_PDF=DEFAULT+SEPERATOR+"protectPDF"; + public static final String DEFAULT_CONFIG_PROTECT_PDF = DEFAULT+SEPERATOR+"protectPDF"; /** * MOA SS Signing Key Identifier @@ -114,12 +114,4 @@ public interface IConfigurationConstants { public static final String SIG_PADES_FORCE_FLAG= SIG_OBJECT + SEPERATOR+"PAdESCompatibility"; public static final String SIG_PADES_INTELL_FLAG = SIG_OBJECT + SEPERATOR+"CheckPAdESCompatibility"; - - /** - * Protect PDF file from copying content and extracting - */ - - public static final String DEFAULT_CONFIG_PROTECT_COPY_PDF = DEFAULT_CONFIG_PROTECT_PDF + SEPERATOR + "accessCopy"; - public static final String DEFAULT_CONFIG_PROTECT_EXTRACT_PDF = DEFAULT_CONFIG_PROTECT_PDF + SEPERATOR + "canModify"; - } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java index a40c336d..a677676d 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java @@ -41,26 +41,4 @@ public class GlobalConfiguration extends SpecificBaseConfiguration return null; } - public String getDefaultProtection() { - if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_PDF)) { - return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_PDF); - } - return null; - } - - public String getDefaultCopyProtection() { - if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_COPY_PDF)) { - return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_COPY_PDF); - } - return null; - } - - public String getDefaultExtractProtection() { - if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_EXTRACT_PDF)) { - return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_EXTRACT_PDF); - } - return null; - } - - } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java index 9906fd6a..4b1a5a49 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java @@ -44,6 +44,7 @@ public class PlaceholderFilter implements IConfigurationConstants, .getPlaceholderExtractor(); String placeholderID = settings.getValue(PLACEHOLDER_ID); String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; if (placeholderModeString != null) { try { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java index 8e84b491..8b9991fd 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java @@ -3,19 +3,19 @@ * 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 @@ -40,20 +40,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SLMarschaller { - private static Marshaller marshaller = null; - private static Unmarshaller unmarshaller = null; + + private static JAXBContext context = null; private static final Logger logger = LoggerFactory .getLogger(SLMarschaller.class); - + static { try { - JAXBContext context = JAXBContext.newInstance("at.gv.egiz.sl.schema"); - marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - - unmarshaller = context.createUnmarshaller(); + context = JAXBContext.newInstance("at.gv.egiz.sl.schema"); } catch (JAXBException e) { logger.error("Error in creating JAXBContext", e); throw new RuntimeException( @@ -61,17 +56,19 @@ public class SLMarschaller { } } - public static void marshal(Object obj, OutputStream os) throws JAXBException { + public static synchronized void marshal(Object obj, OutputStream os) throws JAXBException { + Marshaller marshaller = createMarshaller(); marshaller.marshal(obj, os); } - public static String marshalToString(Object obj) throws JAXBException { + public static synchronized String marshalToString(Object obj) throws JAXBException { + Marshaller marshaller = createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(obj, sw); return sw.toString(); } - - public static Object unmarshal(InputStream is) throws JAXBException { + + public static synchronized Object unmarshal(InputStream is) throws JAXBException { XMLInputFactory xif = null; try { xif = XMLInputFactory.newFactory(); @@ -79,19 +76,20 @@ public class SLMarschaller { // Fallback for old STAX implementations xif = XMLInputFactory.newInstance(); } - xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); - xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); - XMLStreamReader xmlStreamReader; + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; try { xmlStreamReader = xif.createXMLStreamReader(is); + Unmarshaller unmarshaller = createUnmarshaller(); return unmarshaller.unmarshal(xmlStreamReader); } catch (XMLStreamException e) { throw new JAXBException(e); } - + } - - public static Object unmarshalFromString(String message) throws JAXBException { + + public static synchronized Object unmarshalFromString(String message) throws JAXBException { StringReader sr = new StringReader(message); XMLInputFactory xif = null; try { @@ -100,15 +98,41 @@ public class SLMarschaller { // Fallback for old STAX implementations xif = XMLInputFactory.newInstance(); } - - xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); - xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); - XMLStreamReader xmlStreamReader; + + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; try { xmlStreamReader = xif.createXMLStreamReader(sr); + Unmarshaller unmarshaller = createUnmarshaller(); return unmarshaller.unmarshal(xmlStreamReader); } catch (XMLStreamException e) { throw new JAXBException(e); } } -} + + private static synchronized Marshaller createMarshaller() { + try { + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + return marshaller; + } + catch (JAXBException e) { + logger.error("Error in creating Marshaller", e); + throw new RuntimeException( + "There was a problem creating a Marshaller object for formatting the object to XML."); + } + } + + private static synchronized Unmarshaller createUnmarshaller() { + try { + return context.createUnmarshaller(); + } + catch (JAXBException e) { + logger.error("Error in creating Unmarshaller", e); + throw new RuntimeException( + "There was a problem creating a Unmarshaller object for formatting the object to XML."); + } + } +}
\ No newline at end of file |