如何通过JNDI更改LDAP密码 [英] How to change LDAP password via JNDI
问题描述
我正在尝试通过JNDI更改用户密码,但是在下面出现错误消息.
I am trying to change the user's password via JNDI but i am getting the error below.
javax.naming.directory.SchemaViolationException:[LDAP:错误代码65-无法修改uid = yiwei,ou = Administrator,o = SID,dc = QuizPortal,因为结果条目将违反服务器模式:Entry uid = yiwei,ou = Administrator,o = SID,dc = QuizPortal违反了Directory Server架构配置,因为它包含该条目中定义的任何对象类都不允许的属性用户密码];
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Entry uid=yiwei,ou=Administrator,o=SID,dc=QuizPortal cannot not be modified because the resulting entry would have violated the server schema: Entry uid=yiwei,ou=Administrator,o=SID,dc=QuizPortal violates the Directory Server schema configuration because it includes attribute user password which is not allowed by any of the objectclasses defined in that entry];
以下是我的代码.
public class ModifyAtt
{
public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
public static String MY_HOST = "ldap://KhooGP-Comp1:1389/dc=QuizPortal";
public static String MGR_DN = "cn=Directory Manager";
public static String MGR_PW = "password";
public static void main(String[] args)
{
//Identify service provider to use
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
env.put(Context.PROVIDER_URL, MY_HOST);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
env.put(Context.SECURITY_CREDENTIALS, MGR_PW);
try
{
// Create the initial directory context
InitialDirContext initialContext = new InitialDirContext(env);
DirContext ctx = (DirContext)initialContext;
System.out.println("Context Sucessfully Initialized");
ModificationItem[] mods = new ModificationItem[1];
Attribute mod0 = new BasicAttribute("user password", "a");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
ctx.modifyAttributes("uid=yiwei,ou=Administrator,o=SID", mods);
}
catch(Exception e)
{
System.err.println(e);
}
}
}
知道为什么吗?预先非常感谢..
Any idea why?? Many thanks in advance..
凯文
推荐答案
Ah ..用户密码不应有任何空格.
Ah.. there shouldnt be any spacing for the user password.
需要更改
Attribute mod0 = new BasicAttribute("user password", "a");
到
Attribute mod0 = new BasicAttribute("userpassword", "a");
这篇关于如何通过JNDI更改LDAP密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!