feat: 修改LDAP用户同步 增加用户属性映射

This commit is contained in:
wangzhengkun
2021-11-30 15:22:34 +08:00
parent ed4e32c07a
commit 44b818f653
7 changed files with 94 additions and 28 deletions

View File

@@ -35,12 +35,11 @@ func (l *Ldap) Connect() error {
return nil
}
func (l *Ldap) Search(dn, filter string) ([]*ldap.Entry, error) {
func (l *Ldap) Search(dn, filter string, attributes []string) ([]*ldap.Entry, error) {
searchRequest := ldap.NewSearchRequest(dn,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
filter,
[]string{"cn", "mail", "sAMAccountName"},
attributes,
nil)
sr, err := l.Conn.Search(searchRequest)
if err != nil {
@@ -53,11 +52,10 @@ func (l *Ldap) Search(dn, filter string) ([]*ldap.Entry, error) {
return sr.Entries, err
}
func (l *Ldap) Login(dn ,username,password string) error {
func (l *Ldap) Login(dn, filter, password string) error {
searchRequest := ldap.NewSearchRequest(dn,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=organizationalPerson)(cn=%s))", username),
filter,
[]string{"dn", "cn", "uid"},
nil)
sr, err := l.Conn.Search(searchRequest)