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 } }