한 명의 사용자를 성공적으로 인증했습니다. 이제 다른 사용자의 비밀번호를 변경하고 싶습니다. 첫 번째 사용자는 관리자와 동일하므로 다른 사용자의 비밀번호를 변경하거나 재설정해야합니다. 여기한 사용자의 인증 후 다른 사용자의 비밀번호를 변경하는 방법
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";
을 나는 다음과 같은 예외에 geting 오전 :
javax.naming.NoPermissionException: [LDAP: error code 50 - 00002098: SecErr: DSID-03150A48, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
다음의 UPDATE/RESOLVE 섹션을 참조하십시오. http://stackoverflow.com/questions/9699912/can-i-change-myself-active-directory-password-from-ldap-without-administrative – Diego87