🥅 Align LDAP auth errors with regular auth errors.

This commit is contained in:
Daniel Aloni 2023-05-02 15:11:51 +03:00
parent 3e471fcf86
commit a6b8ea963d

View file

@ -268,18 +268,40 @@ func (t *LoginTypePassword) authenticateLdap(username, password string) (bool, *
userDN := result.Entries[0].DN
err = conn.Bind(userDN, password)
if err != nil {
var localpart string
localpart, _, err = userutil.ParseUsernameParam(username, t.Config.Matrix)
if err != nil {
return false, &util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: jsonerror.InvalidUsername(err.Error()),
}
}
if t.Rt != nil {
t.Rt.Act(localpart)
}
return false, &util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: jsonerror.InvalidUsername(err.Error()),
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("The username or password was incorrect or the account does not exist."),
}
}
} else {
bindDn := strings.ReplaceAll(t.Config.Ldap.UserBindDn, "{username}", username)
err = conn.Bind(bindDn, password)
if err != nil {
var localpart string
localpart, _, err = userutil.ParseUsernameParam(username, t.Config.Matrix)
if err != nil {
return false, &util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: jsonerror.InvalidUsername(err.Error()),
}
}
if t.Rt != nil {
t.Rt.Act(localpart)
}
return false, &util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: jsonerror.InvalidUsername(err.Error()),
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("The username or password was incorrect or the account does not exist."),
}
}
}