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