twisted / ldaptor

LDAP server, client and utilities, using Twisted Python
MIT License
158 stars 54 forks source link

Help: how to modify ldap filter within handleBeforeForwardRequest #221

Open resposit opened 3 years ago

resposit commented 3 years ago

Hello, I'm trying to implement a custom LDAP proxy server that gets a searchRequest from a client, inspect the request and possibly modify the search flter before sending it to the proxied server. For example, if the client sends a searchRequest with filter '(a=b)', the proxy should modify this filter to '(&(a=b)(c=d))' and send it to the proxied server. When I override the handleBeforeForwardRequest (of the ProxyBase class), it seems the filter string has already been parsed and the request object contains a pureldap filter object which I don't quite understand how can be modified. Having a string filter would be much easier. Any suggestions ?

Thanks

resposit commented 3 years ago

I think I just found the answer myself, using the .asText() method. Sorry about that.

resposit commented 3 years ago

Apparently I'm not yet able to use the asText() method within handleBeforeForwardRequest() due to bytes/string conversion:

The request filter I'm getting is:

x = LDAPFilter_equalityMatch(attributeDesc=BEROctetString(value=b'attribute'), assertionValue=BEROctetString(value=b'value'))

when I try x.asText() I get:

----> 1 x.asText()

/usr/local/lib/python3.6/site-packages/ldaptor/protocols/pureldap.py in asText(self) 590 + "=" 591 + self.escaper(self.assertionValue.value) --> 592 + ")" 593 )

Any ideas ?

dagmoller commented 1 month ago

Apparently I'm not yet able to use the asText() method within handleBeforeForwardRequest() due to bytes/string conversion:

The request filter I'm getting is:

x = LDAPFilter_equalityMatch(attributeDesc=BEROctetString(value=b'attribute'), assertionValue=BEROctetString(value=b'value'))

when I try x.asText() I get:

----> 1 x.asText()

/usr/local/lib/python3.6/site-packages/ldaptor/protocols/pureldap.py in asText(self) 590 + "=" 591 + self.escaper(self.assertionValue.value) --> 592 + ")" 593 )

Any ideas ?

Any solutions for that?