Skip to content

Commit

Permalink
for #74 initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbiam committed Nov 26, 2019
1 parent 2ec97e9 commit 047d1e9
Show file tree
Hide file tree
Showing 12 changed files with 928 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LDAPModification> mods,
LDAPConstraints constraints) throws LDAPException {
chain.nextModify(dn, mods, constraints);

}

@Override
public void search(SearchInterceptorChain chain, DistinguishedName base, Int scope, Filter filter,
ArrayList<Attribute> 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<Attribute> 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<Attribute> attributes, Bool typesOnly, LDAPSearchConstraints constraints)
throws LDAPException {
chain.nextPostSearchComplete(base, scope, filter, attributes, typesOnly, constraints);

}

@Override
public void shutdown() {


}

}
111 changes: 92 additions & 19 deletions src/main/java/net/sourceforge/myvd/inserts/setrdn/SetRDN.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -275,10 +277,18 @@ private void setExternalDN(Entry entry) {

DN dn = new DN(entry.getEntry().getDN());
Vector<RDN> 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);

Expand Down Expand Up @@ -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<matchFilters.length-1;i++) {
String comp = toker.nextToken();
matchFilters[i] = FilterBuilder.equal(comp.substring(0,comp.indexOf('=')),comp.substring(comp.indexOf('=') + 1) );
}

matchFilters[matchFilters.length - 1] = FilterBuilder.equal("objectClass", this.objectClass);

b.append(FilterBuilder.and(matchFilters).toString());
} else {
b.append("(&(objectClass=").append(this.objectClass).append(")(").append(internalRDNName).append('=').append(internalRDNVal).append("))");
}
//b.append('(').append(this.externalRDN).append('=').append(externalRDNs.get(0).getValue()).append(')');
Filter filter = new Filter(b.toString());

Expand Down Expand Up @@ -468,21 +493,51 @@ private String getInternalAttrDN(String externalDN,InterceptorChain chain) throw
return externalDN;
}

String val = entry.getEntry().getAttribute(this.internalRDN).getStringValue();

DN newInternal = new DN();
b.setLength(0);
b.append(this.internalRDN).append('=').append(val);
RDN rdn = new RDN(b.toString());

newInternal.addRDN(rdn);
RDN rdn;

for (int i=1;i<rdns.size();i++) {
newInternal.addRDNToBack((RDN) rdns.get(i));
if (this.internalRDN.contains("+")) {
StringTokenizer toker = new StringTokenizer(this.internalRDN,"+",false);
String val = "";
while (toker.hasMoreTokens()) {
String comp = toker.nextToken();
val += comp + "=" + entry.getEntry().getAttribute(comp).getStringValue() + "+";

}
val = val.substring(0,val.length()-1);

DN newInternal = new DN();


//newInternal.addRDN(rdn);

for (int i=1;i<rdns.size();i++) {
newInternal.addRDNToBack((RDN) rdns.get(i));
}
String finalDN = val + "," + newInternal.toString();
return finalDN;
} else {
String val = entry.getEntry().getAttribute(this.internalRDN).getStringValue();

b.setLength(0);
b.append(this.internalRDN).append('=').append(val);
rdn = new RDN(b.toString());

DN newInternal = new DN();


newInternal.addRDN(rdn);

for (int i=1;i<rdns.size();i++) {
newInternal.addRDNToBack((RDN) rdns.get(i));
}

this.out2in.put(externalDN.toLowerCase() , newInternal.toString().toLowerCase());
return newInternal.toString();
}

this.out2in.put(externalDN.toLowerCase() , newInternal.toString().toLowerCase());
return newInternal.toString();



}

Expand Down Expand Up @@ -516,11 +571,13 @@ private DN getInternalDN(DN externalDN,InterceptorChain chain,LDAPEntry toadd) t
}

String val = "";
DN internalDN = new DN();
RDN rdn = new RDN();

if (toadd == null) {
ArrayList<Attribute> attributes = new ArrayList<Attribute>();
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("))");
Expand All @@ -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<m;i++) {
internalDN.addRDNToBack(externalRDNs.get(i));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/sourceforge/myvd/test/setrdn/SetRDNAD.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ public void testBaseSearch() throws LDAPException {
attribs.add(new LDAPAttribute("userPassword", "secret"));

// attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal"));
LDAPEntry entry2 = new LDAPEntry("cn=Users\\ Test3,cn=users,dc=ad,dc=com", attribs);
LDAPEntry entry2 = new LDAPEntry("uid=tuser003,cn=users,dc=ad,dc=com", attribs);

LDAPConnection con = new LDAPConnection();
con.connect("localhost", 50983);
// con.bind(3,"cn=admin,o=mycompany","manager".getBytes());
LDAPSearchResults res = con.search("cn=Users\\ Test3,cn=users,dc=ad,dc=com", 0, "(objectClass=*)",
LDAPSearchResults res = con.search("uid=tuser003,cn=users,dc=ad,dc=com", 0, "(objectClass=*)",
new String[0], false);

/*
Expand Down
Loading

0 comments on commit 047d1e9

Please sign in to comment.