mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-09 11:52:56 +08:00
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:

committed by
GitHub

parent
5a92411006
commit
38b9ad1d9f
@@ -130,6 +130,9 @@ func handleSearch(w ldap.ResponseWriter, m *ldap.Message) {
|
|||||||
e.AddAttribute("homeDirectory", message.AttributeValue("/home/"+user.Name))
|
e.AddAttribute("homeDirectory", message.AttributeValue("/home/"+user.Name))
|
||||||
e.AddAttribute("cn", message.AttributeValue(user.Name))
|
e.AddAttribute("cn", message.AttributeValue(user.Name))
|
||||||
e.AddAttribute("uid", message.AttributeValue(user.Id))
|
e.AddAttribute("uid", message.AttributeValue(user.Id))
|
||||||
|
for _, group := range user.Groups {
|
||||||
|
e.AddAttribute(ldapMemberOfAttr, message.AttributeValue(group))
|
||||||
|
}
|
||||||
attrs := r.Attributes()
|
attrs := r.Attributes()
|
||||||
for _, attr := range attrs {
|
for _, attr := range attrs {
|
||||||
if string(attr) == "*" {
|
if string(attr) == "*" {
|
||||||
|
19
ldap/util.go
19
ldap/util.go
@@ -79,6 +79,8 @@ var ldapAttributesMapping = map[string]FieldRelation{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ldapMemberOfAttr = "memberOf"
|
||||||
|
|
||||||
var AdditionalLdapAttributes []message.LDAPString
|
var AdditionalLdapAttributes []message.LDAPString
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -180,7 +182,22 @@ func buildUserFilterCondition(filter interface{}) (builder.Cond, error) {
|
|||||||
}
|
}
|
||||||
return builder.Not{cond}, nil
|
return builder.Not{cond}, nil
|
||||||
case message.FilterEqualityMatch:
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user