cas_server.models module¶
models for the app
-
cas_server.models.logger= <Logger cas_server.models (INFO)>¶ logger facility
-
class
cas_server.models.JsonAttributes(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA base class for models storing attributes as a json
-
attributs¶ The attributes
-
-
class
cas_server.models.FederatedIendityProvider(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelAn identity provider for the federated mode
-
suffix¶ Suffix append to backend CAS returned username:
returned_username@suffix. it must be unique.
-
server_url¶ URL to the root of the CAS server application. If login page is https://cas.example.net/cas/login then
server_urlshould be https://cas.example.net/cas/
-
cas_protocol_version¶ Version of the CAS protocol to use when sending requests the the backend CAS.
-
verbose_name¶ Name for this identity provider displayed on the login page.
-
pos¶ Position of the identity provider on the login page. Identity provider are sorted using the (
pos,verbose_name,suffix) attributes.
-
display¶ Display the provider on the login page. Beware that this do not disable the identity provider, it just hide it on the login page. User will always be able to log in using this provider by fetching
/federate/suffix.
-
static
build_username_from_suffix(username, suffix)[source]¶ Transform backend username into federated username using
suffixParameters: - username (unicode) – A CAS backend returned username
- suffix (unicode) – A suffix identifying the CAS backend
Returns: The federated username:
username@suffix.Return type: unicode
-
build_username(username)[source]¶ Transform backend username into federated username
Parameters: username (unicode) – A CAS backend returned username Returns: The federated username: username@suffix.Return type: unicode
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
federateduser_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
get_cas_protocol_version_display(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
-
class
cas_server.models.FederatedUser(*args, **kwargs)[source]¶ Bases:
JsonAttributesA federated user as returner by a CAS provider (username and attributes)
-
username¶ The user username returned by the CAS backend on successful ticket validation
-
provider¶ A foreign key to
FederatedIendityProvider
-
federated_username¶ The federated username with a suffix for the current
FederatedUser.
-
classmethod
get_from_federated_username(username)[source]¶ Returns: A FederatedUserobject from a federatedusernameReturn type: FederatedUser
-
classmethod
clean_old_entries()[source]¶ remove old unused
FederatedUser
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
get_next_by_last_update(**morekwargs)¶
-
get_previous_by_last_update(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
provider_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.FederateSLO(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelAn association between a CAS provider ticket and a (username, session) for processing SLO
-
classmethod
clean_deleted_sessions()[source]¶ remove old
FederateSLOobject for which the session do not exists anymore
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
classmethod
-
class
cas_server.models.UserAttributes(*args, **kwargs)[source]¶ Bases:
JsonAttributesLocal cache of the user attributes, used then needed
-
username¶ The username of the user for which we cache attributes
-
classmethod
clean_old_entries()[source]¶ Remove
UserAttributesfor which no moreUserexists.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
-
class
cas_server.models.User(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA user logged into the CAS
-
session_key¶ The session key of the current authenticated user
-
username¶ The username of the current authenticated user
-
date¶ Last time the authenticated user has do something (auth, fetch ticket, etc…)
-
last_login¶ last time the user logged
-
delete(*args, **kwargs)[source]¶ Remove the current
User. Ifsettings.CAS_FEDERATEisTrue, also delete the correspondingFederateSLOobject.
-
classmethod
clean_old_entries()[source]¶ Remove
Userobjects inactive since more thatSESSION_COOKIE_AGEand send corresponding SingleLogOut requests.
-
classmethod
clean_deleted_sessions()[source]¶ Remove
Userobjects where the corresponding session do not exists anymore.
-
attributs¶ Property. A fresh
dictfor the user attributes, usingsettings.CAS_AUTH_CLASSif possible, and if not, try to fallback to cached attributes (actually only used for ldap auth class with bind password check mthode).
-
logout(request=None)[source]¶ Send SLO requests to all services the user is logged in.
Parameters: request ( django.http.HttpRequestorNoneType) – The current django HttpRequest to display possible failure to the user.
-
get_ticket(ticket_class, service, service_pattern, renew)[source]¶ Generate a ticket using
ticket_classfor the serviceservicematchingservice_patternand asking or not for authentication renewal withrenewParameters: - ticket_class (type) –
ServiceTicketorProxyTicketorProxyGrantingTicket. - service (unicode) – The service url for which we want a ticket.
- service_pattern (ServicePattern) – The service pattern matching
service. Beware thatservicemust matchServicePattern.patternand the currentUsermust passServicePattern.check_user(). These checks are not done here and you must perform them before calling this method. - renew (bool) – Should be
Trueif authentication has been renewed. Must beFalseotherwise.
Returns: A
Ticketobject.Return type: - ticket_class (type) –
-
get_service_url(service, service_pattern, renew)[source]¶ Return the url to which the user must be redirected to after a Service Ticket has been generated
Parameters: - service (unicode) – The service url for which we want a ticket.
- service_pattern (ServicePattern) – The service pattern matching
service. Beware thatservicemust matchServicePattern.patternand the currentUsermust passServicePattern.check_user(). These checks are not done here and you must perform them before calling this method. - renew (bool) – Should be
Trueif authentication has been renewed. Must beFalseotherwise.
Return unicode: The service url with the ticket GET param added.
Return type: unicode
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
get_next_by_date(**morekwargs)¶
-
get_next_by_last_login(**morekwargs)¶
-
get_previous_by_date(**morekwargs)¶
-
get_previous_by_last_login(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
proxygrantingticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
proxyticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
serviceticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
-
exception
cas_server.models.ServicePatternException[source]¶ Bases:
exceptions.ExceptionBase exception of exceptions raised in the ServicePattern model
-
exception
cas_server.models.BadUsername[source]¶ Bases:
ServicePatternExceptionException raised then an non allowed username try to get a ticket for a service
-
exception
cas_server.models.BadFilter[source]¶ Bases:
ServicePatternExceptionException raised then a user try to get a ticket for a service and do not reach a condition
-
exception
cas_server.models.UserFieldNotDefined[source]¶ Bases:
ServicePatternExceptionException raised then a user try to get a ticket for a service using as username an attribut not present on this user
-
class
cas_server.models.ServicePattern(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelAllowed services pattern against services are tested to
-
name¶ A name for the service (this can bedisplayed to the user on the login page)
-
pattern¶ A regular expression matching services. “Will usually looks like ‘^https://some.server.com/path/.*$’. As it is a regular expression, special character must be escaped with a ‘'.
-
user_field¶ Name of the attribute to transmit as username, if empty the user login is used
-
proxy¶ A boolean allowing to deliver
ProxyTicketto the service.
-
proxy_callback¶ A boolean allowing the service to be used as a proxy callback (via the pgtUrl GET param) to deliver
ProxyGrantingTicket.
-
single_log_out¶ Enable SingleLogOut for the service. Old validaed tickets for the service will be kept until
settings.CAS_TICKET_TIMEOUTafter what a SLO request is send to the service and the ticket is purged from database. A SLO can be send earlier if the user log-out.
-
single_log_out_callback¶ An URL where the SLO request will be POST. If empty the service url will be used. This is usefull for non HTTP proxied services like smtp or imap.
-
check_user(user)[source]¶ Check if
userif allowed to use theses services. Ifuseris not allowed, raises one ofBadFilter,UserFieldNotDefined,BadUsernameParameters: Raises: - BadUsername – if
restrict_usersifTrueandUser.usernameis not withinusernames. - BadFilter – if a
FilterAttributValuecondition offiltersconnot be verified. - UserFieldNotDefined – if
user_fieldis defined and its value is not withinUser.attributs.
Returns: TrueReturn type: bool
- BadUsername – if
-
classmethod
validate(service)[source]¶ Get a
ServicePatternintance from a service url.Parameters: service (unicode) – A service url Returns: A ServicePatterninstance matchingservice.Return type: ServicePatternRaises: ServicePattern.DoesNotExist – if no ServicePatternis matchingservice.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
attributs¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
filters¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
proxygrantingticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
proxyticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
replacements¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
serviceticket¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
usernames¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
-
class
cas_server.models.Username(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA list of allowed usernames on a
ServicePattern-
value¶ username allowed to connect to the service
-
service_pattern¶ ForeignKey to a
ServicePattern.Usernameinstances for aServicePatternare accessible thought itsServicePattern.usernamesattribute.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.ReplaceAttributName(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA replacement of an attribute name for a
ServicePattern. It also tell to transmit an attribute ofUser.attributsto the service. An emptyreplacemean to use the original attribute name.-
name¶ Name the attribute: a key of
User.attributs
-
service_pattern¶ ForeignKey to a
ServicePattern.ReplaceAttributNameinstances for aServicePatternare accessible thought itsServicePattern.attributsattribute.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.FilterAttributValue(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA filter on
User.attributsfor aServicePattern. If aUserdo not have an attributeattributor its value do not matchpattern, thenServicePattern.check_user()will raisesBadFilterif called with that user.-
attribut¶ The name of a user attribute
-
pattern¶ A regular expression the attribute
attributvalue must verify. Ifattributif a list, only one of the list values needs to match.
-
service_pattern¶ ForeignKey to a
ServicePattern.FilterAttributValueinstances for aServicePatternare accessible thought itsServicePattern.filtersattribute.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.ReplaceAttributValue(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA replacement (using a regular expression) of an attribute value for a
ServicePattern.-
attribut¶ Name the attribute: a key of
User.attributs
-
pattern¶ A regular expression matching the part of the attribute value that need to be changed
-
service_pattern¶ ForeignKey to a
ServicePattern.ReplaceAttributValueinstances for aServicePatternare accessible thought itsServicePattern.replacementsattribute.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.Ticket(*args, **kwargs)[source]¶ Bases:
JsonAttributesGeneric class for a Ticket
-
validate¶ A boolean.
Trueif the ticket has been validated
-
service¶ The service url for the ticket
-
service_pattern¶ ForeignKey to a
ServicePattern. TheServicePatterncorresponding toservice. UseServicePattern.validate()to find it.
-
creation¶ Date of the ticket creation
-
renew¶ A boolean.
Trueif the user has just renew his authentication
-
single_log_out¶ A boolean. Set to
service_patternattributeServicePattern.single_log_outvalue.
-
VALIDITY= 60¶ Max duration between ticket creation and its validation. Any validation attempt for the ticket after
creation+ VALIDITY will fail as if the ticket do not exists.
-
TIMEOUT= 86400¶ Time we keep ticket with
single_log_outset toTruebefore sending SingleLogOut requests.
-
exception
DoesNotExist[source]¶ raised in
Ticket.get()then ticket prefix and ticket classes mismatch
-
static
send_slos(queryset_list)[source]¶ Send SLO requests to each ticket of each queryset of
queryset_listParameters: queryset_list (list) – A list a TicketquerysetReturns: A list of possibly encoutered ExceptionReturn type: list
-
static
get_class(ticket, classes=None)[source]¶ Return the ticket class of
ticketParameters: - ticket (unicode) – A ticket
- classes (list) – Optinal arguement. A list of possible
Ticketsubclasses
Returns: The class corresponding to
ticket(ServiceTicketorProxyTicketorProxyGrantingTicket) if found amongclasses, ``Noneotherwise.Return type: typeorNoneType
-
username()[source]¶ The username to send on ticket validation
Returns: The value of the corresponding user attribute if service_pattern.user_field is set, the user username otherwise.
-
attributs_flat()[source]¶ generate attributes list for template rendering
Returns: An list of (attribute name, attribute value) of all user attributes flatened (no nested list) Return type: listoftupleofunicode
-
classmethod
get(ticket, renew=False, service=None)[source]¶ - Search the database for a valid ticket with provided arguments
Parameters: - ticket (unicode) – A ticket value
- renew (bool) – Is authentication renewal needed
- service (unicode) – Optional argument. The ticket service
Raises: - Ticket.DoesNotExist – if no class is found for the ticket prefix
- cls.DoesNotExist – if
ticketvalue is not found in th database
Returns: a
TicketinstanceReturn type:
-
get_next_by_creation(**morekwargs)¶
-
get_previous_by_creation(**morekwargs)¶
-
service_pattern_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.ServiceTicket(*args, **kwargs)[source]¶ Bases:
TicketA Service Ticket
-
PREFIX= 'ST'¶ The ticket prefix used to differentiate it from other tickets types
-
value¶ The ticket value
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
get_next_by_creation(**morekwargs)¶
-
get_previous_by_creation(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
user¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
-
class
cas_server.models.ProxyTicket(*args, **kwargs)[source]¶ Bases:
TicketA Proxy Ticket
-
PREFIX= 'PT'¶ The ticket prefix used to differentiate it from other tickets types
-
value¶ The ticket value
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
get_next_by_creation(**morekwargs)¶
-
get_previous_by_creation(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
proxies¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
service_pattern¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
user¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
-
class
cas_server.models.ProxyGrantingTicket(*args, **kwargs)[source]¶ Bases:
TicketA Proxy Granting Ticket
-
PREFIX= 'PGT'¶ The ticket prefix used to differentiate it from other tickets types
-
VALIDITY= 3600¶ ProxyGranting ticket are never validated. However, they can be used during
VALIDITYto getProxyTicketforuser
-
value¶ The ticket value
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
get_next_by_creation(**morekwargs)¶
-
get_previous_by_creation(**morekwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
service_pattern¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
user¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
-
class
cas_server.models.Proxy(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelA list of proxies on
ProxyTicket-
url¶ Service url of the PGT used for getting the associated
ProxyTicket
-
proxy_ticket¶ ForeignKey to a
ProxyTicket.Proxyinstances for aProxyTicketare accessible thought itsProxyTicket.proxiesattribute.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
proxy_ticket_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
cas_server.models.NewVersionWarning(*args, **kwargs)[source]¶ Bases:
django.db.models.ModelThe last new version available version sent
-
version¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-