Shares #109
4 changed files with 12 additions and 5 deletions
|
@ -12,13 +12,18 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrBadSubject = errors.New("bad subject in token")
|
ErrBadSubject = errors.New("bad subject in token")
|
||||||
|
ErrAccessDenied = errors.New("access denied")
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrAccessDenied(err error) *restrict.AccessDeniedError {
|
func IsErrAccessDenied(err error) error {
|
||||||
if accessErr, ok := err.(*restrict.AccessDeniedError); ok {
|
if accessErr, ok := err.(*restrict.AccessDeniedError); ok {
|
||||||
return accessErr
|
return accessErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err == ErrAccessDenied {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,5 +120,7 @@ func (r *rbac) Check(ctx context.Context, res restrict.Resource, opts ...CheckOp
|
||||||
Context: o.context,
|
Context: o.context,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sub, r.access.Authorize(req)
|
authRes := r.access.Authorize(req)
|
||||||
|
|
||||||
|
return sub, authRes
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ func autoError(err error) render.Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rbac.ErrAccessDenied(err) != nil {
|
if rbac.IsErrAccessDenied(err) != nil {
|
||||||
return forbiddenErrText(err)
|
return forbiddenErrText(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ func (s *postgresStore) Shares(ctx context.Context, p SharesParams) (shares []*S
|
||||||
case *entities.SystemServiceSubject:
|
case *entities.SystemServiceSubject:
|
||||||
owner = nil
|
owner = nil
|
||||||
default:
|
default:
|
||||||
return nil, 0, rbac.ErrAccessDenied(rbac.ErrNotAuthorized)
|
return nil, 0, rbac.ErrAccessDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
db := database.FromCtx(ctx)
|
db := database.FromCtx(ctx)
|
||||||
|
|
|
@ -134,7 +134,7 @@ func (h *RdioHTTP) routeCallUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
err = h.ing.Ingest(entities.CtxWithSubject(ctx, submitterSub), call)
|
err = h.ing.Ingest(entities.CtxWithSubject(ctx, submitterSub), call)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rbac.ErrAccessDenied(err) != nil {
|
if rbac.IsErrAccessDenied(err) != nil {
|
||||||
log.Error().Err(err).Msg("ingest failed")
|
log.Error().Err(err).Msg("ingest failed")
|
||||||
http.Error(w, "Call ingest failed.", http.StatusForbidden)
|
http.Error(w, "Call ingest failed.", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue