[英]How to escape the special character in an ldap query?
I have one user on LDAP named with base DN我在 LDAP 上有一个用基本 DN 命名的用户
=CN=abc def\, ghi,CN=jkl,DC=mno,DC=pqr
and password is xyz
.密码是
xyz
。
I want to search this user in ldap, how do I do that?我想在 ldap 中搜索这个用户,我该怎么做? One thing is clear, the LDAP query should be like,
有一点很清楚,LDAP 查询应该是这样的,
CN=abc def\\\, ghi\,CN=jkl\,DC=mno\,DC=pqr,xyz
tried these solutions尝试了这些解决方案
.getBindUserDN().replaceAll("[,]", "\\\\\\,").getBindUserDN().replaceAll(",", "\\,")
etc. What should be the logic here?等等 这里的逻辑应该是什么?
I found the solution but it's very much specific to this case where we specify only one backslash \\
and a comma ,
ie \\,
我找到了解决方案,但它非常适合这种情况,我们只指定一个反斜杠
\\
和一个逗号,
即\\,
The problem was that, when I was trying to search for a ldap entry, I was taking the value of Bind DN
directly.问题是,当我尝试搜索 ldap 条目时,我直接获取了
Bind DN
的值。 Later after trial and error method I understood that when I am searching for it's secret key we need 6 number of backslashes ie \\\\\\\\\\\\
to find it's secret key as LDAP store it with 3 backslashes and comma \\\\\\,
.后来经过反复试验,我明白当我搜索它的秘密密钥时,我们需要 6 个反斜杠,即
\\\\\\\\\\\\
才能找到它的秘密密钥,因为 LDAP 用 3 个反斜杠和逗号\\\\\\,
存储它。
But when I am going to look into Ldap for this secret key, so now I need to search with this new secret key, it means 6 backslashes should be there.但是当我要查看 Ldap 以获取此密钥时,现在我需要使用此新密钥进行搜索,这意味着应该有 6 个反斜杠。 So I have to search it with double the number of these backslashes ie 12
\\\\\\\\\\\\\\\\\\\\\\\\
所以我必须用这些反斜杠的两倍数量来搜索它,即 12
\\\\\\\\\\\\\\\\\\\\\\\\
PS:- This Solution appltes to a very particular case. But Logic should be similar if someone needs to apply it in a different way
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.