mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-19 23:28:20 +01:00
Merge pull request #154 from reasonerjt/master
adapt to other ldap servers
This commit is contained in:
commit
6e58528fbf
@ -76,31 +76,25 @@ func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
|||||||
|
|
||||||
scope := openldap.LDAP_SCOPE_SUBTREE // LDAP_SCOPE_BASE, LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE
|
scope := openldap.LDAP_SCOPE_SUBTREE // LDAP_SCOPE_BASE, LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE
|
||||||
filter := "objectClass=*"
|
filter := "objectClass=*"
|
||||||
attributes := []string{"cn", "mail", "uid"}
|
attributes := []string{"mail"}
|
||||||
|
|
||||||
result, err := ldap.SearchAll(baseDn, scope, filter, attributes)
|
result, err := ldap.SearchAll(baseDn, scope, filter, attributes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(result.Entries()) != 1 {
|
|
||||||
log.Warningf("Found more than one entry.")
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
en := result.Entries()[0]
|
|
||||||
u := models.User{}
|
u := models.User{}
|
||||||
for _, attr := range en.Attributes() {
|
if len(result.Entries()) == 1 {
|
||||||
val := attr.Values()[0]
|
en := result.Entries()[0]
|
||||||
switch attr.Name() {
|
for _, attr := range en.Attributes() {
|
||||||
case "uid":
|
val := attr.Values()[0]
|
||||||
u.Username = val
|
if attr.Name() == "mail" {
|
||||||
case "mail":
|
u.Email = val
|
||||||
u.Email = val
|
}
|
||||||
case "cn":
|
|
||||||
u.Realname = val
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("username:", u.Username, ",email:", u.Email, ",realname:", u.Realname)
|
u.Username = m.Principal
|
||||||
|
log.Debug("username:", u.Username, ",email:", u.Email)
|
||||||
|
|
||||||
exist, err := dao.UserExists(u, "username")
|
exist, err := dao.UserExists(u, "username")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -114,6 +108,7 @@ func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
|||||||
}
|
}
|
||||||
u.UserID = currentUser.UserID
|
u.UserID = currentUser.UserID
|
||||||
} else {
|
} else {
|
||||||
|
u.Realname = m.Principal
|
||||||
u.Password = "12345678AbC"
|
u.Password = "12345678AbC"
|
||||||
u.Comment = "registered from LDAP."
|
u.Comment = "registered from LDAP."
|
||||||
userID, err := dao.Register(u)
|
userID, err := dao.Register(u)
|
||||||
|
@ -74,16 +74,13 @@ func validate(user models.User) error {
|
|||||||
return errors.New("Username already exists.")
|
return errors.New("Username already exists.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if m, _ := regexp.MatchString(`^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$`, user.Email); !m {
|
if len(user.Email) > 0 {
|
||||||
return errors.New("Email with illegal format.")
|
if m, _ := regexp.MatchString(`^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$`, user.Email); !m {
|
||||||
}
|
return errors.New("Email with illegal format.")
|
||||||
|
}
|
||||||
if isIllegalLength(user.Email, 0, -1) {
|
if exist, _ := UserExists(models.User{Email: user.Email}, "email"); exist {
|
||||||
return errors.New("Email cannot empty.")
|
return errors.New("Email already exists.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if exist, _ := UserExists(models.User{Email: user.Email}, "email"); exist {
|
|
||||||
return errors.New("Email already exists.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isIllegalLength(user.Realname, 0, 20) {
|
if isIllegalLength(user.Realname, 0, 20) {
|
||||||
|
Loading…
Reference in New Issue
Block a user