aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-12-04 19:16:33 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-12-04 19:16:33 +0000
commite452213b7bb66956522cf74fbd255f8970678525 (patch)
treec3c17dc300603713d27548bd495fd73545d2fdb4 /src/main/java/at
parent4dc9bbe2a31599cd853a3dea2f2876d0fd05d73c (diff)
downloadpdf-as-3-e452213b7bb66956522cf74fbd255f8970678525.tar.gz
pdf-as-3-e452213b7bb66956522cf74fbd255f8970678525.tar.bz2
pdf-as-3-e452213b7bb66956522cf74fbd255f8970678525.zip
LDAP implementation enhanced.
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@316 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java25
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactory.java23
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java39
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java3
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPMappingStore.java33
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/LDAPAPI.java7
6 files changed, 59 insertions, 71 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java
index 1409ae8..4099297 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java
@@ -91,24 +91,21 @@ public class LDAPAPIImpl implements LDAPAPI {
}
}
- public String getURL(String issuer) {
- this.initializeFactoryImpl();
- String url = null;
- try {
- LDAPClient client = this.ldapClientFactory.createClient(issuer);
- url = client.getUrl().toString();
- } catch (LDAPException e) {
- this.log.error(e.getMessage(), e);
- }
- return url;
- }
-
public byte[] loadBase64CertificateFromLDAP(String serialNumber, String issuer) {
this.initializeFactoryImpl();
byte[] base64CertData = null;
try {
- LDAPClient client = this.ldapClientFactory.createClient(issuer);
- X509Certificate x509certificate = client.retrieveCertificate(new BigInteger(serialNumber));
+ List clients = this.ldapClientFactory.createClients(issuer);
+ Iterator clientIt = clients.iterator();
+ X509Certificate x509certificate = null;
+ while (clientIt.hasNext() && x509certificate == null) {
+ LDAPClient client = (LDAPClient) clientIt.next();
+ try {
+ x509certificate = client.retrieveCertificate(new BigInteger(serialNumber));
+ } catch (LDAPException e) {
+ this.log.error(e.getMessage(), e);
+ }
+ }
if (x509certificate != null) {
base64CertData = Util.Base64Encode(x509certificate.toByteArray());
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactory.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactory.java
index 7cd98c6..1aa7ff1 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactory.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactory.java
@@ -3,6 +3,7 @@ package at.knowcenter.wag.egov.egiz.ldap.client;
import iaik.asn1.structures.Name;
import java.util.Hashtable;
+import java.util.List;
import org.apache.log4j.Logger;
@@ -29,12 +30,12 @@ public abstract class LDAPClientFactory {
this.ldapMappingStore = new LDAPMappingStore();
}
- public LDAPMapping getMapping(String issuerName) throws LDAPException {
- return this.ldapMappingStore.getMapping(issuerName);
+ public List getMappings(String issuerName) throws LDAPException {
+ return this.ldapMappingStore.getMappings(issuerName);
}
- public LDAPMapping getMapping(Name name) {
- return this.ldapMappingStore.getMapping(name);
+ public List getMapping(Name name) {
+ return this.ldapMappingStore.getMappings(name);
}
public void resetMappings() {
@@ -45,16 +46,8 @@ public abstract class LDAPClientFactory {
return !this.ldapMappingStore.isEmpty();
}
-// public synchronized void registerMappings(Iterable<LDAPMapping> iterable) {
-// public synchronized void registerMappings(Iterable iterable) {
-// if (!iterable.iterator().hasNext()) {
-// log.warn("There were no ldap mappings provided.");
-// }
-// this.ldapMappingStore.storeMappings(iterable);
-// }
-
public synchronized void registerMapping(LDAPMapping ldapMapping) {
- this.ldapMappingStore.storeMapping(ldapMapping);
+ this.ldapMappingStore.addMapping(ldapMapping);
}
public void setLDAPIssuerNameFilter(LDAPIssuerNameFilter filter) throws LDAPException {
@@ -67,7 +60,7 @@ public abstract class LDAPClientFactory {
public boolean isLDAPIssuerNameFilter() {
return this.ldapMappingStore.isLDAPIssuerNameFilter();
}
-
+
public static synchronized LDAPClientFactory getInstance(String idenfifier) {
LDAPClientFactory ldapClientFactoryInstance = (LDAPClientFactory) ldapClientFactoryInstances.get(idenfifier);
if (ldapClientFactoryInstance == null) {
@@ -81,6 +74,6 @@ public abstract class LDAPClientFactory {
return getInstance(DEFAULT_IDENTIFIER);
}
- public abstract LDAPClient createClient(String issuerName) throws LDAPException;
+ public abstract List createClients(String issuerName) throws LDAPException;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java
index 1390202..ec5548b 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientFactoryImpl.java
@@ -5,8 +5,13 @@ 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;
/**
@@ -16,7 +21,6 @@ public final class LDAPClientFactoryImpl extends LDAPClientFactory {
private final Logger log = Logger.getLogger(getClass());
-// private Hashtable<String, LDAPClient> ldapClients;
private Hashtable ldapClients;
protected LDAPClientFactoryImpl() {
@@ -43,13 +47,13 @@ public final class LDAPClientFactoryImpl extends LDAPClientFactory {
return rfc2253Name2Domain(nameParser.parse());
}
- private LDAPClient instantiateLDAPClient(String issuerName) throws LDAPException {
+ private List instantiateLDAPClients(String issuerName) throws LDAPException {
if (!super.hasBeenConfigured()) {
log.warn(super.getClass().getName() + " has not been configured yet.");
}
- LDAPClient client = null;
- LDAPMapping mapping = super.getMapping(issuerName);
- if (mapping == null) {
+ 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) {
@@ -57,30 +61,35 @@ public final class LDAPClientFactoryImpl extends LDAPClientFactory {
}
alternativeURLString = "ldap://" + alternativeURLString;
log.warn("Issuer name \"" + issuerName + "\" has not been registered; trying to instantiate client for url \"" + alternativeURLString + "\"...");
- client = new LDAPClientImpl(alternativeURLString);
+ LDAPClient client = new LDAPClientImpl(alternativeURLString);
+ ldapClients.add(client);
} catch (RFC2253NameParserException e) {
throw new LDAPException(e);
}
} else {
- log.debug("Instantiating LDAP client for " + mapping + ".");
- client = new LDAPClientImpl(mapping);
+ 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 client;
+ return ldapClients;
}
- public synchronized LDAPClient createClient(String issuerName) throws LDAPException {
+ 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.");
}
- LDAPClient ldapClient = (LDAPClient) ldapClients.get(issuerName);
- if (ldapClient == null) {
- ldapClient = instantiateLDAPClient(issuerName);
- ldapClients.put(issuerName, ldapClient);
+ List ldapClientList = (List) ldapClients.get(issuerName);
+ if (ldapClientList == null) {
+ ldapClientList = instantiateLDAPClients(issuerName);
+ ldapClients.put(issuerName, ldapClientList);
}
- return ldapClient;
+ return Collections.unmodifiableList(ldapClientList);
}
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
index 2794c99..c5e2ad2 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
@@ -139,8 +139,9 @@ public final class LDAPClientImpl implements LDAPClient {
);
// connect to the ldap server an read results
- log.debug("Connecting to \"" + this.url.toString() + "\"...");
+ log.debug("Connecting to \"" + this.url.toString() + "\".");
certs = (X509Certificate[]) ldapURLConnection.getContent();
+ log.debug("Result of LDAP query received (" + (certs != null ? certs.length : 0) + " result(s)).");
} catch (IOException e) {
this.timeStampForBlackList = System.currentTimeMillis();
log.warn("Unable to get certificate from \"" + this.getUrl().toString() + "\". LDAPClient is now blocking that URL for " + TIME_ON_BLACKLIST_IN_SECONDS + " seconds.");
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPMappingStore.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPMappingStore.java
index 4416649..b1074e7 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPMappingStore.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPMappingStore.java
@@ -4,8 +4,9 @@ import iaik.asn1.structures.Name;
import iaik.utils.RFC2253NameParser;
import iaik.utils.RFC2253NameParserException;
+import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.Iterator;
+import java.util.List;
import org.apache.log4j.Logger;
@@ -40,34 +41,28 @@ public class LDAPMappingStore {
return this.issuerNameFilter != null;
}
- public void storeMapping(LDAPMapping mapping) {
+ public void addMapping(LDAPMapping mapping) {
Name name = mapping.getIssuerName();
if (issuerNameFilter != null) {
name = this.issuerNameFilter.applyFilter(name);
}
- if (this.storedMappings.containsKey(name)) {
- log.warn("Skipping mapping \"" + mapping + "\" because is has already been stored under \"" + name.getName() + "\".");
- } else {
- log.debug("Storing mapping \"" + mapping + "\" under \"" + name.getName() + "\".");
- this.storedMappings.put(name, mapping);
- }
+ List mappingList = (List) this.storedMappings.get(name);
+ if (mappingList == null) {
+ mappingList = new ArrayList();
+ this.storedMappings.put(name, mappingList);
+ }
+ log.debug("Adding mapping \"" + mapping + "\" for \"" + name.getName() + "\".");
+ mappingList.add(mapping);
}
-// public void storeMappings(Iterable iterable) {
-// Iterator it = iterable.iterator();
-// while (it.hasNext()) {
-// this.storeMapping((LDAPMapping) it.next());
-// }
-// }
-
- public LDAPMapping getMapping(Name name) {
+ public List getMappings(Name name) {
if (issuerNameFilter != null) {
name = this.issuerNameFilter.applyFilter(name);
}
- return (LDAPMapping) this.storedMappings.get(name);
+ return (List) this.storedMappings.get(name);
}
- public LDAPMapping getMapping(String nameString) throws LDAPException {
+ public List getMappings(String nameString) throws LDAPException {
RFC2253NameParser parser = new RFC2253NameParser(nameString);
Name name;
try {
@@ -78,7 +73,7 @@ public class LDAPMappingStore {
if (issuerNameFilter != null) {
name = this.issuerNameFilter.applyFilter(name);
}
- return getMapping(name);
+ return this.getMappings(name);
}
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/LDAPAPI.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/LDAPAPI.java
index f61c7e6..6101632 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/LDAPAPI.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/LDAPAPI.java
@@ -11,13 +11,6 @@ public interface LDAPAPI {
public static final String SYS_PROP_IMPLEMENTATION = "pdfas.ldapapi.impl";
/**
- * Returns the url of the ldap server.
- * @param issuer The issuer name.
- * @return The ldap url.
- */
- public String getURL(String issuer);
-
- /**
* Retrieves an certificate from the ldap server identified by serial number and issuer name.
* @param serialNumber The serial number.
* @param issuer The issuer name.