Skip to content

Commit d78e8e9

Browse files
authored
feat: fix LDAP filter condition will return nil if error happened (casdoor#3604)
1 parent d61f9a1 commit d78e8e9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ldap/util.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ func buildUserFilterCondition(filter interface{}) (builder.Cond, error) {
185185
attr := string(f.AttributeDesc())
186186

187187
if attr == ldapMemberOfAttr {
188-
groupId := string(f.AssertionValue())
189-
users, err := object.GetGroupUsers(groupId)
190-
if err != nil {
191-
return nil, err
192-
}
193188
var names []string
189+
groupId := string(f.AssertionValue())
190+
users := object.GetGroupUsersWithoutError(groupId)
194191
for _, user := range users {
195192
names = append(names, user.Name)
196193
}
@@ -249,7 +246,7 @@ func buildSafeCondition(filter interface{}) builder.Cond {
249246
condition, err := buildUserFilterCondition(filter)
250247
if err != nil {
251248
log.Printf("err = %v", err.Error())
252-
return nil
249+
return builder.And(builder.Expr("1 != 1"))
253250
}
254251
return condition
255252
}

object/group.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ func GetPaginationGroupUsers(groupId string, offset, limit int, field, value, so
302302

303303
func GetGroupUsers(groupId string) ([]*User, error) {
304304
users := []*User{}
305-
owner, _ := util.GetOwnerAndNameFromId(groupId)
305+
owner, _, err := util.GetOwnerAndNameFromIdWithError(groupId)
306+
if err != nil {
307+
return nil, err
308+
}
306309
names, err := userEnforcer.GetUserNamesByGroupName(groupId)
307310
if err != nil {
308311
return nil, err
@@ -314,6 +317,11 @@ func GetGroupUsers(groupId string) ([]*User, error) {
314317
return users, nil
315318
}
316319

320+
func GetGroupUsersWithoutError(groupId string) []*User {
321+
users, _ := GetGroupUsers(groupId)
322+
return users
323+
}
324+
317325
func ExtendGroupWithUsers(group *Group) error {
318326
if group == nil {
319327
return nil

0 commit comments

Comments
 (0)