1人のユーザーの認証に成功しました。他のユーザーのパスワードを変更したいのですが、最初のユーザーはAdminと同じなので、他のユーザーのパスワードを変更またはリセットする必要があります。
私は次のコードを使用しています:
LdapContext ctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.PROVIDER_URL, "ldap://xx.xxx.xx.xxx:389");
ctx = new InitialLdapContext(env, null);
final DistinguishedName dn = usernameMapper.buildDn(username);
final ModificationItem[] passwordChange = new ModificationItem[]
{
new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(passwordAttributeName, newPassword))
};
ctx.modifyAttributes(dn, passwordChange);
System.out.println("Password changed successfully");
ctx.close();
フィールド属性値はここにあります:
String passwordAttributeName = "userPassword";
static LdapUsernameToDnMapper usernameMapper
= new DefaultLdapUsernameToDnMapper("OU=DROID-TEST,DC=example,DC=com",
"cn");
private String username = "test01";
private String password = "test01";
private String newPassword = "123";
次の例外が発生します:
javax.naming.NoPermissionException: [LDAP: error code 50 - 00002098: SecErr: DSID-03150A48, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0