diff options
Diffstat (limited to 'src/main/java/com/c2kernel/lookup')
3 files changed, 38 insertions, 100 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/LDAPLookup.java index 996ca0e..23d30d4 100644 --- a/src/main/java/com/c2kernel/lookup/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/LDAPLookup.java @@ -45,7 +45,7 @@ public class LDAPLookup private LDAPConnection mLDAPConn;
private final LDAPProperties mLDAPProps;
private final NextKeyManager mNextKeyManager;
- private LDAPPropertyManager mPropManager;
+ private final LDAPPropertyManager mPropManager;
private final LDAPRoleManager mRoleManager;
@@ -73,14 +73,7 @@ public class LDAPLookup mNextKeyManager = new NextKeyManager(this, "cn=last,"+EntityPath.mTypeRoot);
Logger.msg(7, "LDAP.useOldProps="+Gateway.getProperty("LDAP.useOldProps", "false"));
- if (Gateway.getProperty("LDAP.useOldProps", "false").equals("true")) {
- Logger.debug(1, "Using Kernel 2.1 LDAP Property Format");
- mPropManager = new LegacyLDAPPropertyManager(this);
- }
- else {
- Logger.debug(1, "Using Kernel 2.2 LDAP Property Format");
- mPropManager = new LDAPPropertyManager(this);
- }
+ mPropManager = new LDAPPropertyManager(this);
mRoleManager = new LDAPRoleManager(this, "cn=agent,"+DomainPath.mTypeRoot, EntityPath.mTypeRoot);
}
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java index 57ed17d..fcf1ef8 100644 --- a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java +++ b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java @@ -51,7 +51,9 @@ public class LDAPPropertyManager { LDAPAttribute props = entityEntry.getAttribute("cristalprop");
for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
String thisProp = (String)e.nextElement();
- propbag.add(thisProp.substring(0, thisProp.indexOf(':')));
+ String thisName = thisProp.substring(0, thisProp.indexOf(':'));
+ if (thisName.startsWith("!") && thisName.length()>1) thisName = thisName.substring(1);
+ propbag.add(thisName);
}
String[] retArr = new String[props.size()];
@@ -61,12 +63,12 @@ public class LDAPPropertyManager { /**
* @param thisEntity - EntityPath of the subject entity
* @param propName - the name of the property to retrieve
- * @return String the property value
+ * @return The Property object
* @throws ObjectNotFoundException
*/
- public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
+ public Property getProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return getPropertyAttr(entityEntry, name);
+ return getProperty(entityEntry, name);
}
/**
@@ -77,9 +79,13 @@ public class LDAPPropertyManager { */
public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- String propVal = getPropertyAttr(entityEntry, name);
+ Property prop = getProperty(entityEntry, name);
Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", name+":"+propVal);
+ LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
+ }
+
+ private static String getPropertyAttrValue(Property prop) {
+ return (prop.isMutable()?"":"!")+prop.getName()+":"+prop.getValue();
}
/**
@@ -91,28 +97,42 @@ public class LDAPPropertyManager { public void setProperty(EntityPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
try {
- String propVal = getPropertyAttr(entityEntry, prop.getName());
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+propVal+"'");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+propVal);
+ Property oldProp = getProperty(entityEntry, prop.getName());
+ Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+oldProp.getValue()+"'");
+ LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(oldProp));
} catch (ObjectNotFoundException ex) {
Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - creating new property.");
}
Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - setting to '"+prop.getValue()+"'");
- LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+prop.getValue());
+ LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
}
- private static String getPropertyAttr(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
+ public static Property getProperty(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
// delete existing props
LDAPAttribute props = myEntry.getAttribute("cristalprop");
if (props == null)
throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
String propPrefix = propName+":";
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String val = (String)e.nextElement();
- if (val.toLowerCase().startsWith(propPrefix.toLowerCase()))
- return val.substring(propPrefix.length());
+ String roPropPrefix = "!"+propPrefix;
+ String val = null, name = null; boolean mutable = false;
+ for (Enumeration<?> e = props.getStringValues(); name==null && e.hasMoreElements();) {
+ String attrVal = (String)e.nextElement();
+ if (attrVal.toLowerCase().startsWith(propPrefix.toLowerCase())) {
+ name = attrVal.substring(0, propPrefix.length()-1);
+ val = attrVal.substring(propPrefix.length());
+ mutable = true; break;
+ }
+
+ if (attrVal.toLowerCase().startsWith(roPropPrefix.toLowerCase())) {
+ name = attrVal.substring(1, roPropPrefix.length()-1);
+ val = attrVal.substring(roPropPrefix.length());
+ mutable = false; break;
+ }
}
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
+ if (name == null)
+ throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
+ Logger.msg(6, "Loaded "+(mutable?"":"Non-")+"Mutable Property: "+name+"="+val);
+ return new Property(name, val, mutable);
}
}
diff --git a/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java deleted file mode 100644 index 638c694..0000000 --- a/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.c2kernel.lookup;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPAttributeSet;
-import com.novell.ldap.LDAPDN;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-
-public class LegacyLDAPPropertyManager extends LDAPPropertyManager {
-
- public LegacyLDAPPropertyManager(LDAPLookup ldap) {
- super(ldap);
- }
-
- @Override
- public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- try {
- LDAPLookupUtils.delete(ldap.getConnection(), "cn="+name+","+thisEntity.getFullDN());
- } catch (LDAPException ex) {
- Logger.error("Error deleting prop "+name+" from "+thisEntity.getSysKey());
- Logger.error(ex);
- }
- }
-
- @Override
- public String[] getPropertyNames(EntityPath thisEntity) throws ObjectNotFoundException {
- String props[]= LDAPLookupUtils.getChildrenDNs(ldap.getConnection(), thisEntity.getFullDN(), "objectclass=cristalproperty");
- String names[] = new String[props.length];
- for (int i=0; i<props.length;i++)
- names[i] = new String(LDAPDN.explodeDN(props[i],true)[0]);
- return names;
- }
-
- @Override
- public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
- LDAPEntry anEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),"cn="+name+","+thisEntity.getFullDN());
- if (anEntry==null)
- throw new ObjectNotFoundException("LDAPLookup: Property "+name+" not found in "+thisEntity.getSysKey(), "");
- return LDAPLookupUtils.getFirstAttributeValue(anEntry,"propval");
- }
-
- @Override
- public boolean hasProperties(EntityPath thisEntity) throws ObjectNotFoundException {
- return LDAPLookupUtils.hasChildren(ldap.getConnection(), thisEntity.getFullDN(), "objectclass=cristalproperty" );
- }
-
- @Override
- public void setProperty(EntityPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- try {
- LDAPEntry anEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),"cn="+prop.getName()+","+thisEntity.getFullDN());
- String currentVal = LDAPLookupUtils.getFirstAttributeValue(anEntry,"propval");
- if (currentVal == null || !currentVal.equals(prop.getValue()) )
- //change the propvalue if the prop.getValue() is not the same value in LDAP
- LDAPLookupUtils.setAttributeValue(ldap.getConnection(), anEntry,"propval",prop.getValue());
-
- } catch (ObjectNotFoundException ex) {
- LDAPAttributeSet attrSet = new LDAPAttributeSet();
- attrSet.add(new LDAPAttribute("objectclass","cristalproperty"));
- attrSet.add(new LDAPAttribute("cn",prop.getName()));
- if (prop.getValue()!=null && prop.getValue().length()!=0)
- attrSet.add(new LDAPAttribute("propval",prop.getValue()));
- LDAPEntry newEntry = new LDAPEntry("cn="+prop.getName()+","+thisEntity.getFullDN(),attrSet);
- try {
- LDAPLookupUtils.addEntry(ldap.getConnection(),newEntry);
- } catch (Exception e) {
- Logger.error(e);
- throw new ObjectCannotBeUpdated(e.getMessage(), "");
- }
- }
- }
-}
|
