From 596818361623dbe537536683146c3df2a2fcdbb2 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 12 Jan 2023 15:23:34 +0100 Subject: fix(sigblock): add mapping to support old RFC2255 names in signature-profile configurations Issue: #70 Add a mapping table into DNUtils to map specific RDN names to old format --- .../at/gv/egiz/pdfas/common/utils/DNUtils.java | 49 ++++++++++++---------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'pdf-as-common') diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java index 2ac91490..810a5d8a 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.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 @@ -23,6 +23,7 @@ ******************************************************************************/ package at.gv.egiz.pdfas.common.utils; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -31,30 +32,36 @@ import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class DNUtils { - private static final Logger logger = LoggerFactory.getLogger(DNUtils.class); - + private static final Map RFC2255_NAME_MAPPER = Collections.unmodifiableMap( + new HashMap() { + private static final long serialVersionUID = 3434415954591076154L; + { + put("title", "T"); + } + }); - public static Map dnToMap(String dn) throws InvalidNameException { - Map map = new HashMap(); + public static Map dnToMap(String dn) throws InvalidNameException { + final Map map = new HashMap<>(); - LdapName ldapName = new LdapName(dn); + final LdapName ldapName = new LdapName(dn); - Iterator rdnIterator = ldapName.getRdns().iterator(); + final Iterator rdnIterator = ldapName.getRdns().iterator(); - while(rdnIterator.hasNext()) { - Rdn rdn = rdnIterator.next(); + while (rdnIterator.hasNext()) { + final Rdn rdn = rdnIterator.next(); + map.put(rdn.getType(), rdn.getValue().toString()); - //logger.debug(rdn.getType() + " = " + rdn.getValue().toString()); - map.put(rdn.getType(), rdn.getValue().toString()); - } + // map specific RFC2255 names to support old PDF-AS signature-profile definitions + if (RFC2255_NAME_MAPPER.containsKey(rdn.getType())) { + map.put(RFC2255_NAME_MAPPER.get(rdn.getType()), rdn.getValue().toString()); - map.put("DN", dn); - //logger.debug("DN = " + dn); - - return map; + } + } + + map.put("DN", dn); + + return map; + } } -- cgit v1.2.3