我想在javax.naming.ldap.LdapContext
上设置 relax 控件(如https://tools.ietf.org/html/draft-zeilenga-ldap-relax-03中所定义),但我不知道如何正确构造控件:< / p>
LdapContext context = new InitialLdapContext(...);
Control[] controls = { new BasicControl(/* What to put here? */) };
context.setRequestControls(controls);
答案 0 :(得分:1)
在一般情况下,您需要编写一个扩展BasicControl的类,并实现编码和解码所需的所有ASN.1内容。鉴于官方JDK中缺乏对ASN.1的支持,这不是一项微不足道的任务。
然而,由于这种控制是微不足道的:
import javax.naming.ldap.BasicControl;
/**
* Relax Rules control
* @author Esmond Pitt
* @see <a href="https://tools.ietf.org/html/draft-zeilenga-ldap-relax-03">The Relax Rules Control</a>
* @see <a href="http://stackoverflow.com/questions/30080294/how-to-set-relax-controls-on-a-ldap-context">Stack Overflow</a>
*/
public class RelaxRulesControl extends BasicControl
{
/** The OID, see Tobias's answer for provenance. */
public static final String OID = "1.3.6.1.4.1.4203.666.5.12";
/** Construct an instance with criticality = true */
public RelaxRulesControl()
{
super(OID, true, null);
}
/** Construct an instance with critically as specified */
public RelaxRulesControl(boolean critical)
{
super(OID, critical, null);
}
}
答案 1 :(得分:0)
幸运的是,我在草案中找到了答案的一部分:
Relax Rules控件是一个LDAP控件[RFC4511] controlType是IANA-ASSIGNED-OID,controlValue是空的,而 真实的关键性。
所以唯一的问题是找到 IANA-ASSIGNED-OID
查看OpenLdap 2.4.40(包含/ ldap.h)的源代码,这是:
#define LDAP_CONTROL_RELAX "1.3.6.1.4.1.4203.666.5.12"
现在这个有效:
LdapContext context = new InitialLdapContext(...);
Control[] controls = { new BasicControl(
"1.3.6.1.4.1.4203.666.5.12", // OID
true, // criticality
null // control value
) };
context.setRequestControls(controls);
请注意,此OID属于 OpenLDAP实验弧(1.3.6.1.4.1.4203.666),并且可能会在将来的OpenLDAP版本中发生更改。