From 535a04fa05f739ec16dd81666e3b0f82dfbd442d Mon Sep 17 00:00:00 2001 From: tknall Date: Wed, 9 Jan 2013 15:41:29 +0000 Subject: 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 --- .../egiz/ldap/client/LDAPClientFactoryImpl.java | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java new file mode 100644 index 0000000..ae3cbc1 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java @@ -0,0 +1,118 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * 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.knowcenter.wag.egov.egiz.ldap.client; + +import iaik.asn1.ObjectID; +import iaik.asn1.structures.Name; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.log4j.Logger; + +/** + * @author Thomas Knall + */ +public final class LDAPClientFactoryImpl extends LDAPClientFactory { + + private final Logger log = Logger.getLogger(getClass()); + + private Hashtable ldapClients; + + protected LDAPClientFactoryImpl() { + this.ldapClients = new Hashtable(); + } + + public static String rfc2253Name2Domain(Name name) { + Object[] values = name.getRDNValues(ObjectID.domainComponent); + if (values == null) { + return null; + } + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < values.length; i++) { + buffer.append(values[i]); + if (i+1 < values.length) { + buffer.append("."); + } + } + return buffer.toString(); + } + + public static String rfc2253Name2Domain(String nameString) throws RFC2253NameParserException { + RFC2253NameParser nameParser = new RFC2253NameParser(nameString); + return rfc2253Name2Domain(nameParser.parse()); + } + + private List instantiateLDAPClients(String issuerName) throws LDAPException { + if (!super.hasBeenConfigured()) { + log.warn(super.getClass().getName() + " has not been configured yet."); + } + List ldapClients = new ArrayList(); + List mappings = super.getMappings(issuerName); + if (mappings == null || mappings.isEmpty()) { + try { + String alternativeURLString = rfc2253Name2Domain(issuerName); + if (alternativeURLString == null || alternativeURLString.length() == 0) { + throw new LDAPException("Neither issuer name \"" + issuerName + "\" has been registered nor domain components were provided."); + } + alternativeURLString = "ldap://" + alternativeURLString; + log.warn("Issuer name \"" + issuerName + "\" has not been registered; trying to instantiate client for url \"" + alternativeURLString + "\"..."); + LDAPClient client = new LDAPClientImpl(alternativeURLString); + ldapClients.add(client); + } catch (RFC2253NameParserException e) { + throw new LDAPException(e); + } + } else { + log.debug("Instantiating LDAP clients for " + ArrayUtils.toString(mappings.toArray()) + "."); + Iterator mappingIt = mappings.iterator(); + while (mappingIt.hasNext()) { + LDAPMapping mapping = (LDAPMapping) mappingIt.next(); + ldapClients.add(new LDAPClientImpl(mapping)); + } + } + return ldapClients; + } + + public synchronized List createClients(String issuerName) throws LDAPException { + if (issuerName == null) { + throw new NullPointerException("Issuer name must not be null."); + } + if (issuerName.length() == 0) { + throw new IllegalArgumentException("Issuer name must not be empty."); + } + List ldapClientList = (List) ldapClients.get(issuerName); + if (ldapClientList == null) { + ldapClientList = instantiateLDAPClients(issuerName); + ldapClients.put(issuerName, ldapClientList); + } + return Collections.unmodifiableList(ldapClientList); + } + +} -- cgit v1.2.3