feat: add LDAP custom filter support (#1719)

* refactor: improve ldap server code

* feat: custom filter

* fix: fix displayName mapping

* feat: add custom filter search fields

* chore: add license

* chore: i18n

* chore: i18n

* chore: update init field
This commit is contained in:
Yaodong Yu
2023-04-13 14:12:31 +08:00
committed by GitHub
parent 968d8646b2
commit 1b1de1dd01
33 changed files with 826 additions and 625 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util"
"github.com/lor00x/goldap/message"
ldap "github.com/forestmgy/ldapserver"
)
@ -68,6 +69,7 @@ func getUsername(filter string) string {
func GetFilteredUsers(m *ldap.Message) (filteredUsers []*object.User, code int) {
r := m.GetSearchRequest()
name, org, code := getNameAndOrgFromFilter(string(r.BaseObject()), r.FilterString())
if code != ldap.LDAPResultSuccess {
return nil, code
@ -114,3 +116,20 @@ func getUserPasswordWithType(user *object.User) string {
}
return fmt.Sprintf("{%s}%s", prefix, user.Password)
}
func getAttribute(attributeName string, user *object.User) message.AttributeValue {
switch attributeName {
case "cn":
return message.AttributeValue(user.Name)
case "uid":
return message.AttributeValue(user.Name)
case "email":
return message.AttributeValue(user.Email)
case "mobile":
return message.AttributeValue(user.Phone)
case "userPassword":
return message.AttributeValue(getUserPasswordWithType(user))
default:
return ""
}
}