Debian Codegraph @

README.rst

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