mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Fix LDAP server bugs
This commit is contained in:
@ -53,7 +53,7 @@ func handleBind(w ldap.ResponseWriter, m *ldap.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bindPassword := string(r.AuthenticationSimple())
|
bindPassword := string(r.AuthenticationSimple())
|
||||||
bindUser, err := object.CheckUserPassword(object.CasdoorOrganization, bindUsername, bindPassword, "en")
|
bindUser, err := object.CheckUserPassword(bindOrg, bindUsername, bindPassword, "en")
|
||||||
if err != "" {
|
if err != "" {
|
||||||
log.Printf("Bind failed User=%s, Pass=%#v, ErrMsg=%s", string(r.Name()), r.Authentication(), err)
|
log.Printf("Bind failed User=%s, Pass=%#v, ErrMsg=%s", string(r.Name()), r.Authentication(), err)
|
||||||
res.SetResultCode(ldap.LDAPResultInvalidCredentials)
|
res.SetResultCode(ldap.LDAPResultInvalidCredentials)
|
||||||
|
11
ldap/util.go
11
ldap/util.go
@ -56,12 +56,19 @@ func getNameAndOrgFromFilter(baseDN, filter string) (string, string, int) {
|
|||||||
|
|
||||||
func getUsername(filter string) string {
|
func getUsername(filter string) string {
|
||||||
nameIndex := strings.Index(filter, "cn=")
|
nameIndex := strings.Index(filter, "cn=")
|
||||||
|
if nameIndex == -1 {
|
||||||
|
nameIndex = strings.Index(filter, "uid=")
|
||||||
if nameIndex == -1 {
|
if nameIndex == -1 {
|
||||||
return "*"
|
return "*"
|
||||||
|
} else {
|
||||||
|
nameIndex += 4
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nameIndex += 3
|
||||||
}
|
}
|
||||||
|
|
||||||
var name string
|
var name string
|
||||||
for i := nameIndex + 3; filter[i] != ')'; i++ {
|
for i := nameIndex; filter[i] != ')'; i++ {
|
||||||
name = name + string(filter[i])
|
name = name + string(filter[i])
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
@ -125,6 +132,8 @@ func getAttribute(attributeName string, user *object.User) message.AttributeValu
|
|||||||
return message.AttributeValue(user.Name)
|
return message.AttributeValue(user.Name)
|
||||||
case "email":
|
case "email":
|
||||||
return message.AttributeValue(user.Email)
|
return message.AttributeValue(user.Email)
|
||||||
|
case "mail":
|
||||||
|
return message.AttributeValue(user.Email)
|
||||||
case "mobile":
|
case "mobile":
|
||||||
return message.AttributeValue(user.Phone)
|
return message.AttributeValue(user.Phone)
|
||||||
case "userPassword":
|
case "userPassword":
|
||||||
|
Reference in New Issue
Block a user