9
9
"fmt"
10
10
"net"
11
11
"os"
12
+ "strings"
12
13
13
14
"github.com/go-ldap/ldap/v3"
14
15
@@ -347,21 +348,23 @@ func (c *ldapConnector) do(_ context.Context, f func(c *ldap.Conn) error) error
347
348
return f (conn )
348
349
}
349
350
350
- func getAttrs (e ldap.Entry , name string ) []string {
351
+ func ( c * ldapConnector ) getAttrs (e ldap.Entry , name string ) []string {
351
352
for _ , a := range e .Attributes {
352
353
if a .Name != name {
353
354
continue
354
355
}
355
356
return a .Values
356
357
}
357
- if name == "DN " {
358
+ if strings . ToLower ( name ) == "dn " {
358
359
return []string {e .DN }
359
360
}
361
+
362
+ c .logger .Debugf ("%q attribute is not fround in entry" , name )
360
363
return nil
361
364
}
362
365
363
- func getAttr (e ldap.Entry , name string ) string {
364
- if a := getAttrs (e , name ); len (a ) > 0 {
366
+ func ( c * ldapConnector ) getAttr (e ldap.Entry , name string ) string {
367
+ if a := c . getAttrs (e , name ); len (a ) > 0 {
365
368
return a [0 ]
366
369
}
367
370
return ""
@@ -373,25 +376,25 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
373
376
missing := []string {}
374
377
375
378
// Fill the identity struct using the attributes from the user entry.
376
- if ident .UserID = getAttr (user , c .UserSearch .IDAttr ); ident .UserID == "" {
379
+ if ident .UserID = c . getAttr (user , c .UserSearch .IDAttr ); ident .UserID == "" {
377
380
missing = append (missing , c .UserSearch .IDAttr )
378
381
}
379
382
380
383
if c .UserSearch .NameAttr != "" {
381
- if ident .Username = getAttr (user , c .UserSearch .NameAttr ); ident .Username == "" {
384
+ if ident .Username = c . getAttr (user , c .UserSearch .NameAttr ); ident .Username == "" {
382
385
missing = append (missing , c .UserSearch .NameAttr )
383
386
}
384
387
}
385
388
386
389
if c .UserSearch .PreferredUsernameAttrAttr != "" {
387
- if ident .PreferredUsername = getAttr (user , c .UserSearch .PreferredUsernameAttrAttr ); ident .PreferredUsername == "" {
390
+ if ident .PreferredUsername = c . getAttr (user , c .UserSearch .PreferredUsernameAttrAttr ); ident .PreferredUsername == "" {
388
391
missing = append (missing , c .UserSearch .PreferredUsernameAttrAttr )
389
392
}
390
393
}
391
394
392
395
if c .UserSearch .EmailSuffix != "" {
393
396
ident .Email = ident .Username + "@" + c .UserSearch .EmailSuffix
394
- } else if ident .Email = getAttr (user , c .UserSearch .EmailAttr ); ident .Email == "" {
397
+ } else if ident .Email = c . getAttr (user , c .UserSearch .EmailAttr ); ident .Email == "" {
395
398
missing = append (missing , c .UserSearch .EmailAttr )
396
399
}
397
400
// TODO(ericchiang): Let this value be set from an attribute.
@@ -575,13 +578,13 @@ func (c *ldapConnector) Refresh(ctx context.Context, s connector.Scopes, ident c
575
578
576
579
func (c * ldapConnector ) groups (ctx context.Context , user ldap.Entry ) ([]string , error ) {
577
580
if c .GroupSearch .BaseDN == "" {
578
- c .logger .Debugf ("No groups returned for %q because no groups baseDN has been configured." , getAttr (user , c .UserSearch .NameAttr ))
581
+ c .logger .Debugf ("No groups returned for %q because no groups baseDN has been configured." , c . getAttr (user , c .UserSearch .NameAttr ))
579
582
return nil , nil
580
583
}
581
584
582
585
var groups []* ldap.Entry
583
586
for _ , matcher := range c .GroupSearch .UserMatchers {
584
- for _ , attr := range getAttrs (user , matcher .UserAttr ) {
587
+ for _ , attr := range c . getAttrs (user , matcher .UserAttr ) {
585
588
filter := fmt .Sprintf ("(%s=%s)" , matcher .GroupAttr , ldap .EscapeFilter (attr ))
586
589
if c .GroupSearch .Filter != "" {
587
590
filter = fmt .Sprintf ("(&%s%s)" , c .GroupSearch .Filter , filter )
@@ -617,7 +620,7 @@ func (c *ldapConnector) groups(ctx context.Context, user ldap.Entry) ([]string,
617
620
618
621
groupNames := make ([]string , 0 , len (groups ))
619
622
for _ , group := range groups {
620
- name := getAttr (* group , c .GroupSearch .NameAttr )
623
+ name := c . getAttr (* group , c .GroupSearch .NameAttr )
621
624
if name == "" {
622
625
// Be obnoxious about missing attributes. If the group entry is
623
626
// missing its name attribute, that indicates a misconfiguration.
0 commit comments