From 34a890ec58012b336b5a5c0a9fcf5dc0e23c4b3f Mon Sep 17 00:00:00 2001 From: Liron Levin Date: Mon, 2 May 2016 11:54:09 +0300 Subject: [PATCH] Fix authorization issue - when request is denied return forbbiden exist code (403). - Return 403 (forbidden) when request is denied in authorization flows (including integration test) - Fix #22428 - Close #22431 Signed-off-by: Liron Levin --- authorization/authz.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/authorization/authz.go b/authorization/authz.go index f703908..08d3e2c 100644 --- a/authorization/authz.go +++ b/authorization/authz.go @@ -85,7 +85,7 @@ func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error { } if !authRes.Allow { - return fmt.Errorf("authorization denied by plugin %s: %s", plugin.Name(), authRes.Msg) + return newAuthorizationError(plugin.Name(), authRes.Msg) } } @@ -110,7 +110,7 @@ func (ctx *Ctx) AuthZResponse(rm ResponseModifier, r *http.Request) error { } if !authRes.Allow { - return fmt.Errorf("authorization denied by plugin %s: %s", plugin.Name(), authRes.Msg) + return newAuthorizationError(plugin.Name(), authRes.Msg) } } @@ -163,3 +163,17 @@ func headers(header http.Header) map[string]string { } return v } + +// authorizationError represents an authorization deny error +type authorizationError struct { + error +} + +// HTTPErrorStatusCode returns the authorization error status code (forbidden) +func (e authorizationError) HTTPErrorStatusCode() int { + return http.StatusForbidden +} + +func newAuthorizationError(plugin, msg string) authorizationError { + return authorizationError{error: fmt.Errorf("authorization denied by plugin %s: %s", plugin, msg)} +}