本文整理匯總了Python中djangosaml2.cache.OutstandingQueriesCache.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python OutstandingQueriesCache.delete方法的具體用法?Python OutstandingQueriesCache.delete怎麽用?Python OutstandingQueriesCache.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類djangosaml2.cache.OutstandingQueriesCache
的用法示例。
在下文中一共展示了OutstandingQueriesCache.delete方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: assertion_consumer_service
# 需要導入模塊: from djangosaml2.cache import OutstandingQueriesCache [as 別名]
# 或者: from djangosaml2.cache.OutstandingQueriesCache import delete [as 別名]
def assertion_consumer_service(request, config_loader_path=None, attribute_mapping=None, create_unknown_user=None):
"""SAML Authorization Response endpoint
The IdP will send its response to this view, which
will process it with pysaml2 help and log the user
in using the custom Authorization backend
djangosaml2.backends.Saml2Backend that should be
enabled in the settings.py
"""
attribute_mapping = attribute_mapping or get_custom_setting("SAML_ATTRIBUTE_MAPPING", {"uid": ("username",)})
create_unknown_user = create_unknown_user or get_custom_setting("SAML_CREATE_UNKNOWN_USER", True)
logger.debug("Assertion Consumer Service started")
conf = get_config(config_loader_path, request)
if "SAMLResponse" not in request.POST:
return HttpResponseBadRequest('Couldn\'t find "SAMLResponse" in POST data.')
post = {"SAMLResponse": request.POST["SAMLResponse"]}
client = Saml2Client(conf, identity_cache=IdentityCache(request.session), logger=logger)
oq_cache = OutstandingQueriesCache(request.session)
outstanding_queries = oq_cache.outstanding_queries()
# process the authentication response
response = client.response(post, outstanding_queries)
if response is None:
logger.error("SAML response is None")
return HttpResponseBadRequest("SAML response has errors. Please check the logs")
session_id = response.session_id()
oq_cache.delete(session_id)
# authenticate the remote user
session_info = response.session_info()
if callable(attribute_mapping):
attribute_mapping = attribute_mapping()
if callable(create_unknown_user):
create_unknown_user = create_unknown_user()
logger.debug("Trying to authenticate the user")
user = auth.authenticate(
session_info=session_info, attribute_mapping=attribute_mapping, create_unknown_user=create_unknown_user
)
if user is None:
logger.error("The user is None")
return HttpResponseForbidden("Permission denied")
auth.login(request, user)
_set_subject_id(request.session, session_info["name_id"])
logger.debug("Sending the post_authenticated signal")
post_authenticated.send_robust(sender=user, session_info=session_info)
# redirect the user to the view where he came from
relay_state = request.POST.get("RelayState", "/")
if not relay_state:
logger.warning("The RelayState parameter exists but is empty")
relay_state = settings.LOGIN_REDIRECT_URL
logger.debug("Redirecting to the RelayState: " + relay_state)
return HttpResponseRedirect(relay_state)
示例2: assertion_consumer_service
# 需要導入模塊: from djangosaml2.cache import OutstandingQueriesCache [as 別名]
# 或者: from djangosaml2.cache.OutstandingQueriesCache import delete [as 別名]
def assertion_consumer_service(request,
config_loader_path=None,
attribute_mapping=None,
create_unknown_user=None):
"""SAML Authorization Response endpoint
The IdP will send its response to this view, which
will process it with pysaml2 help and log the user
in using the custom Authorization backend
djangosaml2.backends.Saml2Backend that should be
enabled in the settings.py
"""
attribute_mapping = attribute_mapping or get_custom_setting('SAML_ATTRIBUTE_MAPPING', {'uid': ('username', )})
create_unknown_user = create_unknown_user if create_unknown_user is not None else \
get_custom_setting('SAML_CREATE_UNKNOWN_USER', True)
conf = get_config(config_loader_path, request)
try:
xmlstr = request.POST['SAMLResponse']
except KeyError:
logger.warning('Missing "SAMLResponse" parameter in POST data.')
raise SuspiciousOperation
client = Saml2Client(conf, identity_cache=IdentityCache(request.session))
oq_cache = OutstandingQueriesCache(request.session)
outstanding_queries = oq_cache.outstanding_queries()
try:
response = client.parse_authn_request_response(xmlstr, BINDING_HTTP_POST, outstanding_queries)
except (StatusError, ToEarly):
logger.exception("Error processing SAML Assertion.")
return fail_acs_response(request)
except ResponseLifetimeExceed:
logger.info("SAML Assertion is no longer valid. Possibly caused by network delay or replay attack.", exc_info=True)
return fail_acs_response(request)
except SignatureError:
logger.info("Invalid or malformed SAML Assertion.", exc_info=True)
return fail_acs_response(request)
except StatusAuthnFailed:
logger.info("Authentication denied for user by IdP.", exc_info=True)
return fail_acs_response(request)
except StatusRequestDenied:
logger.warning("Authentication interrupted at IdP.", exc_info=True)
return fail_acs_response(request)
except StatusNoAuthnContext:
logger.warning("Missing Authentication Context from IdP.", exc_info=True)
return fail_acs_response(request)
except MissingKey:
logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
return fail_acs_response(request)
except UnsolicitedResponse:
logger.exception("Received SAMLResponse when no request has been made.")
return fail_acs_response(request)
if response is None:
logger.warning("Invalid SAML Assertion received (unknown error).")
return fail_acs_response(request, status=400, exc_class=SuspiciousOperation)
session_id = response.session_id()
oq_cache.delete(session_id)
# authenticate the remote user
session_info = response.session_info()
if callable(attribute_mapping):
attribute_mapping = attribute_mapping()
if callable(create_unknown_user):
create_unknown_user = create_unknown_user()
logger.debug('Trying to authenticate the user. Session info: %s', session_info)
user = auth.authenticate(request=request,
session_info=session_info,
attribute_mapping=attribute_mapping,
create_unknown_user=create_unknown_user)
if user is None:
logger.warning("Could not authenticate user received in SAML Assertion. Session info: %s", session_info)
raise PermissionDenied
auth.login(request, user)
_set_subject_id(request.session, session_info['name_id'])
logger.debug("User %s authenticated via SSO.", user)
logger.debug('Sending the post_authenticated signal')
post_authenticated.send_robust(sender=user, session_info=session_info)
# redirect the user to the view where he came from
default_relay_state = get_custom_setting('ACS_DEFAULT_REDIRECT_URL',
settings.LOGIN_REDIRECT_URL)
relay_state = request.POST.get('RelayState', default_relay_state)
if not relay_state:
logger.warning('The RelayState parameter exists but is empty')
relay_state = default_relay_state
if not is_safe_url_compat(url=relay_state, allowed_hosts={request.get_host()}):
relay_state = settings.LOGIN_REDIRECT_URL
logger.debug('Redirecting to the RelayState: %s', relay_state)
return HttpResponseRedirect(relay_state)
示例3: assertion_consumer_service
# 需要導入模塊: from djangosaml2.cache import OutstandingQueriesCache [as 別名]
# 或者: from djangosaml2.cache.OutstandingQueriesCache import delete [as 別名]
def assertion_consumer_service(request,
config_loader_path=None,
attribute_mapping=None,
create_unknown_user=None):
"""SAML Authorization Response endpoint
The IdP will send its response to this view, which
will process it with pysaml2 help and log the user
in using the custom Authorization backend
djangosaml2.backends.Saml2Backend that should be
enabled in the settings.py
"""
attribute_mapping = attribute_mapping or get_custom_setting(
'SAML_ATTRIBUTE_MAPPING', {'uid': ('username', )})
create_unknown_user = create_unknown_user or get_custom_setting(
'SAML_CREATE_UNKNOWN_USER', True)
logger.debug('Assertion Consumer Service started')
conf = get_config(config_loader_path, request)
if 'SAMLResponse' not in request.POST:
return HttpResponseBadRequest(
'Couldn\'t find "SAMLResponse" in POST data.')
xmlstr = request.POST['SAMLResponse']
client = Saml2Client(conf, identity_cache=IdentityCache(request.session))
oq_cache = OutstandingQueriesCache(request.session)
outstanding_queries = oq_cache.outstanding_queries()
# process the authentication response
response = client.parse_authn_request_response(xmlstr, BINDING_HTTP_POST,
outstanding_queries)
if response is None:
logger.error('SAML response is None')
return HttpResponseBadRequest(
"SAML response has errors. Please check the logs")
session_id = response.session_id()
oq_cache.delete(session_id)
# authenticate the remote user
session_info = response.session_info()
if callable(attribute_mapping):
attribute_mapping = attribute_mapping()
if callable(create_unknown_user):
create_unknown_user = create_unknown_user()
logger.debug('Trying to authenticate the user')
user = auth.authenticate(session_info=session_info,
attribute_mapping=attribute_mapping,
create_unknown_user=create_unknown_user)
if user is None:
logger.error('The user is None')
return HttpResponseForbidden("Permission denied")
auth.login(request, user)
_set_subject_id(request.session, session_info['name_id'])
logger.debug('Sending the post_authenticated signal')
post_authenticated.send_robust(sender=user, session_info=session_info)
# redirect the user to the view where he came from
default_relay_state = get_custom_setting('ACS_DEFAULT_REDIRECT_URL',
settings.LOGIN_REDIRECT_URL)
relay_state = request.POST.get('RelayState', default_relay_state)
if not relay_state:
logger.warning('The RelayState parameter exists but is empty')
relay_state = default_relay_state
logger.debug('Redirecting to the RelayState: %s', relay_state)
return HttpResponseRedirect(relay_state)
示例4: assertion_consumer_service_view
# 需要導入模塊: from djangosaml2.cache import OutstandingQueriesCache [as 別名]
# 或者: from djangosaml2.cache.OutstandingQueriesCache import delete [as 別名]
def assertion_consumer_service_view(request,
config_loader_path=None,
attribute_mapping=None,
create_unknown_user=None):
"""SAML Authorization Response endpoint
The IdP will send its response to this view, which
will process it with pysaml2 help and log the user
in using the custom Authorization backend
djangosaml2.backends.Saml2Backend that should be
enabled in the settings.py
"""
logger.debug('Assertion Consumer Service started')
attribute_mapping = attribute_mapping or get_custom_setting(
'SAML_ATTRIBUTE_MAPPING', {'uid': ('username', )})
create_unknown_user = create_unknown_user or get_custom_setting(
'SAML_CREATE_UNKNOWN_USER', True)
logger.debug('Assertion Consumer Service started')
conf = get_config(config_loader_path, request)
if 'SAMLResponse' not in request.POST:
return HttpResponseBadRequest(
'Couldn\'t find "SAMLResponse" in POST data.')
post = {'SAMLResponse': request.POST['SAMLResponse']}
client = Saml2Client(conf, identity_cache=IdentityCache(request.session),
logger=logger)
oq_cache = OutstandingQueriesCache(request.session)
outstanding_queries = oq_cache.outstanding_queries()
# process the authentication response
try:
response = client.response(post, outstanding_queries)
except Exception as e:
logger.error('Error while authenticating. %s' % e)
return HttpResponseRedirect('/saml2/login_error')
if response is None:
logger.error('SAML response is None')
return HttpResponse("SAML response has errors. Please check the logs")
session_id = response.session_id()
oq_cache.delete(session_id)
# authenticate the remote user
session_info = response.session_info()
if callable(attribute_mapping):
attribute_mapping = attribute_mapping()
if callable(create_unknown_user):
create_unknown_user = create_unknown_user()
logger.debug('Trying to authenticate the user')
try:
user = auth.authenticate(session_info=session_info,
attribute_mapping=attribute_mapping,
create_unknown_user=create_unknown_user)
except Exception as e:
logger.error('Error while authenticating. %s' % e)
return HttpResponseRedirect('/saml2/login_error')
if user is None:
logger.error('The user is None')
return HttpResponseRedirect('/saml2/login_error')
#return HttpResponse("There were problems trying to authenticate the user")
auth.login(request, user)
_set_subject_id(request.session, session_info['name_id'])
_set_saml2_auth_used(request.session, True)
logger.debug('Sending the post_authenticated signal')
post_authenticated.send_robust(sender=user, session_info=session_info)
# redirect the user to the view where he came from
#relay_state = request.POST.get('RelayState', '/login')
relay_state = '/login'
logger.debug('Redirecting to the RelayState: ' + relay_state)
return HttpResponseRedirect(relay_state)