Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displayName in LDAP group #28

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{displayName})

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
Loading