Skip to content

Commit

Permalink
backend: fix authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jun 21, 2024
1 parent d7c039f commit 60f57d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 60f57d3

Please sign in to comment.