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) --- src/main/java/com/c2kernel/lookup/Path.java | 87 +++-------------------------- 1 file changed, 9 insertions(+), 78 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/Path.java') diff --git a/src/main/java/com/c2kernel/lookup/Path.java b/src/main/java/com/c2kernel/lookup/Path.java index 16f3e5d..f9fd15d 100644 --- a/src/main/java/com/c2kernel/lookup/Path.java +++ b/src/main/java/com/c2kernel/lookup/Path.java @@ -12,15 +12,11 @@ package com.c2kernel.lookup; import java.io.Serializable; import java.util.ArrayList; -import java.util.Enumeration; +import java.util.Iterator; import java.util.StringTokenizer; -import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.Gateway; -import com.novell.ldap.LDAPAttributeSet; -import com.novell.ldap.LDAPConnection; -import com.novell.ldap.LDAPSearchConstraints; /** @@ -45,19 +41,11 @@ public abstract class Path implements Serializable protected String mStringPath = null; // entity or context protected short mType = CONTEXT; - // LDAP dn - protected String mDN = null; // int syskey (only valid for entity SystemPaths) protected int mSysKey = INVALID; // ior is stored in here when it is resolved protected org.omg.CORBA.Object mIOR = null; - // - // needed for unusual subclass constructors - - protected static String mGlobalPath; //cern.ch - protected static String mRootPath; //cristal2 - protected static String mLocalPath; //lab27 public Path() { } @@ -114,7 +102,6 @@ public abstract class Path implements Serializable public void setPath(String[] path) { mStringPath = null; - mDN = null; mPath = path.clone(); mSysKey = INVALID; } @@ -136,7 +123,6 @@ public abstract class Path implements Serializable mPath = (newPath.toArray(mPath)); mStringPath = null; - mDN = null; mSysKey = INVALID; } @@ -152,40 +138,10 @@ public abstract class Path implements Serializable public void setPath(Path path) { mStringPath = null; - mDN = null; mPath = (path.getPath().clone()); mSysKey = INVALID; } - /* LDAP dn e.g. cn=6L,cn=Barrel,cn=Crystal,cn=Product,cn=domain, - * system/domain node PRESENT - * trailing comma - */ - public void setDN(String dn) - { - // strip off root path components - String root = "cn="+getRoot()+","; - if (dn.endsWith(mLocalPath)) - dn = dn.substring(0, dn.lastIndexOf(mLocalPath)); - - if (dn.endsWith(root)) - dn = dn.substring(0, dn.lastIndexOf(root)); - - ArrayList newPath = new ArrayList(); - StringTokenizer tok = new StringTokenizer(dn, ","); - while (tok.hasMoreTokens()) { - String nextPath = tok.nextToken(); - if (nextPath.indexOf("cn=") == 0) - newPath.add(0, LDAPLookupUtils.unescapeDN(nextPath.substring(3))); - else - break; - } - mPath = (newPath.toArray(mPath)); - mSysKey = INVALID; - mStringPath = null; - mDN = dn+root; - } - /*************************************************************************/ @@ -212,23 +168,8 @@ public abstract class Path implements Serializable return mStringPath; } - public String getDN() { - if (mDN == null) { - StringBuffer dnBuffer = new StringBuffer(); - for (int i=mPath.length-1; i>=0; i--) - dnBuffer.append("cn=").append(LDAPLookupUtils.escapeDN(mPath[i])).append(","); - dnBuffer.append("cn="+getRoot()+","); - mDN = dnBuffer.toString(); - } - return mDN; - } - - public String getFullDN() { - return getDN()+mLocalPath; - } - public boolean exists() { - return Gateway.getLDAPLookup().exists(this); + return Gateway.getLookup().exists(this); } /** Queries the lookup for the IOR @@ -237,9 +178,9 @@ public abstract class Path implements Serializable public org.omg.CORBA.Object getIOR() { org.omg.CORBA.Object newIOR = null; if (mIOR==null) { // if not cached try to resolve - LDAPLookup myLookup = Gateway.getLDAPLookup(); + Lookup myLookup = Gateway.getLookup(); try { - newIOR = myLookup.getIOR(this); + newIOR = myLookup.resolve(this); } catch (ObjectNotFoundException ex) { } setIOR(newIOR); @@ -260,19 +201,11 @@ public abstract class Path implements Serializable return mSysKey; } - public Enumeration getChildren() { - String filter = "objectclass=*"; - LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); - searchCons.setBatchSize(10); - searchCons.setDereference(LDAPSearchConstraints.DEREF_FINDING ); - return Gateway.getLDAPLookup().search(getFullDN(), LDAPConnection.SCOPE_ONE,filter,searchCons); - } - public Path find(String name) throws ObjectNotFoundException { - Enumeration e = Gateway.getLDAPLookup().search(this, name); - if (e.hasMoreElements()) { - Path thisPath = e.nextElement(); - if (e.hasMoreElements()) + Iterator e = Gateway.getLookup().search(this, name); + if (e.hasNext()) { + Path thisPath = e.next(); + if (e.hasNext()) throw new ObjectNotFoundException("More than one match for "+name, ""); return thisPath; } @@ -281,8 +214,6 @@ public abstract class Path implements Serializable public abstract ItemPath getEntity() throws ObjectNotFoundException; - public abstract LDAPAttributeSet createAttributeSet() throws ObjectCannotBeUpdated; - @Override public boolean equals( Object path ) { @@ -298,7 +229,7 @@ public abstract class Path implements Serializable StringBuffer comp = new StringBuffer("Components: { "); for (String element : mPath) comp.append("'").append(element).append("' "); - return "Path - dump(): "+comp.toString()+"}\n dn="+getDN()+"\n string="+toString()+"\n int="+getSysKey()+"\n type="+mType; + return "Path - dump(): "+comp.toString()+"}\n string="+toString()+"\n int="+getSysKey()+"\n type="+mType; } } -- cgit v1.2.3