Debian Codegraph @

README.rst

raw ◀ ▶
1 Debian patch touch this file
1 CAS Server
2 ##########
3
4
5 CAS Server is a Django application implementing the `CAS Protocol 3.0 Specification
6 <https://apereo.github.io/cas/7.0.x/protocol/CAS-Protocol-Specification.html>`_.
7
8 By default, the authentication process uses django internal users but you can easily
9 use any source (see the `Authentication backend`_ section and auth classes in the auth.py file)
10
11 .. contents:: Table of Contents
12
13 Features
14 ========
15
16 * Support CAS version 1.0, 2.0, 3.0
17 * Support Single Sign Out
18 * Configuration of services via the Django Admin application
19 * Fine control on which user's attributes are passed to which service
20 * Possibility to rename/rewrite attributes per service
21 * Possibility to require some attribute values per service
22 * Federated mode between multiple CAS
23 * Supports Django 1.11, 2.2, 3.2, 4.2, 5.2
24 * Supports Python 3.6+
25
26 Dependencies
27 ============
28
29 ``django-cas-server`` depends on the following python packages:
30
31 * Django >= 1.11 < 4.3
32 * requests >= 2.4
33 * requests_futures >= 0.9.5
34 * lxml >= 3.4
35
36 Minimal version of package dependencies are just indicative and means that ``django-cas-server`` has
37 been tested with it. Previous versions of dependencies may or may not work.
38
39 Additionally, depending on the `Authentication backend`_ you plan to use, you may need the following
40 python packages:
41
42 * ldap3
43 * gssapi
44 * psycopg2
45 * mysql-python
46
47
48 Here is a table with the name of python packages and the corresponding packages providing
49 them on debian like systems.
50 You should try as much as possible to use system packages as they are automatically updated when
51 you update your system. You can then install Not Available (N/A)
52 packages on your system using pip3 inside a virtualenv as described in the `Installation`_ section.
53
54 +------------------+--------------------------+
55 | python package | debian like systems |
56 +==================+==========================+
57 | Django | python3-django |
58 +------------------+--------------------------+
59 | requests | python3-requests |
60 +------------------+--------------------------+
61 | requests_futures | python3-requests-futures |
62 +------------------+--------------------------+
63 | lxml | python3-lxml |
64 +------------------+--------------------------+
65 | ldap3 | python3-ldap3 |
66 +------------------+--------------------------+
67 | psycopg2 | python3-psycopg2 |
68 +------------------+--------------------------+
69 | mysql-python | python3-mysqldb |
70 +------------------+--------------------------+
71 | gssapi | python3-gssapi |
72 +------------------+--------------------------+
73
74 Installation
75 ============
76
77 The recommended installation mode is to use a virtualenv with ``--system-site-packages``
78
79 1. Make sure that python virtualenv is installed
80
81 2. Install python packages available via the system package manager:
82
83 On debian like systems::
84
85 $ sudo apt-get install python3-django python3-requests python3-lxml python3-requests-futures
86
87 3. Create a virtualenv::
88
89 $ virtualenv -p python3 --system-site-packages cas_venv
90
91 4. And `activate it <https://virtualenv.pypa.io/en/latest/user_guide.html>`__::
92
93 $ cd cas_venv/; . bin/activate
94
95 5. Create a django project::
96
97 $ django-admin startproject cas_project
98 $ cd cas_project
99
100 6. Install `django-cas-server`. To use the last published release, run::
101
102 $ pip install django-cas-server
103
104 Alternatively if you want to use the version of the git repository, you can clone it::
105
106 $ git clone https://github.com/nitmir/django-cas-server
107 $ cd django-cas-server
108 $ pip install -r requirements.txt
109
110 Then, either run ``make install`` to create a python package using the sources of the repository
111 and install it with pip, or place the ``cas_server`` directory into your
112 `PYTHONPATH <https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH>`_
113 (for instance by symlinking ``cas_server`` to the root of your django project).
114
115 7. Open ``cas_project/settings.py`` in your favourite editor and follow the quick start section.
116
117
118 Quick start
119 ===========
120
121 1. Add "cas_server" to your INSTALLED_APPS setting like this::
122
123 INSTALLED_APPS = (
124 'django.contrib.admin',
125 ...
126 'cas_server',
127 )
128
129 For internationalization support, add "django.middleware.locale.LocaleMiddleware"
130 to your MIDDLEWARE setting like this::
131
132 MIDDLEWARE = [
133 ...
134 'django.middleware.locale.LocaleMiddleware',
135 ...
136 ]
137
138 2. Include the cas_server URLconf in your project urls.py like this::
139
140 from django.urls import path, include
141
142 urlpatterns = [
143 path('admin/', admin.site.urls),
144 ...
145 path('cas/', include('cas_server.urls', namespace="cas_server")),
146 ]
147
148 3. Run ``python manage.py migrate`` to create the cas_server models.
149
150
151 4. You should add some management commands to a crontab: ``clearsessions``,
152 ``cas_clean_tickets`` and ``cas_clean_sessions``.
153
154 * ``clearsessions``: please see `Clearing the session store <https://docs.djangoproject.com/en/stable/topics/http/sessions/#clearing-the-session-store>`_.
155 * ``cas_clean_tickets``: old tickets and timed-out tickets do not get purged from
156 the database automatically. They are just marked as invalid. ``cas_clean_tickets``
157 is a clean-up management command for this purpose. It sends SingleLogOut requests
158 to services with timed out tickets and deletes them.
159 * ``cas_clean_sessions``: Logout and purge users (sending SLO requests) that are
160 inactive more than ``SESSION_COOKIE_AGE``. The default value is ``1209600``
161 seconds (2 weeks). You probably should reduce it to something like ``86400`` seconds (1 day).
162
163 You could, for example, do as below::
164
165 0 0 * * * cas-user /path/to/project/manage.py clearsessions
166 */5 * * * * cas-user /path/to/project/manage.py cas_clean_tickets
167 5 0 * * * cas-user /path/to/project/manage.py cas_clean_sessions
168
169 5. Run ``python manage.py createsuperuser`` to create an administrator user.
170
171 6. Start the development server and visit http://127.0.0.1:8000/admin/
172 to add a first service allowed to authenticate user against the CAS
173 (you'll need the Admin app enabled). See the `Service Patterns`_ section below.
174
175 7. Visit http://127.0.0.1:8000/cas/ to login with your django users.
176
177
178
179
180 Settings
181 ========
182
183 All settings are optional. Add them to ``settings.py`` to customize ``django-cas-server``:
184
185
186 Template settings
187 -----------------
188
189 * ``CAS_LOGO_URL``: URL to the logo shown in the upper left corner on the default
190 template. Set it to ``False`` to disable it.
191 * ``CAS_FAVICON_URL``: URL to the favicon (shortcut icon) used by the default templates.
192 Default is a key icon. Set it to ``False`` to disable it.
193 * ``CAS_SHOW_POWERED``: Set it to ``False`` to hide the powered by footer. The default is ``True``.
194 * ``CAS_COMPONENT_URLS``: URLs to css and javascript external components. It is a dictionary
195 having the five following keys: ``"bootstrap3_css"``, ``"bootstrap3_js"``,
196 ``bootstrap4_css``, ``bootstrap4_js``, ``"html5shiv"``, ``"respond"``, ``"jquery"``.
197 The default is::
198
199 {
200 "bootstrap3_css": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
201 "bootstrap3_js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js",
202 "html5shiv": "https://cdn.jsdelivr.net/npm/[email protected]/dist/html5shiv.min.js",
203 "respond": "https://cdn.jsdelivr.net/npm/[email protected]/dest/respond.min.js",
204 "bootstrap4_css": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
205 "bootstrap4_js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
206 "jquery": "https://code.jquery.com/jquery.min.js",
207 }
208
209 if you omit some keys of the dictionary, the default value for these keys is used.
210 * ``CAS_SHOW_SERVICE_MESSAGES``: Messages displayed about the state of the service on the login page.
211 The default is ``True``.
212 * ``CAS_INFO_MESSAGES``: Messages displayed in info-boxes on the html pages of the default templates.
213 It is a dictionary mapping message name to a message dict. A message dict has 3 keys:
214
215 * ``message``: A unicode message to display, potentially wrapped around ugettex_lazy
216 * ``discardable``: A boolean, specify if the users can close the message info-box
217 * ``type``: One of info, success, warning, danger. The type of the info-box.
218
219 ``CAS_INFO_MESSAGES`` contains by default one message, ``cas_explained``, which explains
220 roughly the purpose of a CAS. The default is::
221
222 {
223 "cas_explained": {
224 "message":_(
225 u"The Central Authentication Service grants you access to most of our websites by "
226 u"authenticating only once, so you don't need to type your credentials again unless "
227 u"your session expires or you logout."
228 ),
229 "discardable": True,
230 "type": "info", # one of info, success, warning, danger
231 },
232 }
233
234 * ``CAS_INFO_MESSAGES_ORDER``: A list of message names. Order in which info-box messages are
235 displayed. Use an empty list to disable messages display. The default is ``[]``.
236 * ``CAS_LOGIN_TEMPLATE``: Path to the template shown on ``/login`` when the user
237 is not autenticated. The default is ``"cas_server/bs4/login.html"``.
238 * ``CAS_WARN_TEMPLATE``: Path to the template shown on ``/login?service=...`` when
239 the user is authenticated and has asked to be warned before being connected
240 to a service. The default is ``"cas_server/bs4/warn.html"``.
241 * ``CAS_LOGGED_TEMPLATE``: Path to the template shown on ``/login`` when the user is
242 authenticated. The default is ``"cas_server/bs4/logged.html"``.
243 * ``CAS_LOGOUT_TEMPLATE``: Path to the template shown on ``/logout`` when the user
244 is being disconnected. The default is ``"cas_server/bs4/logout.html"``
245 * ``CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT``: Should we redirect users to ``/login`` after they
246 logged out instead of displaying ``CAS_LOGOUT_TEMPLATE``. The default is ``False``.
247
248 Note that the old bootstrap3 template is available in ``cas_server/bs3/``
249
250
251 Authentication settings
252 -----------------------
253
254 * ``CAS_AUTH_CLASS``: A dotted path to a class or a class implementing
255 ``cas_server.auth.AuthUser``. The default is ``"cas_server.auth.DjangoAuthUser"``
256 Available classes bundled with ``django-cas-server`` are listed below in the
257 `Authentication backend`_ section.
258
259 * ``CAS_AUTH_GSSAPI_ENABLE``: Activate Kerberos authentication (not compatible with
260 federate mode or auth class requiring access to the user credential to retrieve
261 user attributes).
262 See https://web.mit.edu/kerberos/krb5-1.13/doc/admin/env_variables.html for environment
263 variables allowing to configure the underlying GSSAPI C library.
264 Username retrieved form kerberos auth MUST match username used by the ``CAS_AUTH_CLASS``
265 The default is ``False``
266
267 * ``CAS_AUTH_GSSAPI_SERVICENAME``: Service Principal Name to use for Kerberos authentication
268 (must be available in the server keytab).
269
270 * ``SESSION_COOKIE_AGE``: This is a django setting. Here, it controls the delay in seconds after
271 which inactive users are logged out. The default is ``1209600`` (2 weeks). You probably should
272 reduce it to something like ``86400`` seconds (1 day).
273
274 * ``CAS_TGT_VALIDITY``: Max time after which the user MUST reauthenticate. Set it to `None` for no
275 max time. This can be used to force refreshing cached information only available upon user
276 authentication like the user attributes in federation mode or with the ldap auth in bind mode.
277 The default is ``None``.
278
279 * ``CAS_PROXY_CA_CERTIFICATE_PATH``: Path to certificate authorities file. Usually on linux
280 the local CAs are in ``/etc/ssl/certs/ca-certificates.crt``. The default is ``True`` which
281 tells requests to use its internal certificate authorities. Setting it to ``False`` should
282 disable all x509 certificate validation and MUST not be done in production.
283 x509 certificate validation is performed upon PGT issuance.
284
285 * ``CAS_SLO_MAX_PARALLEL_REQUESTS``: Maximum number of parallel single log out requests sent.
286 If more requests need to be sent, they are queued. The default is ``10``.
287
288 * ``CAS_SLO_TIMEOUT``: Timeout for a single SLO request in seconds. The default is ``5``.
289
290 * ``CAS_REMOVE_DJANGO_SESSION_COOKIE_ON_LOGOUT``: If `True` Django session cookie will be removed
291 on logout from CAS server (default `False`). Note that Django session middleware will generate
292 a new session cookie.
293
294 * ``CAS_REMOVE_DJANGO_CSRF_COOKIE_ON_LOGOUT``: If `True` Django csrf cookie will be removed on
295 logout from CAS server (default `False`). Note that Django csrf middleware will generate a new
296 csrf token cookie.
297
298 * ``CAS_REMOVE_DJANGO_LANGUAGE_COOKIE_ON_LOGOUT``: If `True` Django language cookie will be
299 removed on logout from CAS server (default `False`).
300
301
302 Federation settings
303 -------------------
304
305 * ``CAS_FEDERATE``: A boolean for activating the federated mode (see the `Federation mode`_
306 section below). The default is ``False``.
307 * ``CAS_FEDERATE_REMEMBER_TIMEOUT``: Time after which the cookie used for "remember my identity
308 provider" expire. The default is ``604800``, one week. The cookie is called
309 ``_remember_provider``.
310
311
312 New version warnings settings
313 -----------------------------
314
315 * ``CAS_NEW_VERSION_HTML_WARNING``: A boolean for diplaying a warning on html pages that a new
316 version of the application is avaible. Once closed by a user, it is not displayed to this user
317 until the next new version. The default is ``True``.
318 * ``CAS_NEW_VERSION_EMAIL_WARNING``: A boolean for sending a email to ``settings.ADMINS`` when a new
319 version is available. The default is ``True``.
320
321
322 Tickets validity settings
323 -------------------------
324
325 * ``CAS_TICKET_VALIDITY``: Number of seconds the service tickets and proxy tickets are valid.
326 This is the maximal time between ticket issuance by the CAS and ticket validation by an
327 application. The default is ``60``.
328 * ``CAS_PGT_VALIDITY``: Number of seconds the proxy granting tickets are valid.
329 The default is ``3600`` (1 hour).
330 * ``CAS_TICKET_TIMEOUT``: Number of seconds a ticket is kept in the database before sending
331 Single Log Out request and being cleared. The default is ``86400`` (24 hours).
332
333 Tickets miscellaneous settings
334 ------------------------------
335
336 * ``CAS_TICKET_LEN``: Default ticket length. All CAS implementations MUST support ST and PT
337 up to 32 chars, PGT and PGTIOU up to 64 chars and it is RECOMMENDED that all tickets up
338 to 256 chars are supported. Here the default is ``64``.
339 * ``CAS_LT_LEN``: Length of the login tickets. Login tickets are only processed by ``django-cas-server``
340 thus there are no length restrictions on it. The default is ``CAS_TICKET_LEN``.
341 * ``CAS_ST_LEN``: Length of the service tickets. The default is ``CAS_TICKET_LEN``.
342 You may need to lower it to ``32`` if you use some old clients.
343 * ``CAS_PT_LEN``: Length of the proxy tickets. The default is ``CAS_TICKET_LEN``.
344 This length should be the same as ``CAS_ST_LEN``. You may need to lower it to ``32``
345 if you use some old clients.
346 * ``CAS_PGT_LEN``: Length of the proxy granting tickets. The default is ``CAS_TICKET_LEN``.
347 * ``CAS_PGTIOU_LEN``: Length of the proxy granting tickets IOU. The default is ``CAS_TICKET_LEN``.
348
349 * ``CAS_LOGIN_TICKET_PREFIX``: Prefix of login tickets. The default is ``"LT"``.
350 * ``CAS_SERVICE_TICKET_PREFIX``: Prefix of service tickets. The default is ``"ST"``.
351 The CAS specification mandates that service tickets MUST begin with the characters ST
352 so you should not change this.
353 * ``CAS_PROXY_TICKET_PREFIX``: Prefix of proxy ticket. The default is ``"PT"``.
354 * ``CAS_PROXY_GRANTING_TICKET_PREFIX``: Prefix of proxy granting ticket. The default is ``"PGT"``.
355 * ``CAS_PROXY_GRANTING_TICKET_IOU_PREFIX``: Prefix of proxy granting ticket IOU. The default is ``"PGTIOU"``.
356
357 Forms settings
358 --------------
359
360 * ``CAS_USER_CREDENTIAL_FORM``: A dotted path to a form or a form used on the login page to retrieve
361 user credentials. The default is ``"cas_server.forms.UserCredential"``.
362 * ``CAS_WARN_FORM``: A dotted path to a form or a form used on warn page before emitting a ticket.
363 The default is ``"cas_server.forms.WarnForm"``.
364 * ``CAS_FEDERATE_SELECT_FORM``: A dotted path to a form or a form used on the login page to select
365 another CAS in federated mode. The default is ``"cas_server.forms.FederateSelect"``
366 * ``CAS_FEDERATE_USER_CREDENTIAL_FORM``: A dotted path to a form or a form used on the login page in
367 federated mode. The default is ``"cas_server.forms.FederateUserCredential"``
368 * ``CAS_TICKET_FORM``: A dotted path to a form or a form for Tickets in the admin interface.
369 The default is ``"cas_server.forms.TicketForm"``
370
371 Mysql backend settings
372 ----------------------
373 Deprecated, see the `Sql backend settings`_.
374 Only useful if you are using the mysql authentication backend:
375
376 * ``CAS_SQL_HOST``: Host for the SQL server. The default is ``"localhost"``.
377 * ``CAS_SQL_USERNAME``: Username for connecting to the SQL server.
378 * ``CAS_SQL_PASSWORD``: Password for connecting to the SQL server.
379 * ``CAS_SQL_DBNAME``: Database name.
380 * ``CAS_SQL_DBCHARSET``: Database charset. The default is ``"utf8"``
381 * ``CAS_SQL_USER_QUERY``: The query performed upon user authentication.
382 The username must be in field ``username``, the password in ``password``,
383 additional fields are used as the user attributes.
384 The default is ``"SELECT user AS username, pass AS password, users.* FROM users WHERE user = %s"``
385 * ``CAS_SQL_PASSWORD_CHECK``: The method used to check the user password. Must be one of the following:
386
387 * ``"crypt"`` (see <https://en.wikipedia.org/wiki/Crypt_(C)>), the password in the database
388 should begin with $. This method is deprecated and will stop to work in python 3.13.
389 * ``"ldap"`` (see https://datatracker.ietf.org/doc/html/draft-stroeder-hashed-userpassword-values)
390 the password in the database must begin with one of {MD5}, {SMD5}, {SHA}, {SSHA}, {SHA256},
391 {SSHA256}, {SHA384}, {SSHA384}, {SHA512}, {SSHA512}, {CRYPT}. {CRYPT} is deprecated
392 and will stop to work in python 3.13.
393 * ``"hex_HASH_NAME"`` with ``HASH_NAME`` in md5, sha1, sha224, sha256, sha384, sha512.
394 The hashed password in the database is compared to the hexadecimal digest of the clear
395 password hashed with the corresponding algorithm.
396 * ``"plain"``, the password in the database must be in clear.
397
398 The default is ``"crypt"``. This default is deprecated and will stop to work in python 3.13.
399
400
401 Sql backend settings
402 --------------------
403 Only useful if you are using the sql authentication backend. You must add a ``"cas_server"``
404 database to `settings.DATABASES <https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DATABASES>`__
405 as defined in the django documentation. It is then the database
406 used by the sql backend.
407
408 * ``CAS_SQL_USER_QUERY``: The query performed upon user authentication.
409 The username must be in field ``username``, the password in ``password``,
410 additional fields are used as the user attributes.
411 The default is ``"SELECT user AS username, pass AS password, users.* FROM users WHERE user = %s"``
412 * ``CAS_SQL_PASSWORD_CHECK``: The method used to check the user password. Must be one of the following:
413
414 * ``"crypt"`` (see <https://en.wikipedia.org/wiki/Crypt_(C)>), the password in the database
415 should begin with $. This method is deprecated and will stop to work in python 3.13.
416 * ``"ldap"`` (see https://tools.ietf.org/id/draft-stroeder-hashed-userpassword-values-01.html)
417 the password in the database must begin with one of {MD5}, {SMD5}, {SHA}, {SSHA}, {SHA256},
418 {SSHA256}, {SHA384}, {SSHA384}, {SHA512}, {SSHA512}, {CRYPT}. {CRYPT} is deprecated
419 and will stop to work in python 3.13.
420 * ``"hex_HASH_NAME"`` with ``HASH_NAME`` in md5, sha1, sha224, sha256, sha384, sha512.
421 The hashed password in the database is compared to the hexadecimal digest of the clear
422 password hashed with the corresponding algorithm.
423 * ``"plain"``, the password in the database must be in clear.
424
425 The default is ``"crypt"``. This default is deprecated and will stop to work in python 3.13.
426
427 * ``CAS_SQL_PASSWORD_CHARSET``: Charset the SQL users passwords was hash with. This is needed to
428 encode the user submitted password before hashing it for comparison. The default is ``"utf-8"``.
429
430
431 Ldap backend settings
432 ---------------------
433 Only useful if you are using the ldap authentication backend:
434
435 * ``CAS_LDAP_SERVER``: Address of the LDAP server. The default is ``"localhost"``.
436 * ``CAS_LDAP_USER``: User bind address, for example ``"cn=admin,dc=crans,dc=org"`` for
437 connecting to the LDAP server.
438 * ``CAS_LDAP_PASSWORD``: Password for connecting to the LDAP server.
439 * ``CAS_LDAP_BASE_DN``: LDAP search base DN, for example ``"ou=data,dc=crans,dc=org"``.
440 * ``CAS_LDAP_USER_QUERY``: Search filter for searching user by username. User entered usernames are
441 escaped using ``ldap3.utils.conv.escape_bytes``. The default is ``"(uid=%(username)s)"``
442 * ``CAS_LDAP_USERNAME_ATTR``: Attribute used for user's usernames. The default is ``"uid"``
443 * ``CAS_LDAP_PASSWORD_ATTR``: Attribute used for user's passwords. The default is ``"userPassword"``
444 * ``CAS_LDAP_PASSWORD_CHECK``: The method used to check the user password. Must be one of the following:
445
446 * ``"crypt"`` (see <https://en.wikipedia.org/wiki/Crypt_(C)>), the password in the database
447 should begin with $. This method is deprecated and will stop to work in python 3.13.
448 * ``"ldap"`` (see https://tools.ietf.org/id/draft-stroeder-hashed-userpassword-values-01.html)
449 the password in the database must begin with one of {MD5}, {SMD5}, {SHA}, {SSHA}, {SHA256},
450 {SSHA256}, {SHA384}, {SSHA384}, {SHA512}, {SSHA512}, {CRYPT}. {CRYPT} is deprecated and
451 will stop to work in python 3.13.
452 * ``"hex_HASH_NAME"`` with ``HASH_NAME`` in md5, sha1, sha224, sha256, sha384, sha512.
453 The hashed password in the database is compared to the hexadecimal digest of the clear
454 password hashed with the corresponding algorithm.
455 * ``"plain"``, the password in the database must be in clear.
456 * ``"bind"``, the user credentials are used to bind to the ldap database and retreive the user
457 attribute. In this mode, the settings ``CAS_LDAP_PASSWORD_ATTR`` and ``CAS_LDAP_PASSWORD_CHARSET``
458 are ignored, and it is the ldap server that performs the password check.
459
460 The default is ``"ldap"``.
461 * ``CAS_LDAP_ATTRS_VIEW``: This parameter is only used then ``CAS_LDAP_PASSWORD_CHECK`` is set to
462 ``"bind"``. If ``0`` the user attributes are retrieved by connecting to the ldap as ``CAS_LDAP_USER``.
463 If ``1`` the user attributes are retrieve then the user authenticate using the user credentials and
464 are cached for later use. It means there can be some differences between the attributes in database
465 and the cached ones. See the parameter ``CAS_TGT_VALIDITY`` to force user to reauthenticate
466 periodically.
467 The default is ``0``.
468 * ``CAS_LDAP_PASSWORD_CHARSET``: Charset the LDAP users passwords was hashed with. This is needed to
469 encode the user submitted password before hashing it for comparison. The default is ``"utf-8"``.
470
471
472 Test backend settings
473 ---------------------
474 Only useful if you are using the test authentication backend:
475
476 * ``CAS_TEST_USER``: Username of the test user. The default is ``"test"``.
477 * ``CAS_TEST_PASSWORD``: Password of the test user. The default is ``"test"``.
478 * ``CAS_TEST_ATTRIBUTES``: Attributes of the test user. The default is
479 ``{'nom': 'Nymous', 'prenom': 'Ano', 'email': '[email protected]',
480 'alias': ['demo1', 'demo2']}``.
481
482
483 Authentication backend
484 ======================
485
486 ``django-cas-server`` comes with some authentication backends:
487
488 * dummy backend ``cas_server.auth.DummyAuthUser``: all authentication attempts fail.
489 * test backend ``cas_server.auth.TestAuthUser``: username, password and returned attributes
490 for the user are defined by the ``CAS_TEST_*`` settings.
491 * django backend ``cas_server.auth.DjangoAuthUser``: Users are authenticated against django users system.
492 This is the default backend. The returned attributes are the fields available on the user model.
493 * mysql backend ``cas_server.auth.MysqlAuthUser``: Deprecated, use the sql backend instead.
494 see the `Mysql backend settings`_ section. The returned attributes are those returned by sql query
495 ``CAS_SQL_USER_QUERY``.
496 * sql backend ``cas_server.auth.SqlAuthUser``: see the `Sql backend settings`_ section.
497 The returned attributes are those returned by sql query ``CAS_SQL_USER_QUERY``.
498 * ldap backend ``cas_server.auth.LdapAuthUser``: see the `Ldap backend settings`_ section.
499 The returned attributes are those of the ldap node returned by the query filter ``CAS_LDAP_USER_QUERY``.
500 * federated backend ``cas_server.auth.CASFederateAuth``: It is automatically used when ``CAS_FEDERATE`` is ``True``.
501 You should not set it manually without setting ``CAS_FEDERATE`` to ``True``.
502
503
504 Logs
505 ====
506
507 ``django-cas-server`` logs most of its actions. To enable login, you must set the ``LOGGING``
508 (https://docs.djangoproject.com/en/stable/topics/logging) variable in ``settings.py``.
509
510 Users successful actions (login, logout) are logged with the level ``INFO``, failures are logged
511 with the level ``WARNING`` and user attributes transmitted to a service are logged with the level ``DEBUG``.
512
513 For example to log to syslog you can use :
514
515 .. code-block:: python
516
517 LOGGING = {
518 'version': 1,
519 'disable_existing_loggers': False,
520 'formatters': {
521 'cas_syslog': {
522 'format': 'cas: %(levelname)s %(message)s'
523 },
524 },
525 'handlers': {
526 'cas_syslog': {
527 'level': 'INFO',
528 'class': 'logging.handlers.SysLogHandler',
529 'address': '/dev/log',
530 'formatter': 'cas_syslog',
531 },
532 },
533 'loggers': {
534 'cas_server': {
535 'handlers': ['cas_syslog'],
536 'level': 'INFO',
537 'propagate': True,
538 },
539 },
540 }
541
542
543 Or to log to a file:
544
545 .. code-block:: python
546
547 LOGGING = {
548 'version': 1,
549 'disable_existing_loggers': False,
550 'formatters': {
551 'cas_file': {
552 'format': '%(asctime)s %(levelname)s %(message)s'
553 },
554 },
555 'handlers': {
556 'cas_file': {
557 'level': 'INFO',
558 'class': 'logging.FileHandler',
559 'filename': '/tmp/cas_server.log',
560 'formatter': 'cas_file',
561 },
562 },
563 'loggers': {
564 'cas_server': {
565 'handlers': ['cas_file'],
566 'level': 'INFO',
567 'propagate': True,
568 },
569 },
570 }
571
572 Service Patterns
573 ================
574
575 In a CAS context, ``Service`` refers to the application the client is trying to access.
576 By extension we use ``service`` for the URL of such an application.
577
578 By default, ``django-cas-server`` does not allow any service to use the CAS to authenticate users.
579 In order to allow services, you need to connect to the django admin interface using a django
580 superuser, and add a first service pattern.
581
582 A service pattern comes with 9 fields:
583
584 * ``Position``: an integer used to change the order in which services are matched against
585 service patterns.
586 * ``Name``: the name of the service pattern. It will be displayed to the users asking for a ticket
587 for a service matching this service pattern on the login page.
588 * ``Pattern``: a regular expression used to match services.
589 * ``User field``: the user attribute to use as username for services matching this service pattern.
590 Leave it empty to use the login name.
591 * ``Restrict username``: if checked, only login names defined below are allowed to get tickets
592 for services matching this service pattern.
593 * ``Proxy``: if checked, allow the creation of Proxy Ticket for services matching this
594 service pattern. Otherwise, only Service Ticket will be created.
595 * ``Proxy callback``: if checked, services matching this service pattern are allowed to retrieve Proxy
596 Granting Ticket. A service with a Proxy Granting Ticket can get Proxy Ticket for other services.
597 Hence you must only check this for trusted services that need it. (For instance, a webmail needs
598 Proxy Ticket to authenticate himself as the user to the imap server).
599 * ``Single log out``: Check it to send Single Log Out requests to authenticated services matching
600 this service pattern. SLO requests are sent to all services the user is authenticated to when
601 the user disconnects.
602 * ``Single log out callback``: The http(s) URL to POST the SLO requests. If empty, the service URL
603 is used. This field is useful to allow non http services (imap, smtp, ftp) to handle SLO requests.
604
605 A service pattern has 4 associated models:
606
607 * ``Usernames``: a list of username associated with the ``Restrict username`` field
608 * ``Replace attribute names``: a list of user attributes to send to the service. Choose the name
609 used for sending the attribute by setting ``Replacement`` or leave it empty to leave it unchanged.
610 * ``Replace attribute values``: a list of sent user attributes for which value needs to be tweaked.
611 Replace the attribute value by the string obtained by replacing the leftmost non-overlapping
612 occurrences of ``pattern`` in string by ``replace``. In ``replace`` backslash escapes are processed.
613 Matched groups are captured by \1, \2, etc.
614 * ``Filter attribute values``: a list of user attributes for which value needs to match a regular
615 expression. For instance, service A may need an email address, and you only want user with
616 an email address to connect to it. To do so, put ``email`` in ``Attribute`` and ``.*`` in ``pattern``.
617
618 When a user asks for a ticket for a service, the service URL is compared against each service pattern
619 sorted by ``position``. The first service pattern that matches the service URL is chosen.
620 Hence, you should give low ``position`` to very specific patterns like
621 ``^https://www\.example\.com(/.*)?$`` and higher ``position`` to generic patterns like ``^https://.*``.
622 So the service URL ``https://www.examle.com`` will use the service pattern for
623 ``^https://www\.example\.com(/.*)?$`` and not the one for ``^https://.*``.
624
625
626 Federation mode
627 ===============
628
629 ``django-cas-server`` comes with a federation mode. When ``CAS_FEDERATE`` is ``True``,
630 users are invited to choose an identity provider on the login page, then, they are redirected
631 to the provider CAS to authenticate. This provider transmits to ``django-cas-server`` the user
632 username and attributes. The user is now logged in on ``django-cas-server`` and can use
633 services using ``django-cas-server`` as CAS.
634
635 In federation mode, the user attributes are cached upon user authentication. See the settings
636 ``CAS_TGT_VALIDITY`` to force users to reauthenticate periodically and allow ``django-cas-server``
637 to refresh cached attributes.
638
639 The list of allowed identity providers is defined using the django admin application.
640 With the development server started, visit http://127.0.0.1:8000/admin/ to add identity providers.
641
642 An identity provider comes with 5 fields:
643
644 * ``Position``: an integer used to tweak the order in which identity providers are displayed on
645 the login page. Identity providers are sorted using position first, then, on equal position,
646 using ``verbose name`` and then, on equal ``verbose name``, using ``suffix``.
647 * ``Suffix``: the suffix that will be append to the username returned by the identity provider.
648 It must be unique.
649 * ``Server url``: the URL to the identity provider CAS. For instance, if you are using
650 ``https://cas.example.org/login`` to authenticate on the CAS, the ``server url`` is
651 ``https://cas.example.org``
652 * ``CAS protocol version``: the version of the CAS protocol to use to contact the identity provider.
653 The default is version 3.
654 * ``Verbose name``: the name used on the login page to display the identity provider.
655 * ``Display``: a boolean controlling the display of the identity provider on the login page.
656 Beware that this do not disable the identity provider, it just hide it on the login page.
657 User will always be able to log in using this provider by fetching ``/federate/provider_suffix``.
658
659
660 In federation mode, ``django-cas-server`` build user's username as follow:
661 ``provider_returned_username@provider_suffix``.
662 Choose the provider returned username for ``django-cas-server`` and the provider suffix
663 in order to make sense, as this built username is likely to be displayed to end users in
664 applications.
665
666
667 Then using federate mode, you should add one command to a daily crontab: ``cas_clean_federate``.
668 This command clean the local cache of federated user from old unused users.
669
670
671 You could for example do as below::
672
673 10 0 * * * cas-user /path/to/project/manage.py cas_clean_federate
674