diff --git a/src/main/java/net/sourceforge/myvd/inserts/ldap/LDAPInterceptor.java b/src/main/java/net/sourceforge/myvd/inserts/ldap/LDAPInterceptor.java index 4a51720..7451531 100644 --- a/src/main/java/net/sourceforge/myvd/inserts/ldap/LDAPInterceptor.java +++ b/src/main/java/net/sourceforge/myvd/inserts/ldap/LDAPInterceptor.java @@ -415,6 +415,10 @@ public void search(SearchInterceptorChain chain, DistinguishedName base, if (remoteBase == null) { remoteBase = ""; } + + if (remoteBase.contains("\\+")) { + remoteBase = remoteBase.replace("\\+", "+"); + } if (this.usePaging) { if (constraints != null) { diff --git a/src/main/java/net/sourceforge/myvd/inserts/mapping/ClearMultiValueRDNEscapesFilter.java b/src/main/java/net/sourceforge/myvd/inserts/mapping/ClearMultiValueRDNEscapesFilter.java new file mode 100644 index 0000000..316669a --- /dev/null +++ b/src/main/java/net/sourceforge/myvd/inserts/mapping/ClearMultiValueRDNEscapesFilter.java @@ -0,0 +1,136 @@ +package net.sourceforge.myvd.inserts.mapping; + +import java.util.ArrayList; +import java.util.Properties; + +import com.novell.ldap.LDAPConstraints; +import com.novell.ldap.LDAPException; +import com.novell.ldap.LDAPModification; +import com.novell.ldap.LDAPSearchConstraints; + +import net.sourceforge.myvd.chain.AddInterceptorChain; +import net.sourceforge.myvd.chain.BindInterceptorChain; +import net.sourceforge.myvd.chain.CompareInterceptorChain; +import net.sourceforge.myvd.chain.DeleteInterceptorChain; +import net.sourceforge.myvd.chain.ExetendedOperationInterceptorChain; +import net.sourceforge.myvd.chain.ModifyInterceptorChain; +import net.sourceforge.myvd.chain.PostSearchCompleteInterceptorChain; +import net.sourceforge.myvd.chain.PostSearchEntryInterceptorChain; +import net.sourceforge.myvd.chain.RenameInterceptorChain; +import net.sourceforge.myvd.chain.SearchInterceptorChain; +import net.sourceforge.myvd.core.NameSpace; +import net.sourceforge.myvd.inserts.Insert; +import net.sourceforge.myvd.types.Attribute; +import net.sourceforge.myvd.types.Bool; +import net.sourceforge.myvd.types.DistinguishedName; +import net.sourceforge.myvd.types.Entry; +import net.sourceforge.myvd.types.ExtendedOperation; +import net.sourceforge.myvd.types.Filter; +import net.sourceforge.myvd.types.Int; +import net.sourceforge.myvd.types.Password; +import net.sourceforge.myvd.types.Results; + +public class ClearMultiValueRDNEscapesFilter implements Insert { + + String name; + @Override + public String getName() { + return name; + } + + @Override + public void configure(String name, Properties props, NameSpace nameSpace) throws LDAPException { + this.name = name; + + } + + @Override + public void add(AddInterceptorChain chain, Entry entry, LDAPConstraints constraints) throws LDAPException { + chain.nextAdd(entry, constraints); + + } + + @Override + public void bind(BindInterceptorChain chain, DistinguishedName dn, Password pwd, LDAPConstraints constraints) + throws LDAPException { + chain.nextBind(dn, pwd, constraints); + + } + + @Override + public void compare(CompareInterceptorChain chain, DistinguishedName dn, Attribute attrib, + LDAPConstraints constraints) throws LDAPException { + chain.nextCompare(dn, attrib, constraints); + + } + + @Override + public void delete(DeleteInterceptorChain chain, DistinguishedName dn, LDAPConstraints constraints) + throws LDAPException { + chain.nextDelete(dn, constraints); + + } + + @Override + public void extendedOperation(ExetendedOperationInterceptorChain chain, ExtendedOperation op, + LDAPConstraints constraints) throws LDAPException { + chain.nextExtendedOperations(op, constraints); + + } + + @Override + public void modify(ModifyInterceptorChain chain, DistinguishedName dn, ArrayList mods, + LDAPConstraints constraints) throws LDAPException { + chain.nextModify(dn, mods, constraints); + + } + + @Override + public void search(SearchInterceptorChain chain, DistinguishedName base, Int scope, Filter filter, + ArrayList attributes, Bool typesOnly, Results results, LDAPSearchConstraints constraints) + throws LDAPException { + String strFilter = filter.getValue(); + strFilter = strFilter.replace("\\+", "+"); + Filter nfilter = new Filter(strFilter); + + chain.nextSearch(base, scope, nfilter, attributes, typesOnly, results, constraints); + + } + + @Override + public void rename(RenameInterceptorChain chain, DistinguishedName dn, DistinguishedName newRdn, Bool deleteOldRdn, + LDAPConstraints constraints) throws LDAPException { + chain.nextRename(dn, newRdn, deleteOldRdn, constraints); + + } + + @Override + public void rename(RenameInterceptorChain chain, DistinguishedName dn, DistinguishedName newRdn, + DistinguishedName newParentDN, Bool deleteOldRdn, LDAPConstraints constraints) throws LDAPException { + chain.nextRename(dn, newRdn, newParentDN, deleteOldRdn, constraints); + + } + + @Override + public void postSearchEntry(PostSearchEntryInterceptorChain chain, Entry entry, DistinguishedName base, Int scope, + Filter filter, ArrayList attributes, Bool typesOnly, LDAPSearchConstraints constraints) + throws LDAPException { + chain.nextPostSearchEntry(entry, base, scope, filter, attributes, typesOnly, constraints); + + } + + @Override + public void postSearchComplete(PostSearchCompleteInterceptorChain chain, DistinguishedName base, Int scope, + Filter filter, ArrayList attributes, Bool typesOnly, LDAPSearchConstraints constraints) + throws LDAPException { + chain.nextPostSearchComplete(base, scope, filter, attributes, typesOnly, constraints); + + } + + @Override + public void shutdown() { + + + } + +} diff --git a/src/main/java/net/sourceforge/myvd/inserts/setrdn/SetRDN.java b/src/main/java/net/sourceforge/myvd/inserts/setrdn/SetRDN.java index f04d66a..10e47ea 100644 --- a/src/main/java/net/sourceforge/myvd/inserts/setrdn/SetRDN.java +++ b/src/main/java/net/sourceforge/myvd/inserts/setrdn/SetRDN.java @@ -16,6 +16,7 @@ package net.sourceforge.myvd.inserts.setrdn; +import static org.apache.directory.ldap.client.api.search.FilterBuilder.*; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -24,6 +25,7 @@ import java.util.StringTokenizer; import java.util.Vector; +import org.apache.directory.ldap.client.api.search.FilterBuilder; import org.apache.logging.log4j.Logger; import com.novell.ldap.LDAPAttribute; @@ -275,10 +277,18 @@ private void setExternalDN(Entry entry) { DN dn = new DN(entry.getEntry().getDN()); Vector rdns = dn.getRDNs(); - if (rdns.size() == 0 || ! rdns.get(0).getType().equalsIgnoreCase(this.internalRDN)) { + if (rdns.size() == 0) { + return; + } else if (this.internalRDN.contains("+")) { + + //for now do nothing + + + } else if (! rdns.get(0).getType().equalsIgnoreCase(this.internalRDN)) { return; } + String dnlower = entry.getEntry().getDN().toLowerCase(); String strdn = null;//this.in2out.get(dnlower); @@ -373,7 +383,22 @@ private String getExternalAttrDN(String internalDN,InterceptorChain chain) throw attributes.add(new Attribute(this.objectClass)); StringBuffer b = new StringBuffer(); - b.append("(&(objectClass=").append(this.objectClass).append(")(").append(internalRDNName).append('=').append(internalRDNVal).append("))"); + + if (this.internalRDN.contains("+")) { + StringTokenizer toker = new StringTokenizer(internalRDNName + "=" + internalRDNVal,"+"); + FilterBuilder[] matchFilters = new FilterBuilder[toker.countTokens() + 1]; + + for (int i=0;i attributes = new ArrayList(); - attributes.add(new Attribute(this.internalRDN)); - attributes.add(new Attribute(this.objectClass)); + //attributes.add(new Attribute(this.internalRDN)); + //attributes.add(new Attribute(this.objectClass)); StringBuffer b = new StringBuffer(); b.append("(&(objectClass=").append(this.objectClass).append(")(").append(this.externalRDN).append('=').append(externalRDNs.get(0).getValue()).append("))"); @@ -543,15 +600,31 @@ private DN getInternalDN(DN externalDN,InterceptorChain chain,LDAPEntry toadd) t return externalDN; } - val = entry.getEntry().getAttribute(this.internalRDN).getStringValue(); + + if (this.internalRDN.contains("+")) { + StringTokenizer toker = new StringTokenizer(this.internalRDN,"+",false); + while (toker.hasMoreTokens()) { + String comp = toker.nextToken(); + val += comp + "=" + entry.getEntry().getAttribute(comp).getStringValue() + "+"; + + } + val = val.substring(0,val.length()-1); + rdn = new RDN(val); + + } else { + val = entry.getEntry().getAttribute(this.internalRDN).getStringValue(); + rdn.add(this.internalRDN, val, val); + } + + } else { val = toadd.getAttribute(this.internalRDN).getStringValue(); + rdn.add(this.internalRDN, val, val); } - DN internalDN = new DN(); - RDN rdn = new RDN(); - rdn.add(this.internalRDN, val, val); + + internalDN.addRDN(rdn); for (int i=1,m=externalRDNs.size();i