outposts/ldap: optimise backend Search API requests
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
38
internal/outpost/ldap/instance_search_user.go
Normal file
38
internal/outpost/ldap/instance_search_user.go
Normal file
@ -0,0 +1,38 @@
|
||||
package ldap
|
||||
|
||||
import (
|
||||
ber "github.com/nmcclain/asn1-ber"
|
||||
"github.com/nmcclain/ldap"
|
||||
"goauthentik.io/api"
|
||||
)
|
||||
|
||||
func parseFilterForUser(req api.ApiCoreUsersListRequest, filter string) api.ApiCoreUsersListRequest {
|
||||
f, err := ldap.CompileFilter(filter)
|
||||
if err != nil {
|
||||
return req
|
||||
}
|
||||
switch f.Tag {
|
||||
case ldap.FilterEqualityMatch:
|
||||
return parseFilterForUserSingle(req, f)
|
||||
case ldap.FilterAnd:
|
||||
for _, child := range f.Children {
|
||||
req = parseFilterForUserSingle(req, child)
|
||||
}
|
||||
return req
|
||||
}
|
||||
return req
|
||||
}
|
||||
|
||||
func parseFilterForUserSingle(req api.ApiCoreUsersListRequest, f *ber.Packet) api.ApiCoreUsersListRequest {
|
||||
v := f.Children[1].Value.(string)
|
||||
switch f.Children[0].Value.(string) {
|
||||
case "cn":
|
||||
return req.Username(v)
|
||||
case "name":
|
||||
case "displayName":
|
||||
return req.Name(v)
|
||||
case "mail":
|
||||
return req.Email(v)
|
||||
}
|
||||
return req
|
||||
}
|
Reference in New Issue
Block a user