Merge pull request #71 from globekeeper/daniel/align-auth-errors

🥅 Align LDAP auth errors with regular auth errors.
This commit is contained in:
Daniel Aloni 2023-05-02 15:37:19 +03:00 committed by GitHub
commit ad15eb8bd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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."),
}
}
}