forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usernamemapper.go
32 lines (26 loc) · 952 Bytes
/
usernamemapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package syncgroups
import (
"fmt"
"gopkg.in/ldap.v2"
"github.com/openshift/origin/pkg/auth/ldaputil"
"github.com/openshift/origin/pkg/cmd/admin/groups/sync/interfaces"
)
// NewUserNameMapper returns a new DefaultLDAPGroupUserNameMapper
func NewUserNameMapper(nameAttributes []string) interfaces.LDAPUserNameMapper {
return &DefaultLDAPUserNameMapper{
nameAttributes: nameAttributes,
}
}
// DefaultLDAPUserNameMapper extracts the OpenShift User name of an LDAP entry representing
// a user in a deterministic manner
type DefaultLDAPUserNameMapper struct {
nameAttributes []string
}
func (m *DefaultLDAPUserNameMapper) UserNameFor(ldapUser *ldap.Entry) (string, error) {
openShiftUserName := ldaputil.GetAttributeValue(ldapUser, m.nameAttributes)
if len(openShiftUserName) == 0 {
return "", fmt.Errorf("the user entry (%v) does not map to a OpenShift User name with the given mapping",
ldapUser)
}
return openShiftUserName, nil
}