如何在一个用户认证后更改其他用户的密码

发布于 2024-12-21 00:28:47 字数 1494 浏览 1 评论 0原文

我已成功验证一个用户的身份。现在我想更改其他用户的密码。我的第一个用户就像管理员一样,因此应更改或重置其他用户的密码。

我正在使用以下代码:

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    

I have successfully authenticated one user.Now i want to change password for other user.My first user is just like Admin,so other users password should be changed or reset.

I am using following code:

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();

fields attributes values is here :

 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";

I am geting following exception :

javax.naming.NoPermissionException: [LDAP: error code 50 - 00002098: SecErr: DSID-03150A48, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-12-28 00:28:47

NoPermissionException 意味着您连接到 LDAP 的用户无权替换该属性。您需要为您绑定的用户提供更高级别的访问权限。

此外,根据 LDAP 提供商的不同,您可能需要通过安全 ldaps 连接而不是基本 ldap 连接进行连接。

NoPermissionException means that the user you are connecting to LDAP with doesn't have access to replace that attribute. You need to give the user that you bind with higher level access.

Also, depending on the LDAP provider, you may need to be connecting over a secure ldaps connection rather than a basic ldap connection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文