From 60f57d3be37eb824446a8f4b1ab1ce21fdaac25b Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Fri, 21 Jun 2024 15:22:46 +0200 Subject: [PATCH] backend: fix authentication --- backend.go | 3 ++- gofakes3.go | 4 ++++ routing.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend.go b/backend.go index e7998a2..6e51af9 100644 --- a/backend.go +++ b/backend.go @@ -325,7 +325,8 @@ type MultipartBackend interface { } type AuthenticatedBackend interface { - AuthenticateRequest(w http.ResponseWriter, r *http.Request, bucket string) bool + IsAuthenticated(w http.ResponseWriter, r *http.Request, bucket string) bool + AuthenticationMiddleware(handler http.Handler) http.Handler } // CopyObject is a helper function useful for quickly implementing CopyObject on diff --git a/gofakes3.go b/gofakes3.go index 81a4f0d..4c0090d 100644 --- a/gofakes3.go +++ b/gofakes3.go @@ -98,6 +98,10 @@ func (g *GoFakeS3) Server() http.Handler { } else if g.hostBucket { handler = g.hostBucketMiddleware(handler) } + + if ab, ok := g.storage.(AuthenticatedBackend); ok { + handler = ab.AuthenticationMiddleware(handler) + } return handler } diff --git a/routing.go b/routing.go index 8305385..7728ac0 100644 --- a/routing.go +++ b/routing.go @@ -31,7 +31,7 @@ func (g *GoFakeS3) routeBase(w http.ResponseWriter, r *http.Request) { // perform authentication if necessary ab, ok := g.storage.(AuthenticatedBackend) if ok { - if !ab.AuthenticateRequest(w, r, bucket) { + if !ab.IsAuthenticated(w, r, bucket) { return // unable to authenticate } }