From d4fa3bd9dd48f4d5e26850a23f5ba48a9c10ad64 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 5 Jun 2014 15:02:07 +0200 Subject: LDAP refactored behind interfaces. All functions of LDAP now hidden behind interfaces: Authenticator, Lookup and NextKeyManager (LDAP property storage was already a ClusterStorage). Gateway holds additional objects, and Fixes #26 #191. Refs #27 (needs additional work for read perms and auth tokens) --- .../java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java') diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java new file mode 100644 index 0000000..806976d --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java @@ -0,0 +1,81 @@ +package com.c2kernel.lookup.ldap; + +import java.util.Iterator; + +import com.c2kernel.lookup.Path; +import com.c2kernel.utils.Logger; +import com.novell.ldap.LDAPEntry; +import com.novell.ldap.LDAPException; +import com.novell.ldap.LDAPSearchResults; + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 2005/12/01 14:23:14 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + + + +public class LDAPPathSet implements Iterator { + LDAPSearchResults results; + LDAPEntry nextEntry; + LDAPLookup ldap; + + public LDAPPathSet(LDAPLookup ldap) { // empty + this.ldap = ldap; + results = null; + } + + public LDAPPathSet(LDAPSearchResults results, LDAPLookup ldap) { + this.ldap = ldap; + this.results = results; + } + + @Override + public boolean hasNext() { + if (results == null) return false; + if (nextEntry != null) return true; + if (results.hasMore()) + try { + nextEntry = results.next(); + return true; + } catch (LDAPException ex) { + if (ex.getResultCode()!=32) {// no results + Logger.error(ex); + Logger.error("Error loading LDAP result set: "+ex.getMessage()); + } + } + return false; + } + + @Override + public Path next() { + if (results == null) return null; + try { + if (nextEntry == null) + nextEntry = results.next(); + Path nextPath = ldap.nodeToPath(nextEntry); + nextEntry = null; + return nextPath; + } catch (Exception ex) { + Logger.error("Error loading next path"); + Logger.error(ex); + nextEntry = null; + if (hasNext()) { + Logger.error("Skipping to next entry"); + return next(); + } + else + return null; + } + } + + @Override + public void remove() { + // do nothing + + } +} -- cgit v1.2.3