diff options
Diffstat (limited to 'internal/handlers/handler_authz_impl_authrequest.go')
| -rw-r--r-- | internal/handlers/handler_authz_impl_authrequest.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/handlers/handler_authz_impl_authrequest.go b/internal/handlers/handler_authz_impl_authrequest.go new file mode 100644 index 000000000..19292201f --- /dev/null +++ b/internal/handlers/handler_authz_impl_authrequest.go @@ -0,0 +1,42 @@ +package handlers + +import ( + "fmt" + "net/url" + + "github.com/valyala/fasthttp" + + "github.com/authelia/authelia/v4/internal/authorization" + "github.com/authelia/authelia/v4/internal/middlewares" +) + +func handleAuthzGetObjectAuthRequest(ctx *middlewares.AutheliaCtx) (object authorization.Object, err error) { + var ( + targetURL *url.URL + + rawURL, method []byte + ) + + if rawURL = ctx.XOriginalURL(); len(rawURL) == 0 { + return object, middlewares.ErrMissingXOriginalURL + } + + if targetURL, err = url.ParseRequestURI(string(rawURL)); err != nil { + return object, fmt.Errorf("failed to parse X-Original-URL header: %w", err) + } + + if method = ctx.XOriginalMethod(); len(method) == 0 { + return object, fmt.Errorf("header 'X-Original-Method' is empty") + } + + if hasInvalidMethodCharacters(method) { + return object, fmt.Errorf("header 'X-Original-Method' with value '%s' has invalid characters", method) + } + + return authorization.NewObjectRaw(targetURL, method), nil +} + +func handleAuthzUnauthorizedAuthRequest(ctx *middlewares.AutheliaCtx, authn *Authn, _ *url.URL) { + ctx.Logger.Infof("Access to %s (method %s) is not authorized to user %s, responding with status code %d", authn.Object.URL.String(), authn.Method, authn.Username, fasthttp.StatusUnauthorized) + ctx.ReplyUnauthorized() +} |
