aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-01-09 12:15:13 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-01-09 12:15:13 +0000
commit35963f5cb727db6b77962a0c58380b73c4e9d952 (patch)
tree72df7858fcf71a093a6a5a09c8f4d51b400a06b2 /src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
parentae74d148749f8458e825083550c3fc8ed8a201da (diff)
downloadpdf-as-3-35963f5cb727db6b77962a0c58380b73c4e9d952.tar.gz
pdf-as-3-35963f5cb727db6b77962a0c58380b73c4e9d952.tar.bz2
pdf-as-3-35963f5cb727db6b77962a0c58380b73c4e9d952.zip
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@24 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java175
1 files changed, 0 insertions, 175 deletions
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
deleted file mode 100644
index 3dae9ae..0000000
--- a/src/main/java/at/knowcenter/wag/egov/egiz/ldap/client/LDAPClientImpl.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package at.knowcenter.wag.egov.egiz.ldap.client;
-
-import iaik.x509.X509Certificate;
-import iaik.x509.net.ldap.LdapURLConnection;
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-public final class LDAPClientImpl implements LDAPClient {
-
- // constants
- protected static final String DEFAULT_LDAP_ATTR_SERIAL_NUMBER = "eidCertificateSerialNumber";
- private static final iaik.x509.net.ldap.Handler LDAP_HANDLER = new iaik.x509.net.ldap.Handler();
-
- // fields
- private URL url;
- private String serialNumberAttrName;
-
- // constructors
- protected LDAPClientImpl() {
- this.setSerialNumberAttrName(DEFAULT_LDAP_ATTR_SERIAL_NUMBER);
- }
-
- protected LDAPClientImpl(URL url) {
- this();
- this.setUrl(url);
- }
-
- protected LDAPClientImpl(String urlString) throws LDAPException {
- this();
- try {
- this.setUrl(new URL(null, urlString, LDAP_HANDLER));
- } catch (MalformedURLException e) {
- throw new LDAPException(e);
- }
- }
-
- protected LDAPClientImpl(LDAPMapping ldapMapping) {
- this();
- this.setUrl(ldapMapping.getLdapURL());
- this.setSerialNumberAttrName(ldapMapping.getSerialNumberAttrName());
- }
-
-
- // getter/setter
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#getUrl()
- */
- public URL getUrl() {
- return this.url;
- }
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#setUrl(java.net.URL)
- */
- public void setUrl(URL ldapURL) {
- if (ldapURL == null) {
- throw new NullPointerException("LDAP url must not be null.");
- }
- this.url = ldapURL;
- }
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#getSerialNumberAttrName()
- */
- public String getSerialNumberAttrName() {
- return this.serialNumberAttrName;
- }
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#setSerialNumberAttrName(java.lang.String)
- */
- public void setSerialNumberAttrName(String serialNumberAttrName) {
- if (serialNumberAttrName != null && serialNumberAttrName.length() == 0) {
- throw new IllegalArgumentException("Serial number attribute name must not be empty");
- }
- this.serialNumberAttrName = serialNumberAttrName != null ? serialNumberAttrName : DEFAULT_LDAP_ATTR_SERIAL_NUMBER;
- }
-
- // service methods
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#retrieveCertificates(java.lang.String)
- */
- public X509Certificate[] retrieveCertificates(String filter) throws LDAPException {
- if (filter == null) {
- throw new NullPointerException("Filter string must not be null.");
- }
- if (filter.length() == 0) {
- throw new IllegalArgumentException("Filter string must not be empty.");
- }
-
- X509Certificate[] certs = new X509Certificate[] { };
- LdapURLConnection ldapURLConnection = null;
- try {
- this.validateData();
- ldapURLConnection = (LdapURLConnection) this.url.openConnection();
-
- // search for end enity certificates
- ldapURLConnection.setRequestProperty(
- LdapURLConnection.RP_ATTRIBUTE_DESCRIPTION,
- LdapURLConnection.AD_USER_CERTIFICATE
- );
-
- // search subtree
- ldapURLConnection.setRequestProperty(
- LdapURLConnection.RP_SEARCH_SCOPE,
- LdapURLConnection.SEARCH_SCOPE_SUBTREE
- );
-
- //set filter
- ldapURLConnection.setRequestProperty(
- LdapURLConnection.RP_FILTER,
- filter
- );
-
- // connect to the ldap server an read results
- certs = (X509Certificate[]) ldapURLConnection.getContent();
- } catch (IOException e) {
- throw new LDAPException(e);
- } finally {
- if (ldapURLConnection != null) {
- ldapURLConnection.disconnect();
- }
- }
- return certs;
- }
-
- /*
- * @see at.iaik.commons.ldap.LDAPClient#retrieveCertificate(java.math.BigInteger)
- */
- public X509Certificate retrieveCertificate(BigInteger serialNumber) throws LDAPException {
- if (serialNumber == null) {
- throw new NullPointerException("Serial number must not be null");
- }
- this.validateData();
- X509Certificate[] certs = retrieveCertificates("(" + this.serialNumberAttrName + "=" + serialNumber + ")");
- if (certs.length > 1) {
- throw new LDAPException("There was more than one certificate with serial number " + serialNumber + ".");
- } else if (certs.length == 0) {
- return null;
- }
- return certs[0];
- }
-
- // misc
- public void validateData() throws LDAPException {
- if (this.url == null) {
- throw new LDAPException("LDAP URL must not be null.");
- }
- if (this.serialNumberAttrName == null || this.serialNumberAttrName.length() == 0) {
- throw new LDAPException("LDAP key for serial number is null or empty.");
- }
- }
-
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("ldapURL = ").append(this.url);
- buffer.append(", serialNumberAttrName = ").append(this.serialNumberAttrName);
- boolean dataValid;
- try {
- this.validateData();
- dataValid = true;
- } catch (LDAPException e) {
- dataValid = false;
- }
- buffer.append("; data seems to be ").append(dataValid ? "valid" : "invalid");
- return buffer.toString();
- }
-
-}