# Path: atlassian_jwt_auth/frameworks/common/decorators.py
# def _with_asap(func=None, backend=None, issuers=None, required=True,
#                subject_should_match_issuer=None):
#     if backend is None:
#         raise ValueError(
#             'Invalid value for backend. Use a subclass instead.'
#         )
# 
#     def with_asap_decorator(func):
#         @wraps(func)
#         def with_asap_wrapper(*args, **kwargs):
#             settings = _update_settings_from_kwargs(
#                 backend.settings,
#                 issuers=issuers, required=required,
#                 subject_should_match_issuer=subject_should_match_issuer
#             )
# 
#             request = None
#             if len(args) > 0:
#                 request = args[0]
# 
#             error_response = _process_asap_token(
#                 request, backend, settings
#             )
# 
#             if error_response is not None:
#                 return error_response
# 
#             return func(*args, **kwargs)
# 
#         return with_asap_wrapper
# 
#     if callable(func):
#         return with_asap_decorator(func)
# 
#     return with_asap_decorator
# 
# def _restrict_asap(func=None, backend=None, issuers=None,
#                    required=True, subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authorization, assuming ASAP
#     authentication has already occurred.
#     """
# 
#     def restrict_asap_decorator(func):
#         @wraps(func)
#         def restrict_asap_wrapper(request, *args, **kwargs):
#             settings = _update_settings_from_kwargs(
#                 backend.settings,
#                 issuers=issuers, required=required,
#                 subject_should_match_issuer=subject_should_match_issuer
#             )
#             asap_claims = getattr(request, 'asap_claims', None)
#             error_response = None
# 
#             if required and not asap_claims:
#                 return backend.get_401_response(
#                     'Unauthorized', request=request
#                 )
# 
#             try:
#                 _verify_issuers(asap_claims, settings.ASAP_VALID_ISSUERS)
#             except InvalidIssuerError:
#                 error_response = backend.get_403_response(
#                     'Forbidden: Invalid token issuer', request=request
#                 )
#             except InvalidTokenError:
#                 error_response = backend.get_401_response(
#                     'Unauthorized: Invalid token', request=request
#                 )
# 
#             if error_response and required:
#                 return error_response
# 
#             return func(request, *args, **kwargs)
# 
#         return restrict_asap_wrapper
# 
#     if callable(func):
#         return restrict_asap_decorator(func)
# 
#     return restrict_asap_decorator
# 
# Path: atlassian_jwt_auth/frameworks/django/backend.py
# class DjangoBackend(Backend):
#     def get_authorization_header(self, request=None):
#         if request is None:
#             raise ValueError('No request available')
# 
#         return request.META.get('HTTP_AUTHORIZATION', b'')
# 
#     def get_401_response(self, data=None, headers=None, request=None):
#         if headers is None:
#             headers = {}
# 
#         headers.update(self.default_headers_401)
# 
#         response = HttpResponse(content=data, status=401)
#         for k, v in headers.items():
#             response[k] = v
# 
#         return response
# 
#     def get_403_response(self, data=None, headers=None, request=None):
#         if headers is None:
#             headers = {}
# 
#         response = HttpResponseForbidden(data)
#         for k, v in headers.items():
#             response[k] = v
# 
#         return response
# 
#     def set_asap_claims_for_request(self, request, claims):
#         request.asap_claims = claims
# 
#     @property
#     def settings(self):
#         settings = {}
#         settings.update(self.default_settings)
# 
#         for k in settings.keys():
#             value = getattr(django_settings, k, None)
#             if value is None:
#                 continue
# 
#             settings[k] = value
# 
#         return self._process_settings(settings)


from ..common.decorators import _with_asap, _restrict_asap
from .backend import DjangoBackend
    :param boolean subject_should_match_issuer: Indicate whether the subject
                                                must match the issuer for a
                                                token to be considered valid.
    """
    return _with_asap(
        func, DjangoBackend(), issuers, required,
        subject_should_match_issuer
    )


def restrict_asap(func=None, backend=None, issuers=None,
                  required=True, subject_should_match_issuer=None):
    """Decorator to allow endpoint-specific ASAP authorization policies.

    This decorator assumes that request.asap_claims has previously been set by
    the asap_middleware.

    If the token does not meet the requirements imposed by the decorator, a 401
    or 403 response will be returned. Otherwise, the decorated function will be
    executed.

    :param list func: The view to decorate.
    :param list issuers: A list of valid token issuers that can access this
                         endpoint.
    :param boolean required: Whether or not to require ASAP on this endpoint.
    :param boolean subject_should_match_issuer: Indicate whether the subject
                                                must match the issuer for a
                                                token to be considered valid.
    """
    return _restrict_asap(

# Path: atlassian_jwt_auth/frameworks/common/decorators.py
# def _with_asap(func=None, backend=None, issuers=None, required=True,
#                subject_should_match_issuer=None):
#     if backend is None:
#         raise ValueError(
#             'Invalid value for backend. Use a subclass instead.'
#         )
# 
#     def with_asap_decorator(func):
#         @wraps(func)
#         def with_asap_wrapper(*args, **kwargs):
#             settings = _update_settings_from_kwargs(
#                 backend.settings,
#                 issuers=issuers, required=required,
#                 subject_should_match_issuer=subject_should_match_issuer
#             )
# 
#             request = None
#             if len(args) > 0:
#                 request = args[0]
# 
#             error_response = _process_asap_token(
#                 request, backend, settings
#             )
# 
#             if error_response is not None:
#                 return error_response
# 
#             return func(*args, **kwargs)
# 
#         return with_asap_wrapper
# 
#     if callable(func):
#         return with_asap_decorator(func)
# 
#     return with_asap_decorator
# 
# def _restrict_asap(func=None, backend=None, issuers=None,
#                    required=True, subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authorization, assuming ASAP
#     authentication has already occurred.
#     """
# 
#     def restrict_asap_decorator(func):
#         @wraps(func)
#         def restrict_asap_wrapper(request, *args, **kwargs):
#             settings = _update_settings_from_kwargs(
#                 backend.settings,
#                 issuers=issuers, required=required,
#                 subject_should_match_issuer=subject_should_match_issuer
#             )
#             asap_claims = getattr(request, 'asap_claims', None)
#             error_response = None
# 
#             if required and not asap_claims:
#                 return backend.get_401_response(
#                     'Unauthorized', request=request
#                 )
# 
#             try:
#                 _verify_issuers(asap_claims, settings.ASAP_VALID_ISSUERS)
#             except InvalidIssuerError:
#                 error_response = backend.get_403_response(
#                     'Forbidden: Invalid token issuer', request=request
#                 )
#             except InvalidTokenError:
#                 error_response = backend.get_401_response(
#                     'Unauthorized: Invalid token', request=request
#                 )
# 
#             if error_response and required:
#                 return error_response
# 
#             return func(request, *args, **kwargs)
# 
#         return restrict_asap_wrapper
# 
#     if callable(func):
#         return restrict_asap_decorator(func)
# 
#     return restrict_asap_decorator
# 
# Path: atlassian_jwt_auth/frameworks/django/backend.py
# class DjangoBackend(Backend):
#     def get_authorization_header(self, request=None):
#         if request is None:
#             raise ValueError('No request available')
# 
#         return request.META.get('HTTP_AUTHORIZATION', b'')
# 
#     def get_401_response(self, data=None, headers=None, request=None):
#         if headers is None:
#             headers = {}
# 
#         headers.update(self.default_headers_401)
# 
#         response = HttpResponse(content=data, status=401)
#         for k, v in headers.items():
#             response[k] = v
# 
#         return response
# 
#     def get_403_response(self, data=None, headers=None, request=None):
#         if headers is None:
#             headers = {}
# 
#         response = HttpResponseForbidden(data)
#         for k, v in headers.items():
#             response[k] = v
# 
#         return response
# 
#     def set_asap_claims_for_request(self, request, claims):
#         request.asap_claims = claims
# 
#     @property
#     def settings(self):
#         settings = {}
#         settings.update(self.default_settings)
# 
#         for k in settings.keys():
#             value = getattr(django_settings, k, None)
#             if value is None:
#                 continue
# 
#             settings[k] = value
# 
#         return self._process_settings(settings)


# Path: atlassian_jwt_auth/frameworks/django/decorators.py
from ..common.decorators import _with_asap, _restrict_asap
from .backend import DjangoBackend

    :param boolean subject_should_match_issuer: Indicate whether the subject
                                                must match the issuer for a
                                                token to be considered valid.
    """
    return _with_asap(
        func, DjangoBackend(), issuers, required,
        subject_should_match_issuer
    )


def restrict_asap(func=None, backend=None, issuers=None,
                  required=True, subject_should_match_issuer=None):
    """Decorator to allow endpoint-specific ASAP authorization policies.

    This decorator assumes that request.asap_claims has previously been set by
    the asap_middleware.

    If the token does not meet the requirements imposed by the decorator, a 401
    or 403 response will be returned. Otherwise, the decorated function will be
    executed.

    :param list func: The view to decorate.
    :param list issuers: A list of valid token issuers that can access this
                         endpoint.
    :param boolean required: Whether or not to require ASAP on this endpoint.
    :param boolean subject_should_match_issuer: Indicate whether the subject
                                                must match the issuer for a
                                                token to be considered valid.
    """
    return _restrict_asap(

        func, DjangoBackend(), issuers, required,