java 如何通过 JNDI 更改 LDAP 密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4393948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:10:07  来源:igfitidea点击:

How to change LDAP password via JNDI

javapasswordsldapjndi

提问by Nivek

I am trying to change the user's password via JNDI but i am getting the error below.

我正在尝试通过 JNDI 更改用户密码,但出现以下错误。

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

javax.naming.directory.SchemaViolationException: [LDAP: 错误代码 65 - 条目 uid=yiwei,ou=Administrator,o=SID,dc=QuizPortal 不能修改,因为结果条目会违反服务器架构:条目 uid=yiwei ,ou=Administrator,o=SID,dc=QuizPortal 违反了目录服务器架构配置,因为它包含该条目中定义的任何对象类都不允许的属性用户密码];

The below is my code.

下面是我的代码。

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..

知道为什么吗?提前谢谢了..

Kevin

凯文

回答by Nivek

Ah.. there shouldnt be any spacing for the user password.

啊.. 用户密码不应该有任何空格。

need to change

需要改变

Attribute mod0 = new BasicAttribute("user password", "a");

to

Attribute mod0 = new BasicAttribute("userpassword", "a");

回答by M2E67

attribute should be a single word without any space.

属性应该是一个没有任何空格的单词。