cas_server.views module¶
views for the app
-
class
cas_server.views.CsrfExemptView(**kwargs)[source]¶ Bases:
django.views.generic.base.Viewbase class for csrf exempt class views
-
class
cas_server.views.LogoutView(**kwargs)[source]¶ Bases:
django.views.generic.base.View,cas_server.views.LogoutMixindestroy CAS session (logout) view
-
request= None¶ current
django.http.HttpRequestobject
-
service= None¶ service GET parameter
-
url= None¶ url GET paramet
-
ajax= None¶ Trueif the HTTP_X_AJAX http header is sent andsettings.CAS_ENABLE_AJAX_AUTHisTrue,Falseotherwise.
-
init_get(request)[source]¶ Initialize the
LogoutViewattributes on GET request- Parameters
request (django.http.HttpRequest) – The current request object
-
-
class
cas_server.views.FederateAuth(**kwargs)[source]¶ Bases:
cas_server.views.CsrfExemptViewview to authenticated user against a backend CAS then CAS_FEDERATE is True
csrf is disabled for allowing SLO requests reception.
-
service_url= None¶ current URL used as service URL by the CAS client
-
get_cas_client(request, provider, renew=False)[source]¶ return a CAS client object matching provider
- Parameters
request (django.http.HttpRequest) – The current request object
provider (cas_server.models.FederatedIendityProvider) – the user identity provider
- Returns
The user CAS client object
- Return type
-
-
class
cas_server.views.LoginView(**kwargs)[source]¶ Bases:
django.views.generic.base.View,cas_server.views.LogoutMixincredential requestor / acceptor
-
user= None¶ The current
models.Userobject
-
form= None¶ The form to display to the user
-
request= None¶ current
django.http.HttpRequestobject
-
service= None¶ service GET/POST parameter
-
renew= None¶ Trueif renew GET/POST parameter is present and not “False”
-
warn= None¶ the warn GET/POST parameter
-
gateway= None¶ the gateway GET/POST parameter
-
method= None¶ the method GET/POST parameter
-
ajax= None¶ Trueif the HTTP_X_AJAX http header is sent andsettings.CAS_ENABLE_AJAX_AUTHisTrue,Falseotherwise.
-
renewed= False¶ Trueif the user has just authenticated
-
warned= False¶ Trueif renew GET/POST parameter is present and not “False”
-
username= None¶ The
FederateAuthtransmited username (only used ifsettings.CAS_FEDERATEisTrue)
-
ticket= None¶ The
FederateAuthtransmited ticket (only used ifsettings.CAS_FEDERATEisTrue)
-
INVALID_LOGIN_TICKET= 1¶
-
USER_LOGIN_OK= 2¶
-
USER_LOGIN_FAILURE= 3¶
-
USER_ALREADY_LOGGED= 4¶
-
USER_AUTHENTICATED= 5¶
-
USER_NOT_AUTHENTICATED= 6¶
-
init_post(request)[source]¶ Initialize POST received parameters
- Parameters
request (django.http.HttpRequest) – The current request object
-
check_lt()[source]¶ Check is the POSTed LoginTicket is valid, if yes invalide it
- Returns
Trueif the LoginTicket is valid,Falseotherwise- Return type
bool
-
post(request, *args, **kwargs)[source]¶ method called on POST request on this view
- Parameters
request (django.http.HttpRequest) – The current request object
-
process_post()[source]¶ Analyse the POST request:
check that the LoginTicket is valid
check that the user sumited credentials are valid
- Returns
INVALID_LOGIN_TICKETif the POSTed LoginTicket is not validUSER_ALREADY_LOGGEDif the user is already logged and do no request reauthentication.USER_LOGIN_FAILUREif the user is not logged or request for reauthentication and his credentials are not validUSER_LOGIN_OKif the user is not logged or request for reauthentication and his credentials are valid
- Return type
int
-
init_get(request)[source]¶ Initialize GET received parameters
- Parameters
request (django.http.HttpRequest) – The current request object
-
get(request, *args, **kwargs)[source]¶ method called on GET request on this view
- Parameters
request (django.http.HttpRequest) – The current request object
-
process_get()[source]¶ Analyse the GET request
- Returns
USER_NOT_AUTHENTICATEDif the user is not authenticated or is requesting for authentication renewalUSER_AUTHENTICATEDif the user is authenticated and is not requesting for authentication renewal
- Return type
int
-
init_form(values=None)[source]¶ Initialization of the good form depending of POST and GET parameters
- Parameters
values (django.http.QueryDict) – A POST or GET QueryDict
-
service_login()[source]¶ Perform login against a service
- Returns
The rendering of the
settings.CAS_WARN_TEMPLATEif the user asked to be warned before ticket emission and has not yep been warned.The redirection to the service URL with a ticket GET parameter
The redirection to the service URL without a ticket if ticket generation failed and the
gatewayattribute is setThe rendering of the
settings.CAS_LOGGED_TEMPLATEtemplate with some error messages if the ticket generation failed (e.g: user not allowed).
- Return type
django.http.HttpResponse
-
authenticated()[source]¶ Processing authenticated users
- Returns
The returned value of
service_login()ifserviceis definedThe rendering of
settings.CAS_LOGGED_TEMPLATEotherwise
- Return type
django.http.HttpResponse
-
not_authenticated()[source]¶ Processing non authenticated users
- Returns
The rendering of
settings.CAS_LOGIN_TEMPLATEwith various messages depending of GET/POST parametersThe redirection to
FederateAuthifsettings.CAS_FEDERATEisTrueand the “remember my identity provider” cookie is found
- Return type
django.http.HttpResponse
-
common()[source]¶ Common part execute uppon GET and POST request
- Returns
The returned value of
authenticated()if the user is authenticated and not requesting for authentication or if the authentication has just been renewedThe returned value of
not_authenticated()otherwise
- Return type
django.http.HttpResponse
-
-
class
cas_server.views.Auth(**kwargs)[source]¶ Bases:
cas_server.views.CsrfExemptViewA simple view to validate username/password/service tuple
csrf is disable as it is intended to be used by programs. Security is assured by a shared secret between the programs dans django-cas-server.
-
static
post(request)[source]¶ method called on POST request on this view
- Parameters
request (django.http.HttpRequest) – The current request object
- Returns
HttpResponse(u"yes\n")if the POSTed tuple (username, password, service) if valid (i.e. (username, password) is valid dans username is allowed on service).HttpResponse(u"no\n…")otherwise, with possibly an error message on the second line.- Return type
django.http.HttpResponse
-
static
-
class
cas_server.views.Validate(**kwargs)[source]¶ Bases:
django.views.generic.base.Viewservice ticket validation
-
exception
cas_server.views.ValidationBaseError(code, msg='')[source]¶ Bases:
ExceptionBase class for both saml and cas validation error
-
code= None¶ The error code
-
msg= None¶ The error message
-
-
exception
cas_server.views.ValidateError(code, msg='')[source]¶ Bases:
cas_server.views.ValidationBaseErrorhandle service validation error
-
template= 'cas_server/serviceValidateError.xml'¶ template to be render for the error
-
-
class
cas_server.views.ValidateService(**kwargs)[source]¶ Bases:
django.views.generic.base.Viewservice ticket validation [CAS 2.0] and [CAS 3.0]
-
request= None¶ Current
django.http.HttpRequestobject
-
service= None¶ The service GET parameter
-
ticket= None¶ the ticket GET parameter
-
pgt_url= None¶ the pgtUrl GET parameter
-
renew= None¶ the renew GET parameter
-
allow_proxy_ticket= False¶ specify if ProxyTicket are allowed by the view. Hence we user the same view for
/serviceValidateand/proxyValidatejuste changing the parameter.
-
get(request)[source]¶ method called on GET request on this view
- Parameters
request (django.http.HttpRequest) – The current request object:
- Returns
The rendering of
cas_server/serviceValidate.xmlif no errors is raised, the rendering orcas_server/serviceValidateError.xmlotherwise.- Return type
django.http.HttpResponse
-
process_ticket()[source]¶ fetch the ticket against the database and check its validity
- Raises
ValidateError – if the ticket is not found or not valid, potentially for that service
- Returns
A couple (ticket, proxies list)
- Return type
tuple
-
process_pgturl(params)[source]¶ Handle PGT request
- Parameters
params (dict) – A template context dict
- Raises
ValidateError – if pgtUrl is invalid or if TLS validation of the pgtUrl fails
- Returns
The rendering of
cas_server/serviceValidate.xml, usingparams- Return type
django.http.HttpResponse
-
-
class
cas_server.views.Proxy(**kwargs)[source]¶ Bases:
django.views.generic.base.Viewproxy ticket service
-
request= None¶ Current
django.http.HttpRequestobject
-
pgt= None¶ A ProxyGrantingTicket from the pgt GET parameter
-
target_service= None¶ the targetService GET parameter
-
get(request)[source]¶ method called on GET request on this view
- Parameters
request (django.http.HttpRequest) – The current request object:
- Returns
The returned value of
process_proxy()if no error is raised, else the rendering ofcas_server/serviceValidateError.xml.- Return type
django.http.HttpResponse
-
process_proxy()[source]¶ handle PT request
- Raises
ValidateError – if the PGT is not found, or the target service not allowed or the user not allowed on the tardet service.
- Returns
The rendering of
cas_server/proxy.xml- Return type
django.http.HttpResponse
-
-
exception
cas_server.views.SamlValidateError(code, msg='')[source]¶ Bases:
cas_server.views.ValidationBaseErrorhandle saml validation error
-
template= 'cas_server/samlValidateError.xml'¶ template to be render for the error
-
-
class
cas_server.views.SamlValidate(**kwargs)[source]¶ Bases:
cas_server.views.CsrfExemptViewSAML ticket validation
-
request= None¶
-
target= None¶
-
ticket= None¶
-
root= None¶
-
post(request, *args, **kwargs)[source]¶ method called on POST request on this view
- Parameters
request (django.http.HttpRequest) – The current request object
- Returns
the rendering of
cas_server/samlValidate.xmlif no error is raised, else the rendering ofcas_server/samlValidateError.xml.- Return type
django.http.HttpResponse
-