feat: Add Support for memberOf Overlay in LDAP Server (#3068)

* feat: Allow All Users to Perform LDAP Search Lookups in their org

* feat: add ldap member of support
This commit is contained in:
Mohammad Yosefpor 2024-07-20 20:55:42 +03:30 committed by GitHub
parent 5a92411006
commit 38b9ad1d9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -130,6 +130,9 @@ func handleSearch(w ldap.ResponseWriter, m *ldap.Message) {
e.AddAttribute("homeDirectory", message.AttributeValue("/home/"+user.Name))
e.AddAttribute("cn", message.AttributeValue(user.Name))
e.AddAttribute("uid", message.AttributeValue(user.Id))
for _, group := range user.Groups {
e.AddAttribute(ldapMemberOfAttr, message.AttributeValue(group))
}
attrs := r.Attributes()
for _, attr := range attrs {
if string(attr) == "*" {

View File

@ -79,6 +79,8 @@ var ldapAttributesMapping = map[string]FieldRelation{
},
}
const ldapMemberOfAttr = "memberOf"
var AdditionalLdapAttributes []message.LDAPString
func init() {
@ -180,7 +182,22 @@ func buildUserFilterCondition(filter interface{}) (builder.Cond, error) {
}
return builder.Not{cond}, nil
case message.FilterEqualityMatch:
field, err := getUserFieldFromAttribute(string(f.AttributeDesc()))
attr := string(f.AttributeDesc())
if attr == ldapMemberOfAttr {
groupId := string(f.AssertionValue())
users, err := object.GetGroupUsers(groupId)
if err != nil {
return nil, err
}
var names []string
for _, user := range users {
names = append(names, user.Name)
}
return builder.In("name", names), nil
}
field, err := getUserFieldFromAttribute(attr)
if err != nil {
return nil, err
}