diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-28 18:38:16 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-28 18:38:16 +0300 |
commit | 5f971520a50d3bd7b3b565a673c185b00f0df680 (patch) | |
tree | f3200b170ec06b35841e6a5564bad5e278536bd0 /internal/auth | |
parent | 08d70aef345f1811f13cc990529f5114ccf3a92e (diff) |
refactor: move acl to auth package and update function signature
Diffstat (limited to 'internal/auth')
-rw-r--r-- | internal/auth/middleware.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/internal/auth/middleware.go b/internal/auth/middleware.go index 263e48b8..4eb1e943 100644 --- a/internal/auth/middleware.go +++ b/internal/auth/middleware.go @@ -3,11 +3,12 @@ package auth import ( "net/http" + "gitlab.com/gitlab-org/gitlab-pages/internal/request" "gitlab.com/gitlab-org/gitlab-pages/internal/source" ) // NewMiddleware returns middleware which handles authentication requests -func NewMiddleware(handler http.Handler, a *Auth, s source.Source) http.Handler { +func (a *Auth) AuthenticationMiddleware(handler http.Handler, s source.Source) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if a.TryAuthenticate(w, r, s) { return @@ -16,3 +17,20 @@ func NewMiddleware(handler http.Handler, a *Auth, s source.Source) http.Handler handler.ServeHTTP(w, r) }) } + +// NewMiddleware returns middleware which handle authorization +func (a *Auth) AuthorizationMiddleware(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + domain := request.GetDomain(r) + + // Only for projects that have access control enabled + if domain.IsAccessControlEnabled(r) { + // accessControlMiddleware + if a.CheckAuthentication(w, r, domain) { + return + } + } + + handler.ServeHTTP(w, r) + }) +} |