Skip to content

Commit

Permalink
Update auth.py
Browse files Browse the repository at this point in the history
  • Loading branch information
grugna committed Dec 10, 2024
1 parent 1d4770a commit 444d6c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fence/authz/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from fence.errors import Forbidden, Unauthorized, NotFound
from fence.jwt.utils import get_jwt_header
from fence.config import config
from pcdcutils.gen3 import Gen3RequestManager


def check_arborist_auth(resource, method, constraints=None):
def check_arborist_auth(resource, method, constraints=None, check_signature=False):
"""
Check with arborist to verify the authz for a request.
Expand Down Expand Up @@ -47,7 +48,16 @@ def wrapper(*f_args, **f_kwargs):
methods=method,
resources=resource,
):
raise Forbidden("user does not have privileges to access this endpoint")
if check_signature:
g3rm = Gen3RequestManager(headers=flask.request.headers)
if g3rm.is_gen3_signed():
data = flask.request.get_json()
if not g3rm.valid_gen3_signature(json.dumps(data), config):
raise Forbidden("Gen3 signed request is invalid")
else:
raise Forbidden("user does not have privileges to access this endpoint and the signature is not present.")
else:
raise Forbidden("user does not have privileges to access this endpoint")
return f(*f_args, **f_kwargs)

return wrapper
Expand Down

0 comments on commit 444d6c0

Please sign in to comment.