开发者

How to change LDAP password via JNDI

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


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


attribute should be a single word without any space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜