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 params
dictionary with the keysettings
set 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
data
serialized in jsonReturn type:
-
cas_server.utils.
import_attr
(path)[source]¶ transform a python dotted path to the attr
Parameters: path ( unicode
orstr
or 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_name
withparams
as querystringParameters: Returns: A redirection to the URL with name
url_name
withparams
as querystring.Return type:
-
cas_server.utils.
reverse_params
(url_name, params=None, **kwargs)[source]¶ compute the reverse url of
url_name
and add to it parameters fromparams
as querystringParameters: Returns: The computed reverse URL of
url_name
with possible querystring fromparams
Return type: unicode
-
cas_server.utils.
copy_params
(get_or_post_params, ignore=None)[source]¶ copy a
django.http.QueryDict
in adict
ignoring keys in the setignore
Parameters: - 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: - get_or_post_params (django.http.QueryDict) – A GET or POST
Set the cookie
key
onresponse
with valuevalue
valid formax_age
secondesParameters: - 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_params
in the querystring.Return type: unicode
-
cas_server.utils.
update_url
(url, params)[source]¶ update parameters using
params
in theurl
query stringParameters: Returns: The URL with an updated querystring
Return type: unicode
-
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_PREFIX
and lengthsettings.CAS_LT_LEN
Return type: unicode
-
cas_server.utils.
gen_st
()[source]¶ Generate a Service Ticket
Returns: A ticket with prefix settings.CAS_SERVICE_TICKET_PREFIX
and lengthsettings.CAS_ST_LEN
Return type: unicode
-
cas_server.utils.
gen_pt
()[source]¶ Generate a Proxy Ticket
Returns: A ticket with prefix settings.CAS_PROXY_TICKET_PREFIX
and lengthsettings.CAS_PT_LEN
Return type: unicode
-
cas_server.utils.
gen_pgt
()[source]¶ Generate a Proxy Granting Ticket
Returns: A ticket with prefix settings.CAS_PROXY_GRANTING_TICKET_PREFIX
and lengthsettings.CAS_PGT_LEN
Return 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_PREFIX
and lengthsettings.CAS_PGTIOU_LEN
Return type: unicode
-
cas_server.utils.
gen_saml_id
()[source]¶ Generate an saml id
Returns: A random id of length settings.CAS_TICKET_LEN
Return type: unicode
-
cas_server.utils.
get_tuple
(nuplet, index, default=None)[source]¶ Parameters: 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: True
ifsalt
is a valid crypt salt on this system,False
otherwiseReturn type: bool
-
class
cas_server.utils.
LdapHashUserPassword
[source]¶ Bases:
object
Class 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:
ValueError
Error raised then the hash scheme is not in
LdapHashUserPassword.schemes_salt
+LdapHashUserPassword.schemes_nosalt
-
exception
BadHash
[source]¶ Bases:
ValueError
Error raised then the hash is too short
-
exception
BadSalt
[source]¶ Bases:
ValueError
Error raised then, with the scheme
{CRYPT}
, the salt is invalid
-
classmethod
hash
(scheme, password, salt=None, charset='utf8')[source]¶ Hash
password
withscheme
usingsalt
. This three variable beeing encoded incharset
.Parameters: Returns: The hashed password encoded with
charset
Return type:
-
classmethod
get_scheme
(hashed_passord)[source]¶ Return the scheme of
hashed_passord
or raiseBadHash
Parameters: 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_passord
possibly 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_passord
or if the hashed password is too short for the scheme found.
-
-
cas_server.utils.
check_password
(method, password, hashed_password, charset)[source]¶ Check that
password
match 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 (
str
orunicode
) – The user inputed password - hashed_password (
str
orunicode
) – 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
password
when it was initially )
Returns: True if
password
matchhashed_password
usingmethod
,False
otherwiseReturn type: - 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