response.py

About this file

We attempted to read from templates/app_lib_onelogin_saml2_response.py_hw.txt but failed.

Code Check Report


app/lib/onelogin/saml2/response.py:14:121: E501 line too long (142 > 120 characters)
app/lib/onelogin/saml2/response.py:105:121: E501 line too long (135 > 120 characters)
app/lib/onelogin/saml2/response.py:114:121: E501 line too long (149 > 120 characters)
app/lib/onelogin/saml2/response.py:129:121: E501 line too long (160 > 120 characters)
app/lib/onelogin/saml2/response.py:167:121: E501 line too long (128 > 120 characters)
app/lib/onelogin/saml2/response.py:172:121: E501 line too long (152 > 120 characters)
app/lib/onelogin/saml2/response.py:233:121: E501 line too long (131 > 120 characters)
app/lib/onelogin/saml2/response.py:303:121: E501 line too long (131 > 120 characters)
app/lib/onelogin/saml2/response.py:307:121: E501 line too long (232 > 120 characters)
app/lib/onelogin/saml2/response.py:314:121: E501 line too long (245 > 120 characters)
app/lib/onelogin/saml2/response.py:378:121: E501 line too long (134 > 120 characters)
app/lib/onelogin/saml2/response.py:512:121: E501 line too long (122 > 120 characters)
app/lib/onelogin/saml2/response.py:683:121: E501 line too long (125 > 120 characters)
app/lib/onelogin/saml2/response.py:713:121: E501 line too long (152 > 120 characters)
app/lib/onelogin/saml2/response.py:718:121: E501 line too long (157 > 120 characters)
app/lib/onelogin/saml2/response.py:794:121: E501 line too long (137 > 120 characters)
app/lib/onelogin/saml2/response.py:796:121: E501 line too long (139 > 120 characters)
app/lib/onelogin/saml2/response.py:820:121: E501 line too long (136 > 120 characters)
                        

Documentation drawn from source code

OneLogin_Saml2_Response class

Copyright (c) 2010-2018 OneLogin, Inc.
MIT License

SAML Response class of OneLogin's Python Toolkit.


OneLogin_Saml2_Response(object):


This class handles a SAML Response. It parses or validates
a Logout Response object.


__init__(self, settings, response):

Constructs the response object.

:param settings: The setting info
:type settings: OneLogin_Saml2_Setting object

:param response: The base64 encoded, XML string containing the samlp:Response
:type response: string

is_valid(self, request_data, request_id=None, raise_exceptions=False):

Validates the response object.

:param request_data: Request Data
:type request_data: dict

:param request_id: Optional argument. The ID of the AuthNRequest sent by this SP to the IdP
:type request_id: string

:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean

:returns: True if the SAML Response is valid, False if not
:rtype: bool

check_status(self):

Check if the status of the response is success or not

:raises: Exception. If the status is not success

check_one_condition(self):

Checks that the samlp:Response/saml:Assertion/saml:Conditions element exists and is unique.

check_one_authnstatement(self):

Checks that the samlp:Response/saml:Assertion/saml:AuthnStatement element exists and is unique.

get_audiences(self):

Gets the audiences

:returns: The valid audiences for the SAML Response
:rtype: list

get_authn_contexts(self):

Gets the authentication contexts

:returns: The authentication classes for the SAML Response
:rtype: list

get_issuers(self):

Gets the issuers (from message and from assertion)

:returns: The issuers
:rtype: list

get_nameid_data(self):

Gets the NameID Data provided by the SAML Response from the IdP

:returns: Name ID Data (Value, Format, NameQualifier, SPNameQualifier)
:rtype: dict

get_nameid(self):

Gets the NameID provided by the SAML Response from the IdP

:returns: NameID (value)
:rtype: string|None

get_nameid_format(self):

Gets the NameID Format provided by the SAML Response from the IdP

:returns: NameID Format
:rtype: string|None

get_session_not_on_or_after(self):

Gets the SessionNotOnOrAfter from the AuthnStatement
Could be used to set the local session expiration

:returns: The SessionNotOnOrAfter value
:rtype: time|None

get_assertion_not_on_or_after(self):

Returns the NotOnOrAfter value of the valid SubjectConfirmationData node if any

get_session_index(self):

Gets the SessionIndex from the AuthnStatement
Could be used to be stored in the local session in order
to be used in a future Logout Request that the SP could
send to the SP, to set what specific session must be deleted

:returns: The SessionIndex value
:rtype: string|None

get_attributes(self):

Gets the Attributes from the AttributeStatement element.
EncryptedAttributes are not supported

validate_num_assertions(self):

Verifies that the document only contains a single Assertion (encrypted or not)

:returns: True if only 1 assertion encrypted or not
:rtype: bool

process_signed_elements(self):

Verifies the signature nodes:
- Checks that are Response or Assertion
- Check that IDs and reference URI are unique and consistent.

:returns: The signed elements tag names
:rtype: list

validate_signed_elements(self, signed_elements):

Verifies that the document has the expected signed nodes.

:param signed_elements: The signed elements to be checked
:type signed_elements: list
:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean

validate_timestamps(self):

Verifies that the document is valid according to Conditions Element

:returns: True if the condition is valid, False otherwise
:rtype: bool

__query_assertion(self, xpath_expr):

Extracts nodes that match the query from the Assertion

:param xpath_expr: Xpath Expresion
:type xpath_expr: String

:returns: The queried nodes
:rtype: list

__query(self, query):

Extracts nodes that match the query from the Response

:param query: Xpath Expresion
:type query: String

:returns: The queried nodes
:rtype: list

__decrypt_assertion(self, xml):

Decrypts the Assertion

:raises: Exception if no private key available
:param xml: Encrypted Assertion
:type xml: Element
:returns: Decrypted Assertion
:rtype: Element

get_error(self):

After executing a validation process, if it fails this method returns the cause

get_xml_document(self):

Returns the SAML Response document (If contains an encrypted assertion, decrypts it)

:return: Decrypted XML response document
:rtype: DOMDocument

get_id(self):

:returns: the ID of the response
:rtype: string

get_assertion_id(self):

:returns: the ID of the assertion in the response
:rtype: string

Source code