cas_server.utils module¶
Some util function for the app
-
cas_server.utils.logger= <Logger cas_server.utils (INFO)>¶ logger facility
-
cas_server.utils.context(params)[source]¶ Function that add somes variable to the context before template rendering
Parameters: params (dict) – The context dictionary used to render templates. Returns: The paramsdictionary with the keysettingsset todjango.conf.settings.Return type: dict
-
cas_server.utils.json_response(request, data)[source]¶ Wrapper dumping data to a json and sending it to the user with an HttpResponse
Parameters: - request (django.http.HttpRequest) – The request object used to generate this response.
- data (dict) – The python dictionnary to return as a json
Returns: The content of
dataserialized in jsonReturn type: django.http.HttpResponse
-
cas_server.utils.import_attr(path)[source]¶ transform a python dotted path to the attr
Parameters: path ( unicodeorstror anything) – A dotted path to a python object or a python objectReturns: The python object pointed by the dotted path or the python object unchanged
-
cas_server.utils.redirect_params(url_name, params=None)[source]¶ Redirect to
url_namewithparamsas querystringParameters: - url_name (unicode) – a URL pattern name
- params (
dictorNoneType) – Some parameter to append to the reversed URL
Returns: A redirection to the URL with name
url_namewithparamsas querystring.Return type: django.http.HttpResponseRedirect
-
cas_server.utils.reverse_params(url_name, params=None, **kwargs)[source]¶ compute the reverse url of
url_nameand add to it parameters fromparamsas querystringParameters: - url_name (unicode) – a URL pattern name
- params (
dictorNoneType) – Some parameter to append to the reversed URL - **kwargs –
additional parameters needed to compure the reverse URL
Returns: The computed reverse URL of
url_namewith possible querystring fromparamsReturn type: unicode
-
cas_server.utils.copy_params(get_or_post_params, ignore=None)[source]¶ copy a
django.http.QueryDictin adictignoring keys in the setignoreParameters: - get_or_post_params (django.http.QueryDict) – A GET or POST
QueryDict - ignore (set) – An optinal set of keys to ignore during the copy
Returns: A copy of get_or_post_params
Return type: dict
- get_or_post_params (django.http.QueryDict) – A GET or POST
Set the cookie
keyonresponsewith valuevaluevalid formax_agesecondesParameters: - response (django.http.HttpResponse) – a django response where to set the cookie
- key (unicode) – the cookie key
- value (unicode) – the cookie value
- max_age (int) – the maximum validity age of the cookie
-
cas_server.utils.get_current_url(request, ignore_params=None)[source]¶ Giving a django request, return the current http url, possibly ignoring some GET parameters
Parameters: - request (django.http.HttpRequest) – The current request object.
- ignore_params (set) – An optional set of GET parameters to ignore
Returns: The URL of the current page, possibly omitting some parameters from
ignore_paramsin the querystring.Return type: unicode
-
cas_server.utils.update_url(url, params)[source]¶ update parameters using
paramsin theurlquery stringParameters: - url (
unicodeorstr) – An URL possibily with a querystring - params (dict) – A dictionary of parameters for updating the url querystring
Returns: The URL with an updated querystring
Return type: unicode
- url (
-
cas_server.utils.unpack_nested_exception(error)[source]¶ If exception are stacked, return the first one
Parameters: error – A python exception with possible exception embeded within Returns: A python exception with no exception embeded within
-
cas_server.utils.gen_lt()[source]¶ Generate a Login Ticket
Returns: A ticket with prefix settings.CAS_LOGIN_TICKET_PREFIXand lengthsettings.CAS_LT_LENReturn type: unicode
-
cas_server.utils.gen_st()[source]¶ Generate a Service Ticket
Returns: A ticket with prefix settings.CAS_SERVICE_TICKET_PREFIXand lengthsettings.CAS_ST_LENReturn type: unicode
-
cas_server.utils.gen_pt()[source]¶ Generate a Proxy Ticket
Returns: A ticket with prefix settings.CAS_PROXY_TICKET_PREFIXand lengthsettings.CAS_PT_LENReturn type: unicode
-
cas_server.utils.gen_pgt()[source]¶ Generate a Proxy Granting Ticket
Returns: A ticket with prefix settings.CAS_PROXY_GRANTING_TICKET_PREFIXand lengthsettings.CAS_PGT_LENReturn type: unicode
-
cas_server.utils.gen_pgtiou()[source]¶ Generate a Proxy Granting Ticket IOU
Returns: A ticket with prefix settings.CAS_PROXY_GRANTING_TICKET_IOU_PREFIXand lengthsettings.CAS_PGTIOU_LENReturn type: unicode
-
cas_server.utils.gen_saml_id()[source]¶ Generate an saml id
Returns: A random id of length settings.CAS_TICKET_LENReturn type: unicode
-
cas_server.utils.get_tuple(nuplet, index, default=None)[source]¶ Parameters: - nuplet (tuple) – A tuple
- index (int) – An index
- default – An optional default value
Returns: nuplet[index]if defined, elsedefault(possiblyNone)
-
cas_server.utils.crypt_salt_is_valid(salt)[source]¶ Validate a salt as crypt salt
Parameters: salt (str) – a password salt Returns: Trueifsaltis a valid crypt salt on this system,FalseotherwiseReturn type: bool
-
class
cas_server.utils.LdapHashUserPassword[source]¶ Bases:
objectClass to deal with hashed password as defined at https://tools.ietf.org/id/draft-stroeder-hashed-userpassword-values-01.html
-
schemes_salt= {b'{CRYPT}', b'{SMD5}', b'{SSHA256}', b'{SSHA384}', b'{SSHA512}', b'{SSHA}'}¶ valide schemes that require a salt
-
schemes_nosalt= {b'{MD5}', b'{SHA256}', b'{SHA384}', b'{SHA512}', b'{SHA}'}¶ valide sschemes that require no slat
-
exception
BadScheme[source]¶ Bases:
ValueErrorError raised then the hash scheme is not in
LdapHashUserPassword.schemes_salt+LdapHashUserPassword.schemes_nosalt
-
exception
BadSalt[source]¶ Bases:
ValueErrorError raised then, with the scheme
{CRYPT}, the salt is invalid
-
classmethod
hash(scheme, password, salt=None, charset='utf8')[source]¶ Hash
passwordwithschemeusingsalt. This three variable beeing encoded incharset.Parameters: - scheme (bytes) – A valid scheme
- password (bytes) – A byte string to hash using
scheme - salt (bytes) – An optional salt to use if
schemerequires any - charset (str) – The encoding of
scheme,passwordandsalt
Returns: The hashed password encoded with
charsetReturn type: bytes
-
classmethod
get_scheme(hashed_passord)[source]¶ Return the scheme of
hashed_passordor raiseBadHashParameters: hashed_passord (bytes) – A hashed password Returns: The scheme used by the hashed password Return type: bytes Raises: BadHash – if no valid scheme is found within hashed_passord
-
classmethod
get_salt(hashed_passord)[source]¶ Return the salt of
hashed_passordpossibly emptyParameters: hashed_passord (bytes) – A hashed password Returns: The salt used by the hashed password (empty if no salt is used) Return type: bytes Raises: BadHash – if no valid scheme is found within hashed_passordor if the hashed password is too short for the scheme found.
-
-
cas_server.utils.check_password(method, password, hashed_password, charset)[source]¶ Check that
passwordmatch hashed_password usingmethod, assuming the encoding ischarset.Parameters: - method (str) – on of
"crypt","ldap","hex_md5","hex_sha1","hex_sha224","hex_sha256","hex_sha384","hex_sha512","plain" - password (
strorunicode) – The user inputed password - hashed_password (
strorunicode) – The hashed password as stored in the database - charset (str) – The used char encoding (also used internally, so it must be valid for
the charset used by
passwordwhen it was initially )
Returns: True if
passwordmatchhashed_passwordusingmethod,FalseotherwiseReturn type: bool
- method (str) – on of
-
cas_server.utils.decode_version(version)[source]¶ decode a version string following version semantic http://semver.org/ input a tuple of int. It will work as long as we do not use pre release versions.
Parameters: version (unicode) – A dotted version Returns: A tuple a int Return type: tuple
-
cas_server.utils.last_version()[source]¶ Fetch the last version from pypi and return it. On successful fetch from pypi, the response is cached 24h, on error, it is cached 10 min.
Returns: the last django-cas-server version Return type: unicode