Associate Ldap user to a group with Java

前端 未结 4 745
闹比i
闹比i 2021-01-05 17:25

I\'m having problems to find how to associate a #Ldap user to a given group.

That is what I have tried:

    Attributes attrs = new BasicAttributes();         


        
相关标签:
4条回答
  • 2021-01-05 17:47

    Most probably your DN is wrong, because it seems you've specified one extra Organizational Unit instead of Domain Component:

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

    should be:

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

    In LDAP the Directory Structure starts with 2 domain components, which are a reversed company domain name (by convention).

    In order for your code to work, you have to take into account the following:

    • there's a schema "Person" that's loaded in your LDAP Server

    • there's an attribute "MemberOf" defined in your "Person" schema

    • "MemberOf" requires full DN as entry

    I would also encourage you to take a look at UnboundID LDAP SDK.

    Hope that helps.

    0 讨论(0)
  • 2021-01-05 17:49

    The value of the memberOf attribute is wrong. The memberOf attribute is probably a distinguished name. LDAP clients should consult the schema (the base DN of which might be available in the root DSE) when in doubt about the syntax, ordering, or matching rules of an attribute.

    0 讨论(0)
  • 2021-01-05 17:50

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

    0 讨论(0)
  • 2021-01-05 17:57

    If you're using OpenLDAP the memberOf attribute is maintained automatically by the memberOf overlay, and your application shouldn't write it at all. What you should be doing is adding the DN of the user to the uniqueMember or roleOccupant etc. attribute of the group he is joining. Then its DN will magically appear in his memberOf attribute.

    0 讨论(0)
提交回复
热议问题