django-cas-server
django-cas-server Documentation Contents:
- Provided by: python3-django-cas-server-doc (Version: 1.1.0-1)
- Source: django-cas-server
- Report a bug
django-cas-server Documentation Contents:
|travis|
|coverage|
|licence|
|github_version|
|pypi_version|
|codacy|
|doc|
CAS Server is a Django application implementing the CAS Protocol 3.0 Specification.
By default, the authentication process use django internal users but you can easily use any sources (see the Authentication backend section and auth classes in the auth.py file)
django-cas-server depends on the following python packages:
Minimal version of packages dependancy are just indicative and meens that django-cas-server has been tested with it. Previous versions of dependencies may or may not work.
Additionally, denpending of the Authentication backend you plan to use, you may need the following python packages:
Here there is a table with the name of python packages and the corresponding packages providing them on debian like systems and centos like systems. You should try as much as possible to use system packages as there are automatically updated then you update your system. You can then install Not Available (N/A) packages on your system using pip inside a virtualenv as described in the Installation section. For use with python3, just replace python(2) in the table by python3.
| python package | debian like systems | centos like systems |
| Django | python-django | python-django |
| requests | python-requests | python-requests |
| requests_futures | python-requests-futures | N/A |
| lxml | python-lxml | python-lxml |
| six | python-six | python-six |
| ldap3 | python-ldap3 | python-ldap3 |
| psycopg2 | python-psycopg2 | python-psycopg2 |
| mysql-python | python-mysqldb | python2-mysql |
The recommended installation mode is to use a virtualenv with --system-site-packages
On debian like systems:
$ sudo apt-get install python-django python-requests python-six python-lxml python-requests-futures
On debian jessie, you can use the version of python-django available in the backports.
On centos like systems:
$ sudo yum install python-django python-requests python-six python-lxml
$ virtualenv --system-site-packages cas_venv Running virtualenv with interpreter /var/www/html/cas-server/bin/python2 Using real prefix '/usr' New python executable in cas/bin/python2 Also creating executable in cas/bin/python Installing setuptools, pip...done.
$ cd cas_venv/; . bin/activate
$ django-admin startproject cas_project $ cd cas_project
$ pip install django-cas-server
Alternatively if you want to use the version of the git repository, you can clone it:
$ git clone https://github.com/nitmir/django-cas-server $ cd django-cas-server $ pip install -r requirements.txt
Then, either run make install to create a python package using the sources of the repository and install it with pip, or place the cas_server directory into your PYTHONPATH (for instance by symlinking cas_server to the root of your django project).
INSTALLED_APPS = (
'django.contrib.admin',
...
'cas_server',
)
For internationalization support, add “django.middleware.locale.LocaleMiddleware” to your MIDDLEWARE_CLASSES setting like this:
MIDDLEWARE_CLASSES = (
...
'django.middleware.locale.LocaleMiddleware',
...
)
from django.conf.urls import url, include
urlpatterns = [
url(r'^admin/', admin.site.urls),
...
url(r'^cas/', include('cas_server.urls', namespace="cas_server")),
]
You could for example do as bellow:
0 0 * * * cas-user /path/to/project/manage.py clearsessions */5 * * * * cas-user /path/to/project/manage.py cas_clean_tickets 5 0 * * * cas-user /path/to/project/manage.py cas_clean_sessions
All settings are optional. Add them to settings.py to customize django-cas-server:
{
"bootstrap3_css": "//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
"bootstrap3_js": "//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js",
"html5shiv": "//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js",
"respond": "//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js",
"jquery": "//code.jquery.com/jquery.min.js",
}
if you omit some keys of the dictionnary, the default value for these keys is used.
CAS_INFO_MESSAGES contains by default one message, cas_explained, which explain roughly the purpose of a CAS. The default is:
{
"cas_explained": {
"message":_(
u"The Central Authentication Service grants you access to most of our websites by "
u"authenticating only once, so you don't need to type your credentials again unless "
u"your session expires or you logout."
),
"discardable": True,
"type": "info", # one of info, success, info, warning, danger
},
}
Deprecated, see the Sql backend settings. Only usefull if you are using the mysql authentication backend:
The default is "crypt".
Only usefull if you are using the sql authentication backend. You must add a "cas_server" database to settings.DATABASES as defined in the django documentation. It is then the database use by the sql backend.
The default is "crypt".
Only usefull if you are using the ldap authentication backend:
The default is "ldap".
Only usefull if you are using the test authentication backend:
django-cas-server comes with some authentication backends:
django-cas-server logs most of its actions. To enable login, you must set the LOGGING (https://docs.djangoproject.com/en/stable/topics/logging) variable in settings.py.
Users successful actions (login, logout) are logged with the level INFO, failures are logged with the level WARNING and user attributes transmitted to a service are logged with the level DEBUG.
For example to log to syslog you can use :
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'cas_syslog': {
'format': 'cas: %(levelname)s %(message)s'
},
},
'handlers': {
'cas_syslog': {
'level': 'INFO',
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
'formatter': 'cas_syslog',
},
},
'loggers': {
'cas_server': {
'handlers': ['cas_syslog'],
'level': 'INFO',
'propagate': True,
},
},
}
Or to log to a file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'cas_file': {
'format': '%(asctime)s %(levelname)s %(message)s'
},
},
'handlers': {
'cas_file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '/tmp/cas_server.log',
'formatter': 'cas_file',
},
},
'loggers': {
'cas_server': {
'handlers': ['cas_file'],
'level': 'INFO',
'propagate': True,
},
},
}
In a CAS context, Service refers to the application the client is trying to access. By extension we use service for the URL of such an application.
By default, django-cas-server do not allow any service to use the CAS to authenticate users. In order to allow services, you need to connect to the django admin interface using a django superuser, and add a first service pattern.
A service pattern comes with 9 fields:
A service pattern has 4 associated models:
Then a user ask a ticket for a service, the service URL is compare against each service patterns sorted by position. The first service pattern that matches the service URL is chosen. Hence, you should give low position to very specific patterns like ^https://www\.example\.com(/.*)?$ and higher position to generic patterns like ^https://.*. So the service URL https://www.examle.com will use the service pattern for ^https://www\.example\.com(/.*)?$ and not the one for ^https://.*.
django-cas-server comes with a federation mode. Then CAS_FEDERATE is True, user are invited to choose an identity provider on the login page, then, they are redirected to the provider CAS to authenticate. This provider transmit to django-cas-server the user username and attributes. The user is now logged in on django-cas-server and can use services using django-cas-server as CAS.
In federation mode, the user attributes are cached upon user authentication. See the settings CAS_TGT_VALIDITY to force users to reauthenticate periodically and allow django-cas-server to refresh cached attributes.
The list of allowed identity providers is defined using the django admin application. With the development server started, visit http://127.0.0.1:8000/admin/ to add identity providers.
An identity provider comes with 5 fields:
In federation mode, django-cas-server build user’s username as follow: provider_returned_username@provider_suffix. Choose the provider returned username for django-cas-server and the provider suffix in order to make sense, as this built username is likely to be displayed to end users in applications.
Then using federate mode, you should add one command to a daily crontab: cas_clean_federate. This command clean the local cache of federated user from old unused users.
You could for example do as bellow:
10 0 * * * cas-user /path/to/project/manage.py cas_clean_federate
template tags for the app
module for the admin interface of the app
Base class for inlines in the admin interface.
Base class for inlines in UserAdmin interface
ServiceTicket in admin interface
ProxyTicket in admin interface
ProxyGrantingTicket in admin interface
User in admin interface
Username in admin interface
ReplaceAttributName in admin interface
ReplaceAttributValue in admin interface
FilterAttributValue in admin interface
ServicePattern in admin interface
FederatedIendityProvider in admin interface
FederatedUser in admin interface
UserAttributes in admin interface
django config module
django CAS application config class
Some authentication classes for the CAS
Authentication base class
raises NotImplementedError: always. The method need to be implemented by subclasses
A Dummy authentication class. Authentication always fails
A test authentication class only working for one unique user.
base class for databate based auth classes
DEPRECATED, use SqlAuthUser instead.
A mysql authentication class: authenticate user against a mysql database
A SQL authentication class: authenticate user against a SQL database. The SQL database must be configures in settings.py as settings.DATABASES['cas_server'].
A ldap authentication class: authenticate user against a ldap database
A django auth class: authenticate user against django internal users
Authentication class used then CAS_FEDERATE is True
CAS Client Version 1
Returns username on success and None on failure.
CAS Client Version 2
CAS Client Version 3
CASClient 3.0+ with SAML
@date: 2011-11-30 @author: Carlos Gonzalez Vila <carlewis@gmail.com>
Returns username and attributes on success and None,None on failure.
SAML request values:
Default values for the app’s settings
CAS_INFO_MESSAGES contains by default one message, cas_explained, which explain roughly the purpose of a CAS.
Implement database session store.
If this operation isn’t possible on a given backend, it should raise NotImplementedError. If it isn’t necessary, because the backend has a built-in expiration mechanism, it should be a no-op.
federated mode helper classes
Class CAS client used to authenticate the user again a CAS provider
forms for the app
Form base class to use boostrap then rendering the form fields
Base form with all field possibly hidden on the login pages
Form used on warn page before emiting a ticket
Form used on the login page when settings.CAS_FEDERATE is True allowing the user to choose an identity provider.
Form used on the login page to retrive user credentials
Form used on a auto submited page for linking the views FederateAuth and LoginView.
On successful authentication on a provider, in the view FederateAuth a FederatedUser is created by cas_server.federate.CASFederateValidateUser.verify_ticket() and the user is redirected to LoginView. This form is then automatically filled with infos matching the created FederatedUser using the ticket as one time password and submited using javascript. If javascript is not enabled, a connect button is displayed.
This stub authentication form, allow to implement the federated mode with very few modificatons to the LoginView view.
Form for Tickets in the admin interface
models for the app
A base class for models storing attributes as a json
An identity provider for the federated mode
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
A federated user as returner by a CAS provider (username and attributes)
An association between a CAS provider ticket and a (username, session) for processing SLO
``@``component
Local cache of the user attributes, used then needed
A user logged into the CAS
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
Base exception of exceptions raised in the ServicePattern model
Exception raised then an non allowed username try to get a ticket for a service
Exception raised then a user try to get a ticket for a service and do not reach a condition
Exception raised then a user try to get a ticket for a service using as username an attribut not present on this user
Allowed services pattern against services are tested to
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
A list of allowed usernames on a ServicePattern
A replacement of an attribute name for a ServicePattern. It also tell to transmit an attribute of User.attributs to the service. An empty replace mean to use the original attribute name.
A filter on User.attributs for a ServicePattern. If a User do not have an attribute attribut or its value do not match pattern, then ServicePattern.check_user() will raises BadFilter if called with that user.
A replacement (using a regular expression) of an attribute value for a ServicePattern.
Generic class for a Ticket
A Service Ticket
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A Proxy Ticket
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A Proxy Granting Ticket
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A list of proxies on ProxyTicket
The last new version available version sent
urls for the app
Some util function for the app
additional parameters needed to compure the reverse URL
Class to deal with hashed password as defined at https://tools.ietf.org/id/draft-stroeder-hashed-userpassword-values-01.html
Error raised then the hash scheme is not in LdapHashUserPassword.schemes_salt + LdapHashUserPassword.schemes_nosalt
Error raised then the hash is too short
Error raised then, with the scheme {CRYPT}, the salt is invalid
views for the app
destroy CAS session utils
base class for csrf exempt class views
destroy CAS session (logout) view
view to authenticated user against a backend CAS then CAS_FEDERATE is True
csrf is disabled for allowing SLO requests reception.
credential requestor / acceptor
A 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.
service ticket validation
Base class for both saml and cas validation error
handle service validation error
service ticket validation [CAS 2.0] and [CAS 3.0]
proxy ticket service
handle saml validation error
SAML ticket validation
A django CAS server application
All notable changes to this project will be documented in this file.
commit: 282e3a831b3c0b0818881c2f16d056850d572b89
commit: 07a537b403c5c5e39a4ddd084f90e3a4de88a54e
commit: 773707e6c3c3fa20f697c946e31cafc591e8fee8
commit: b168e0a6423c53de31aae6c444fa1d1c5083afa6
commit: 4ad4d13baa4236c5cd72cc5216d7ff08dd361476
It was originally developped to mach the need of https://ares.fr (Federated CAS at https://cas.ares.fr, example of an application using it as https://chat.myares.fr)
commit: e3ab64271b718a17e4cbbbabda0a2453107a83df
commit: 77d1607b0beefe8b171adcd8e2dcd974e3cdc72a
commit: f6d436acb49f8d32b5457c316c18c4892accfd3b
commit: d1cd17d6103281b03a8c57013671057eab80d21c
commit: 5e63f39f9b7c678a300ad2f8132166be34d1d35b
commit: 7b4fac575449e50c2caff07f5798dba7f4e4857c
commit: 51fa0861f550723171e52d58025fa789dccb8cde
commit: 9fbfe19c550b147e8d0377108cdac8231cf0fb27
commit: 16b700d0127abe33a1eabf5d5fe890aeb5167e5a
commit: eef9490885bf665a53349573ddb9cbe844319b3e
commit: d0f6ed9ea3a4b3e2bf715fd218c460892c32e39f
commit: b69769d71a99806a69e300eca0d7c6744a2b327e
commit: 90e077dedb991d651822e9bb283470de8bddd7dd
First github and PyPi release
commit: a071ad46d7cd76fc97eb86f2f538d330457c6767
commit: 6981433bdf8a406992ba0c5e844a47d06ccc08fb
Valentin Samir
2019, Valentin Samir