Associate Ldap user with group with Java

I'm having trouble finding how to associate the #Ldap user with a specific group.

Here is what I tried:

    Attributes attrs = new BasicAttributes();

    BasicAttribute basicAttrs = new BasicAttribute("objectclass");
    basicAttrs.add("top");
    basicAttrs.add("person");

    BasicAttribute memberOf = new BasicAttribute("memberOf");
    memberOf.add("Managers"); // Tried with distinguished name too
    memberOf.add("Administrators"); // Tried with distinguished name too

    attrs.put(basicAttrs);
    attrs.put("cn", user.getLogin());
    attrs.put("name", user.getLogin());
    attrs.put("login", user.getLogin());
    attrs.put("mail", user.getMail());
    attrs.put("displayName", user.getDisplayName());
    attrs.put("memberOf", memberOf);

    try {
        ctx.bind("CN=" + user.getLogin() + "," + baseDn, null, attrs);
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I also tried using distinguished names, for example: "CN = Managers, OU = <system_name>, OU = Users, OU = <server>, DC = com", but it does not work. I think it should be somewhere to reference the Ldap group.

But I got this error:

javax.naming.directory.InvalidAttributeValueException: Malformed 'memberOf' attribute value; remaining name 'CN=lcarvalho,OU=<system_name>,OU=Users,OU=<server>,DC=com'
at com.sun.jndi.ldap.LdapClient.encodeAttribute(LdapClient.java:951)
at com.sun.jndi.ldap.LdapClient.add(LdapClient.java:999)
at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:396)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_bind(ComponentDirContext.java:277)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.bind(PartialCompositeDirContext.java:197)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.bind(PartialCompositeDirContext.java:186)
at javax.naming.directory.InitialDirContext.bind(InitialDirContext.java:158)
...

This is all stack trace except application lines.

+5
source share
4 answers

OpenLDAP, memberOf memberOf, . DN uniqueMember roleOccupant .. , . DN memberOf.

+5

, DN , , :

"CN=Managers,OU=<system_name>,OU=Users,OU=<server>,DC=com"

:

"cn=Managers,ou=<system_name>,ou=Users,dc=<server>,dc=com"

LDAP 2- , ( ).

, :

  • "", LDAP

  • MemberOf, "Person"

  • "MemberOf" DN

UnboundID LDAP SDK.

, .

0

memberOf . memberOf, , . LDAP ( DN DSE), , .

0

I had the same problem. Check the value type of this attribute using any ldap client (for example: Apache Directory Studio). If you try to replace an attribute whose type is a String with an int value, this will cause this error.

-1
source

All Articles