How to use the djangosaml2.utils.fail_acs_response function in djangosaml2

To help you get started, we’ve selected a few djangosaml2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudera / hue / desktop / core / ext-py / djangosaml2-0.16.4 / djangosaml2 / views.py View on Github external
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 MissingKey:
        logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
        return fail_acs_response(request)
github cloudera / hue / desktop / core / ext-py / djangosaml2-0.16.11 / djangosaml2 / views.py View on Github external
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 MissingKey:
        logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
        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,
github knaperek / djangosaml2 / djangosaml2 / views.py View on Github external
response = client.parse_authn_request_response(xmlstr, BINDING_HTTP_POST, outstanding_queries)
        except (StatusError, ToEarly) as e:
            logger.exception("Error processing SAML Assertion.")
            return fail_acs_response(request, exception=e)
        except ResponseLifetimeExceed as e:
            logger.info("SAML Assertion is no longer valid. Possibly caused by network delay or replay attack.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except SignatureError as e:
            logger.info("Invalid or malformed SAML Assertion.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except StatusAuthnFailed as e:
            logger.info("Authentication denied for user by IdP.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except StatusRequestDenied as e:
            logger.warning("Authentication interrupted at IdP.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except StatusNoAuthnContext as e:
            logger.warning("Missing Authentication Context from IdP.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except MissingKey as e:
            logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
            return fail_acs_response(request, exception=e)
        except UnsolicitedResponse as e:
            logger.exception("Received SAMLResponse when no request has been made.")
            return fail_acs_response(request, exception=e)

        if response is None:
            logger.warning("Invalid SAML Assertion received (unknown error).")
            return fail_acs_response(request, status=400, exception=SuspiciousOperation('Unknown SAML2 error'))

        session_id = response.session_id()
        oq_cache.delete(session_id)
github knaperek / djangosaml2 / djangosaml2 / views.py View on Github external
except StatusRequestDenied as e:
            logger.warning("Authentication interrupted at IdP.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except StatusNoAuthnContext as e:
            logger.warning("Missing Authentication Context from IdP.", exc_info=True)
            return fail_acs_response(request, exception=e)
        except MissingKey as e:
            logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
            return fail_acs_response(request, exception=e)
        except UnsolicitedResponse as e:
            logger.exception("Received SAMLResponse when no request has been made.")
            return fail_acs_response(request, exception=e)

        if response is None:
            logger.warning("Invalid SAML Assertion received (unknown error).")
            return fail_acs_response(request, status=400, exception=SuspiciousOperation('Unknown SAML2 error'))

        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,
github cloudera / hue / desktop / core / ext-py / djangosaml2-0.16.11 / djangosaml2 / views.py View on Github external
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 MissingKey:
        logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
        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()
github cloudera / hue / desktop / core / ext-py / djangosaml2-0.16.4 / djangosaml2 / views.py View on Github external
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 MissingKey:
        logger.exception("SAML Identity Provider is not configured correctly: certificate key is missing!")
        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,