如何通过 JNDI 更改 LDAP 密码

发布于 2024-10-06 17:33:54 字数 1726 浏览 3 评论 0原文

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

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

下面是我的代码。

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

知道为什么吗?提前非常感谢..

凯文

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

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

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

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

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

发布评论

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

评论(2

楠木可依 2024-10-13 17:33:54

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

需要更改

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

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

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");
御守 2024-10-13 17:33:54

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

attribute should be a single word without any space.

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