Skip to content

Commit

Permalink
Add support for displayName in LDAP group
Browse files Browse the repository at this point in the history
  • Loading branch information
tsueho committed Aug 14, 2023
1 parent ccde965 commit bc20e16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// CreateGroup creates ldap group
func (c *Client) CreateGroup(dn, name, description, groupType, managedBy string, members []string) error {
func (c *Client) CreateGroup(dn, name, description, groupType, managedBy string, displayName string, members []string) error {

req := ldap.NewAddRequest(dn, []ldap.Control{})
req.Attribute("objectClass", []string{"group"})
Expand All @@ -25,6 +25,10 @@ func (c *Client) CreateGroup(dn, name, description, groupType, managedBy string,
req.Attribute("managedBy", []string{managedBy})
}

if displayName != "" {
req.Attribute("displayName", []string{displayName})
}

if len(members) > 0 {
req.Attribute("member", members)
}
Expand Down Expand Up @@ -80,7 +84,7 @@ func (c *Client) ReadGroup(dn string, memberPageSize int) (attributes map[string
0,
false,
"(objectclass=group)",
[]string{"name", "description", "groupType", "managedBy"},
[]string{"name", "description", "groupType", "managedBy", "displayName"},
[]ldap.Control{},
)

Expand Down Expand Up @@ -204,6 +208,16 @@ func (c *Client) UpdateGroupManagedBy(dn string, managedBy string) error {
return c.Conn.Modify(req)
}

// UpdateGroupDisplayName updates ldap group displayName
func (c *Client) UpdateGroupDisplayName(dn string, displayName string) error {

req := ldap.NewModifyRequest(dn, []ldap.Control{})

req.Replace("displayName", []string{managedBy})

return c.Conn.Modify(req)
}

// DeleteGroup deletes the specify group
func (c *Client) DeleteGroup(dn string) error {

Expand Down
2 changes: 1 addition & 1 deletion group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestCreateGroup(t *testing.T) {
t.FailNow()
}

err = client.CreateGroup(os.Getenv("GOLDAP_TESTGROUP"), os.Getenv("GOLDAP_TESTNAME"), os.Getenv("GOLDAP_TESTDESC"), "", "", []string{})
err = client.CreateGroup(os.Getenv("GOLDAP_TESTGROUP"), os.Getenv("GOLDAP_TESTNAME"), os.Getenv("GOLDAP_TESTDESC"), "", "", "", []string{})
if err != nil {
fmt.Printf("%s", err)
t.FailNow()
Expand Down

0 comments on commit bc20e16

Please sign in to comment.