MSP-437 implement admin authz middleware
This commit is contained in:
1 parent
14995e91dd
commit
0367fa8ac7
1 file changed
+32
@@ -0,0 +1,32 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-gate-service/httperrors"
|
||||
"isp-gate-service/request"
|
||||
)
|
||||
|
||||
type AdminMethodStore interface {
|
||||
IsInnerMethod(path string) bool
|
||||
}
|
||||
|
||||
func AdminAuthorize(store AdminMethodStore) Middleware {
|
||||
return func(next Handler) Handler {
|
||||
return HandlerFunc(func(ctx *request.Context) error {
|
||||
isInner := store.IsInnerMethod(ctx.Endpoint())
|
||||
if !isInner {
|
||||
return next.Handle(ctx)
|
||||
}
|
||||
if ctx.IsAdminAuthenticated() {
|
||||
return next.Handle(ctx)
|
||||
}
|
||||
return httperrors.New(
|
||||
http.StatusForbidden,
|
||||
"admin authentication required",
|
||||
errors.Errorf("admin authorization: admin authentication required for '%s'", ctx.Endpoint()),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user