# Path: atlassian_jwt_auth/frameworks/django/decorators.py
# def with_asap(func=None, issuers=None, required=None,
#               subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authentication.
# 
#     If authentication fails, a 401 or 403 response will be returned. Otherwise,
#     the decorated function will be executed.
# 
#     The ASAP claimset will be set on request.asap_claims for further
#     inspection later in the request lifecycle.
# 
#     :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 _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,
#         subject_should_match_issuer=None
#     )
# 
# Path: atlassian_jwt_auth/contrib/django/decorators.py
# def requires_asap(issuers=None, subject_should_match_issuer=None, func=None):
#     """Decorator for Django endpoints to require ASAP
# 
#     :param list issuers: *required The 'iss' claims that this endpoint is from.
#     """
#     return with_asap(func=func,
#                      required=True,
#                      issuers=issuers,
#                      subject_should_match_issuer=subject_should_match_issuer)
# 
# def validate_asap(issuers=None, subjects=None, required=True):
#     """Decorator to allow endpoint-specific ASAP authorization, assuming ASAP
#     authentication has already occurred.
# 
#     :param list issuers: A list of issuers that are allowed to use the
#         endpoint.
#     :param list subjects: A list of subjects that are allowed to use the
#         endpoint.
#     :param boolean required: Whether or not to require ASAP on this endpoint.
#         Note that requirements will be still be verified if claims are present.
#     """
#     def validate_asap_decorator(func):
#         @wraps(func)
#         def validate_asap_wrapper(request, *args, **kwargs):
#             asap_claims = getattr(request, 'asap_claims', None)
#             if required and not asap_claims:
#                 message = 'Unauthorized: Invalid or missing token'
#                 response = HttpResponse(message, status=401)
#                 response['WWW-Authenticate'] = 'Bearer'
#                 return response
# 
#             if asap_claims:
#                 iss = asap_claims['iss']
#                 if issuers and iss not in issuers:
#                     message = 'Forbidden: Invalid token issuer'
#                     return HttpResponse(message, status=403)
# 
#                 sub = asap_claims.get('sub')
#                 if subjects and sub not in subjects:
#                     message = 'Forbidden: Invalid token subject'
#                     return HttpResponse(message, status=403)
# 
#             return func(request, *args, **kwargs)
# 
#         return validate_asap_wrapper
#     return validate_asap_decorator


from django.http import HttpResponse
from atlassian_jwt_auth.frameworks.django import with_asap, restrict_asap
from atlassian_jwt_auth.contrib.django.decorators import (requires_asap,
                                                          validate_asap)
@with_asap(issuers=['whitelist'])
def decorated_view(request):
    return HttpResponse('Only the right issuer is allowed.')


@requires_asap()
def settings_view(request):
    return HttpResponse('Any settings issuer is allowed.')


@with_asap(subject_should_match_issuer=False)
def subject_does_not_need_to_match_issuer_view(request):
    return HttpResponse('Subject does not need to match issuer.')


@with_asap(subject_should_match_issuer=True)
def subject_does_need_to_match_issuer_view(request):
    return HttpResponse('Subject does need to match issuer.')


@with_asap()
def subject_does_not_need_to_match_issuer_from_settings_view(request):
    return HttpResponse('Subject does not need to match issuer (settings).')


@restrict_asap
def needed_view(request):
    return HttpResponse('one')



# Path: atlassian_jwt_auth/frameworks/django/decorators.py
# def with_asap(func=None, issuers=None, required=None,
#               subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authentication.
# 
#     If authentication fails, a 401 or 403 response will be returned. Otherwise,
#     the decorated function will be executed.
# 
#     The ASAP claimset will be set on request.asap_claims for further
#     inspection later in the request lifecycle.
# 
#     :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 _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,
#         subject_should_match_issuer=None
#     )
# 
# Path: atlassian_jwt_auth/contrib/django/decorators.py
# def requires_asap(issuers=None, subject_should_match_issuer=None, func=None):
#     """Decorator for Django endpoints to require ASAP
# 
#     :param list issuers: *required The 'iss' claims that this endpoint is from.
#     """
#     return with_asap(func=func,
#                      required=True,
#                      issuers=issuers,
#                      subject_should_match_issuer=subject_should_match_issuer)
# 
# def validate_asap(issuers=None, subjects=None, required=True):
#     """Decorator to allow endpoint-specific ASAP authorization, assuming ASAP
#     authentication has already occurred.
# 
#     :param list issuers: A list of issuers that are allowed to use the
#         endpoint.
#     :param list subjects: A list of subjects that are allowed to use the
#         endpoint.
#     :param boolean required: Whether or not to require ASAP on this endpoint.
#         Note that requirements will be still be verified if claims are present.
#     """
#     def validate_asap_decorator(func):
#         @wraps(func)
#         def validate_asap_wrapper(request, *args, **kwargs):
#             asap_claims = getattr(request, 'asap_claims', None)
#             if required and not asap_claims:
#                 message = 'Unauthorized: Invalid or missing token'
#                 response = HttpResponse(message, status=401)
#                 response['WWW-Authenticate'] = 'Bearer'
#                 return response
# 
#             if asap_claims:
#                 iss = asap_claims['iss']
#                 if issuers and iss not in issuers:
#                     message = 'Forbidden: Invalid token issuer'
#                     return HttpResponse(message, status=403)
# 
#                 sub = asap_claims.get('sub')
#                 if subjects and sub not in subjects:
#                     message = 'Forbidden: Invalid token subject'
#                     return HttpResponse(message, status=403)
# 
#             return func(request, *args, **kwargs)
# 
#         return validate_asap_wrapper
#     return validate_asap_decorator


# Path: atlassian_jwt_auth/frameworks/django/tests/views.py
from django.http import HttpResponse
from atlassian_jwt_auth.frameworks.django import with_asap, restrict_asap
from atlassian_jwt_auth.contrib.django.decorators import (requires_asap,
                                                          validate_asap)

@with_asap(issuers=['whitelist'])
def decorated_view(request):
    return HttpResponse('Only the right issuer is allowed.')


@requires_asap()
def settings_view(request):
    return HttpResponse('Any settings issuer is allowed.')


@with_asap(subject_should_match_issuer=False)
def subject_does_not_need_to_match_issuer_view(request):
    return HttpResponse('Subject does not need to match issuer.')


@with_asap(subject_should_match_issuer=True)
def subject_does_need_to_match_issuer_view(request):
    return HttpResponse('Subject does need to match issuer.')


@with_asap()
def subject_does_not_need_to_match_issuer_from_settings_view(request):
    return HttpResponse('Subject does not need to match issuer (settings).')


@restrict_asap
def needed_view(request):
    return HttpResponse('one')



@restrict_asap(required=False)