有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

ssl Modify LDAP属性在Java中失败,但通过ldapmodify命令成功

我设法对一个属性执行STARTTLS ldapmodify(-ZZ),但未能使用javax执行相同的修改。命名。ldap编码

服务器是OpenLDAP。它已授权SSL证书进行修改,并且允许不安全的读取。经典组合

我从同一台服务器上运行以下命令,我将尝试在该服务器上执行Java代码(稍后):

ldapmodify -H ldap://my.ldap.server:389 -D "myldapadmin" -W -ZZ
Enter LDAP Password:
dn: CN=John Westood,OU=L100,DC=l,DC=woods
changetype: modify
replace: uPwd
uPwd:: 234WF34TG2U
modifying entry "CN=John Westood,OU=L100,DC=l,DC=woods" 

。。。如你所见,它要求我输入MyldAppAdmin的密码,我输入了密码,修改就发生了

这是我在Java上做的,我想做同样的修改,我在同一台服务器上运行它。我首先将SSigned LDAP SSL证书导入java

Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://my.ldap.server:389");

// Create initial context
LdapContext ctx = new InitialLdapContext(env, null);

ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, "myldapadmin");
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, "myadminpass");

// Start TLS (STARTTLS is also used by the console command ldapmodify)
StartTlsResponse tls = (StartTlsResponse) ctx.extendedOperation(new 
StartTlsRequest());
SSLSession sess = tls.negotiate();

//Modification of 'uPwd' attribute
ModificationItem[] mods = new ModificationItem[1];
Attribute mod0 = new BasicAttribute("uPwd", "4G45G435G436UJWG");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
ctx.modifyAttributes("CN=John Westood,OU=L100,DC=l,DC=woods", mods);

// Stop TLS
tls.close();
// Context close
ctx.close();

我在方法ctx中遇到异常。修改属性。例外情况如下:

javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000052D: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0

有人知道为什么modify uPwd可以从命令行而不是Java中运行吗


共 (1) 个答案