Skip to content

Commit

Permalink
adding GroupsAttributeInfoByField (#192)
Browse files Browse the repository at this point in the history
## Type of Change
Please select the type of change your PR introduces by checking the
appropriate box:
- [ ] Fixes an issue
- [X] Adds a new feature
- [ ] Refactor
- [ ] Documentation update
- [ ] Other (please describe it in the Description Section)

## Description
This function added will allow to filter multiple Ldap entries
attributes based on the user desired attribute like "cn", filter and
search string.

No need for map[string] interface as the go-ldap pkg Entry struct Values
type is a string slice.

=>https://pkg.go.dev/github.com/go-ldap/ldap/v3#EntryAttribute
  • Loading branch information
sabouaram authored Nov 18, 2024
2 parents 8451eae + 9795564 commit 08fd0fc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,37 @@ func (lc *HelperLDAP) UserInfoByField(username string, fieldOfUnicValue string)
func (lc *HelperLDAP) GroupInfo(groupname string) (map[string]interface{}, liberr.Error) {
return lc.GroupInfoByField(groupname, groupFieldCN)
}
func (lc *HelperLDAP) AttributeFilter(search string,
filter string, attribute string) (map[string][]string,
liberr.Error) {

var (
err liberr.Error
src *ldap.SearchResult
grpInfo map[string][]string
)

src, err = lc.runSearch(fmt.Sprintf("(&(objectClass~=groupOfNames)(%s=%s))", filter, search), []string{})

if err != nil {
return grpInfo, err
}

if len(src.Entries) == 0 {
return nil, ErrorLDAPGroupNotFound.Error(nil)
}

for _, entry := range src.Entries {
for _, entryAttribute := range entry.Attributes {
if entryAttribute.Name == attribute {
grpInfo[entryAttribute.Name] = append(grpInfo[entryAttribute.Name], entryAttribute.Values...)
}
}
}

lc.getLogEntry(loglvl.DebugLevel, "ldap group find success").FieldAdd("ldap.group", search).FieldAdd("ldap.map", grpInfo).Log()
return grpInfo, nil
}

// GroupInfoByField used to retrieve the information of a given group cn, but use a given field to make the search.
func (lc *HelperLDAP) GroupInfoByField(groupname string, fieldForUnicValue string) (map[string]interface{}, liberr.Error) {
Expand Down

0 comments on commit 08fd0fc

Please sign in to comment.