You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/05/30 21:25:51 UTC
[GitHub] rob05c closed pull request #2324: correct login status codes and
enhance ldap logging
rob05c closed pull request #2324: correct login status codes and enhance ldap logging
URL: https://github.com/apache/incubator-trafficcontrol/pull/2324
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/LICENSE b/LICENSE
index 487b432ae..76015096f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -436,3 +436,11 @@ For the siphash component:
For the miekg/dns component:
@traffic_ops/traffic_ops_golang/vendor/github.com/miekg/dns/*
./licenses/BSD-miekg-dns
+
+The asn1-ber.v1 component is used under the MIT license:
+@traffic_ops/vendor/gopkg.in/asn1-ber.v1/*
+./traffic_ops/vendor/gopkg.in/asn1-ber.v1/LICENSE
+
+The ldap.v2 component is used under the MIT license:
+@traffic_ops/vendor/gopkg.in/ldap.v2/*
+./traffic_ops/vendor/gopkg.in/ldap.v2/LICENSE
diff --git a/traffic_ops/traffic_ops_golang/auth/ldap.go b/traffic_ops/traffic_ops_golang/auth/ldap.go
index 9f8291c06..bb89ace9b 100644
--- a/traffic_ops/traffic_ops_golang/auth/ldap.go
+++ b/traffic_ops/traffic_ops_golang/auth/ldap.go
@@ -98,8 +98,10 @@ func LookupUserDN(username string, cfg *config.ConfigLDAP) (string, bool, error)
return "", false, err
}
- if len(sr.Entries) != 1 {
- return "", false, errors.New("User does not exist or too many entries returned")
+ if len(sr.Entries) < 1 {
+ return "", false, errors.New("User does not exist")
+ } else if len(sr.Entries) > 1 {
+ return "", false, errors.New("too many user entries returned")
}
userDN := sr.Entries[0].DN
return userDN, true, nil
diff --git a/traffic_ops/traffic_ops_golang/auth/login.go b/traffic_ops/traffic_ops_golang/auth/login.go
index 602159345..ecc95bfa5 100644
--- a/traffic_ops/traffic_ops_golang/auth/login.go
+++ b/traffic_ops/traffic_ops_golang/auth/login.go
@@ -47,6 +47,7 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
defer r.Body.Close()
+ authenticated := false
form := passwordForm{}
if err := json.NewDecoder(r.Body).Decode(&form); err != nil {
handleErrs(http.StatusBadRequest, err)
@@ -60,7 +61,7 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
log.Errorf("error checking local user: %s\n", err.Error())
}
if userAllowed {
- authenticated, err := checkLocalUserPassword(form, db)
+ authenticated, err = checkLocalUserPassword(form, db)
if err != nil {
log.Errorf("error checking local user password: %s\n", err.Error())
}
@@ -81,7 +82,6 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
resp = struct {
tc.Alerts
}{tc.CreateAlerts(tc.SuccessLevel, "Successfully logged in.")}
-
} else {
resp = struct {
tc.Alerts
@@ -97,8 +97,10 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
handleErrs(http.StatusInternalServerError, err)
return
}
-
w.Header().Set(tc.ContentType, tc.ApplicationJson)
+ if !authenticated {
+ w.WriteHeader(http.StatusUnauthorized)
+ }
fmt.Fprintf(w, "%s", respBts)
}
}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 693bc62db..16f5f0bae 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -128,7 +128,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
{1.1, http.MethodGet, `hwinfo-wip/?(\.json)?$`, hwinfo.HWInfoHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//Login
- {1.2, http.MethodPost, `user/login/?$`, auth.LoginHandler(d.DB, d.Config), 0, NoAuth, nil}, {1.3, http.MethodPost, `user/login/?$`, auth.LoginHandler(d.DB, d.Config), 0, NoAuth, nil},
+ {1.2, http.MethodPost, `user/login/?$`, wrapAccessLog(d.Secrets[0], auth.LoginHandler(d.DB, d.Config)), 0, NoAuth, nil}, {1.3, http.MethodPost, `user/login/?$`, auth.LoginHandler(d.DB, d.Config), 0, NoAuth, nil},
//Parameter: CRUD
{1.1, http.MethodGet, `parameters/?(\.json)?$`, api.ReadHandler(parameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services