aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/authz/middleware.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/internal/authz/middleware.go b/internal/authz/middleware.go
index 9031c99..f4838ec 100644
--- a/internal/authz/middleware.go
+++ b/internal/authz/middleware.go
@@ -21,6 +21,7 @@ var (
func Authentication(authMap TokenMap, next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
+ slog.Info("access request recv")
u, p, ok := req.BasicAuth()
if !ok {
rw.Header().Set("WWW-Authenticate", `Basic realm="git"`)
@@ -30,6 +31,7 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler {
urn := fmt.Sprintf("uid:%s", u)
hash, ok := authMap[urn]
if !ok {
+ slog.Info("failed access", "urn", urn)
http.Error(rw, "Bad Request", http.StatusForbidden)
return
}
@@ -39,10 +41,12 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler {
return
}
if err := bcrypt.CompareHashAndPassword([]byte(hash), token); err != nil {
+ slog.Info("bad token for user", "urn", urn)
http.Error(rw, "Bad Request", http.StatusForbidden)
return
}
ctx := context.WithValue(req.Context(), AuthzUrnKey, urn)
+ slog.Info("access request granted", "urn", urn)
next.ServeHTTP(rw, req.WithContext(ctx))
})
}