aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2006-12-13 10:31:02 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2006-12-13 10:31:02 +0000
commitc9f44ea347a9d7a1c1372693bffcfa3901c48dc4 (patch)
treeca53d9f2bc3cd5fa12cfeff86060912b29debb79 /src/main/java/at/knowcenter/wag/egov/egiz/ldap/api
parent5831b59334060bd49739c1c49365da16cff49c96 (diff)
downloadpdf-as-3-c9f44ea347a9d7a1c1372693bffcfa3901c48dc4.tar.gz
pdf-as-3-c9f44ea347a9d7a1c1372693bffcfa3901c48dc4.tar.bz2
pdf-as-3-c9f44ea347a9d7a1c1372693bffcfa3901c48dc4.zip
LDAP support added
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@17 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/ldap/api')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIException.java55
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactory.java30
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactoryImpl.java62
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java106
4 files changed, 253 insertions, 0 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIException.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIException.java
new file mode 100644
index 0000000..4f2e363
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIException.java
@@ -0,0 +1,55 @@
+package at.knowcenter.wag.egov.egiz.ldap.api;
+
+/**
+ * @author <a href="mailto:thomas.knall@iaik.tugraz.at">Thomas Knall</a>
+ */
+public class LDAPAPIException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private Exception exception;
+
+ public Exception getException() {
+ return this.exception;
+ }
+
+ public String getMessage() {
+ String message = super.getMessage();
+ if (message == null && exception != null) {
+ return exception.getMessage();
+ } else {
+ return message;
+ }
+ }
+
+ public LDAPAPIException(String message, Exception exception) {
+ super(message);
+ this.exception = exception;
+ }
+
+ public LDAPAPIException(String message) {
+ super(message);
+ this.exception = null;
+ }
+
+ public LDAPAPIException(Exception exception) {
+ super();
+ this.exception = exception;
+ }
+
+ public LDAPAPIException() {
+ super();
+ this.exception = null;
+
+ }
+
+ @Override
+ public String toString() {
+ if (exception != null) {
+ return exception.toString();
+ } else {
+ return super.toString();
+ }
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactory.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactory.java
new file mode 100644
index 0000000..ba58908
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactory.java
@@ -0,0 +1,30 @@
+package at.knowcenter.wag.egov.egiz.ldap.api;
+
+import iaik.security.ecc.provider.ECCProvider;
+import at.knowcenter.wag.egov.egiz.sig.LDAPAPI;
+
+/**
+ * @author <a href="mailto:thomas.knall@iaik.tugraz.at">Thomas Knall</a>
+ */
+public abstract class LDAPAPIFactory {
+
+ private static LDAPAPIFactory ldapAPIfactoryInstance;
+
+ protected LDAPAPIFactory() {
+ ECCProvider.addAsProvider();
+ }
+
+ public static synchronized LDAPAPIFactory getInstance() {
+ if (ldapAPIfactoryInstance == null) {
+ ldapAPIfactoryInstance = new LDAPAPIFactoryImpl();
+ }
+ return ldapAPIfactoryInstance;
+ }
+
+ public synchronized LDAPAPI createLDAPAPI() throws LDAPAPIException {
+ return createLDAPAPI(null);
+ }
+
+ public abstract LDAPAPI createLDAPAPI(String implClassURI) throws LDAPAPIException;
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactoryImpl.java b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactoryImpl.java
new file mode 100644
index 0000000..340b54a
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIFactoryImpl.java
@@ -0,0 +1,62 @@
+package at.knowcenter.wag.egov.egiz.ldap.api;
+
+import java.util.Hashtable;
+
+import org.apache.log4j.Logger;
+
+import at.knowcenter.wag.egov.egiz.sig.LDAPAPI;
+
+/**
+ * @author <a href="mailto:thomas.knall@iaik.tugraz.at">Thomas Knall</a>
+ */
+public class LDAPAPIFactoryImpl extends LDAPAPIFactory {
+
+ private static final Logger log = Logger.getLogger(LDAPAPIFactoryImpl.class);
+
+ private Hashtable<String, LDAPAPI> ldapImpls;
+
+ protected LDAPAPIFactoryImpl() {
+ ldapImpls = new Hashtable<String, LDAPAPI>();
+ }
+
+ private static LDAPAPI instantiatelAPIImpl(String implClassURI) throws LDAPAPIException {
+ if (implClassURI == null) {
+ throw new NullPointerException("URI of implementing class must not be null.");
+ }
+ if (implClassURI.length() == 0) {
+ throw new IllegalArgumentException("URI of implementing class must not be empty.");
+ }
+ log.info("Trying to instantiate \"" + LDAPAPI.class.getName() + "\" implementation \"" + implClassURI + "\"...");
+ LDAPAPI ldapAPIImpl = null;
+ try {
+ Class clazz = Class.forName(implClassURI);
+ Object ldapAPIImplObj = clazz.newInstance();
+ if (!(ldapAPIImplObj instanceof LDAPAPI)) {
+ throw new LDAPAPIException("Declared class does not implement \"" + LDAPAPI.class.getName() + "\".");
+ }
+ ldapAPIImpl = (LDAPAPI) ldapAPIImplObj;
+ log.info("LDAPAPI implementation successfully instantiated.");
+ } catch (InstantiationException e) {
+ throw new LDAPAPIException("Declared implementation of \"" + LDAPAPI.class.getName() + "\" cannot be instantiated.");
+ } catch (IllegalAccessException e) {
+ throw new LDAPAPIException("Declared implementation of \"" + LDAPAPI.class.getName() + "\" cannot be instantiated (illegal access).");
+ } catch (ClassNotFoundException e) {
+ throw new LDAPAPIException("Unable to find class \"" + implClassURI + "\" as implementation of \"" + LDAPAPI.class.getName() + "\".");
+ }
+ return ldapAPIImpl;
+ }
+
+ public synchronized LDAPAPI createLDAPAPI(String implClassURI) throws LDAPAPIException {
+ if (implClassURI == null || implClassURI.length() == 0) {
+ // use internal implementation
+ implClassURI = LDAPAPIImpl.class.getName();
+ }
+ LDAPAPI impl = ldapImpls.get(implClassURI);
+ if (impl == null) {
+ impl = instantiatelAPIImpl(implClassURI);
+ ldapImpls.put(implClassURI, impl);
+ }
+ return impl;
+ }
+
+}
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
new file mode 100644
index 0000000..96409f6
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/ldap/api/LDAPAPIImpl.java
@@ -0,0 +1,106 @@
+package at.knowcenter.wag.egov.egiz.ldap.api;
+
+import iaik.utils.Util;
+import iaik.x509.X509Certificate;
+
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.ldap.client.LDAPClient;
+import at.knowcenter.wag.egov.egiz.ldap.client.LDAPClientFactory;
+import at.knowcenter.wag.egov.egiz.ldap.client.LDAPException;
+import at.knowcenter.wag.egov.egiz.ldap.client.LDAPMapping;
+import at.knowcenter.wag.egov.egiz.sig.LDAPAPI;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.tools.Normalizer;
+
+/**
+ * @author <a href="mailto:thomas.knall@iaik.tugraz.at">Thomas Knall</a>
+ */
+public class LDAPAPIImpl implements LDAPAPI {
+
+ private final Logger log = Logger.getLogger(getClass());
+
+ /**
+ * Prefix for specific entry in config properties file.
+ */
+ private static final String PROP_LDAP_PREFIX = "ldap_mapping";
+ private static final String PROP_ISSUER_NAME_POSTFIX = "issuer_name";
+ private static final String PROP_LDAP_URL_POSTFIX = "url";
+ private static final String PROP_SERIAL_ATTR_POSTFIX = "serial_attr";
+
+ private static final String LDAP_FACTORY_IDENTIFIER = "PDF-AS LDAP Support";
+ private LDAPClientFactory ldapClientFactory;
+
+ protected LDAPAPIImpl() {
+ try {
+ SettingsReader settings = SettingsReader.getInstance();
+
+ ldapClientFactory = LDAPClientFactory.getInstance(LDAP_FACTORY_IDENTIFIER);
+ // configure normalization of issuer according to method
+ // normalizeIssuer(String) of at.knowcenter.wag.egov.egiz.sig.SignatureObject
+ ldapClientFactory.setWhiteSpaceRemoval(true);
+ ldapClientFactory.setNormalizer(new Normalizer().getInstance());
+
+ List mappingKeys = settings.getKeys(PROP_LDAP_PREFIX);
+ if (mappingKeys != null) {
+ Iterator it = mappingKeys.iterator();
+ while (it.hasNext()) {
+ String keyPrefix = PROP_LDAP_PREFIX + "." + (String) it.next() + ".";
+ String issuerName = settings.getSetting(keyPrefix + PROP_ISSUER_NAME_POSTFIX);
+ String ldapURL = settings.getSetting(keyPrefix + PROP_LDAP_URL_POSTFIX);
+ String serialAttr = settings.getSetting(keyPrefix + PROP_SERIAL_ATTR_POSTFIX, null);
+
+ LDAPMapping ldapMapping = new LDAPMapping(issuerName, ldapURL, serialAttr);
+ ldapClientFactory.registerMapping(ldapMapping);
+ }
+ } else {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(PROP_LDAP_PREFIX).append(".foo.").append(PROP_ISSUER_NAME_POSTFIX).append(", ");
+ buffer.append(PROP_LDAP_PREFIX).append(".foo.").append(PROP_LDAP_URL_POSTFIX).append(", ");
+ buffer.append(PROP_LDAP_PREFIX).append(".foo.").append(PROP_SERIAL_ATTR_POSTFIX);
+ log.warn("There are no LDAP mappings (" + buffer.toString() + ") declared within config file.");
+ }
+
+ } catch (SettingsException e) {
+ log.error(e);
+ } catch (SettingNotFoundException e) {
+ log.error(e);
+ } catch (LDAPException e) {
+ log.error(e);
+ } catch (NormalizeException e) {
+ log.error(e);
+ };
+ }
+
+ public String getURL(String issuer) {
+ String url = null;
+ try {
+ LDAPClient client = ldapClientFactory.createClient(issuer);
+ url = client.getUrl().toString();
+ } catch (LDAPException e) {
+ log.error(e);
+ }
+ return url;
+ }
+
+ public byte[] loadBase64CertificateFromLDAP(String serialNumber, String issuer) {
+ byte[] base64CertData = null;
+ try {
+ LDAPClient client = ldapClientFactory.createClient(issuer);
+ X509Certificate x509certificate = client.retrieveCertificate(new BigInteger(serialNumber));
+ base64CertData = Util.Base64Encode(x509certificate.toByteArray());
+ } catch (LDAPException e) {
+ log.error(e);
+ }
+ return base64CertData;
+ }
+
+}