| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
| 3 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 4 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for |
| 5 |
# more details. |
| 6 |
# |
| 7 |
# You should have received a copy of the GNU General Public License version 3 |
| 8 |
# along with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 9 |
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 10 |
# |
| 11 |
# (c) 2015-2025 Valentin Samir |
| 12 |
"""Default values for the app's settings""" |
| 13 |
from django.conf import settings |
| 14 |
from django.templatetags.static import static |
| 15 |
|
| 16 |
from importlib import import_module |
| 17 |
|
| 18 |
import sys |
| 19 |
if sys.version_info < (3, ): |
| 20 |
from django.utils.translation import ugettext_lazy as _ |
| 21 |
else: |
| 22 |
from django.utils.translation import gettext_lazy as _ |
| 23 |
|
| 24 |
|
| 25 |
try: |
| 26 |
#: URL to the logo showed in the up left corner on the default templates. |
| 27 |
CAS_LOGO_URL = static("cas_server/logo.png") |
| 28 |
#: URL to the favicon (shortcut icon) used by the default templates. Default is a key icon. |
| 29 |
CAS_FAVICON_URL = static("cas_server/favicon.ico") |
| 30 |
# is settings.DEBUG is False and collectstatics has not been run yet, the static function will |
| 31 |
# raise a ValueError because the file is not found. |
| 32 |
except ValueError: |
| 33 |
#: URL to the logo showed in the up left corner on the default templates. |
| 34 |
CAS_LOGO_URL = None |
| 35 |
#: URL to the favicon (shortcut icon) used by the default templates. Default is a key icon. |
| 36 |
CAS_FAVICON_URL = None |
| 37 |
|
| 38 |
|
| 39 |
#: Show the powered by footer if set to ``True`` |
| 40 |
CAS_SHOW_POWERED = True |
| 41 |
#: URLs to css and javascript external components. |
| 42 |
CAS_COMPONENT_URLS = { |
| 43 |
"bootstrap3_css": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", |
| 44 |
"bootstrap3_js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js", |
| 45 |
"html5shiv": "https://cdn.jsdelivr.net/npm/[email protected]/dist/html5shiv.min.js", |
| 46 |
"respond": "https://cdn.jsdelivr.net/npm/[email protected]/dest/respond.min.js", |
| 47 |
"bootstrap4_css": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", |
| 48 |
"bootstrap4_js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js", |
| 49 |
"jquery": "https://code.jquery.com/jquery.min.js", |
| 50 |
} |
| 51 |
#: Path to the template showed on /login then the user is not autenticated. |
| 52 |
CAS_LOGIN_TEMPLATE = 'cas_server/bs4/login.html' |
| 53 |
#: Path to the template showed on /login?service=... then the user is authenticated and has asked |
| 54 |
#: to be warned before being connected to a service. |
| 55 |
CAS_WARN_TEMPLATE = 'cas_server/bs4/warn.html' |
| 56 |
#: Path to the template showed on /login then to user is authenticated. |
| 57 |
CAS_LOGGED_TEMPLATE = 'cas_server/bs4/logged.html' |
| 58 |
#: Path to the template showed on /logout then to user is being disconnected. |
| 59 |
CAS_LOGOUT_TEMPLATE = 'cas_server/bs4/logout.html' |
| 60 |
#: Should we redirect users to /login after they logged out instead of displaying |
| 61 |
#: :obj:`CAS_LOGOUT_TEMPLATE`. |
| 62 |
CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT = False |
| 63 |
|
| 64 |
|
| 65 |
#: A dotted path to a class or a class implementing cas_server.auth.AuthUser. |
| 66 |
CAS_AUTH_CLASS = 'cas_server.auth.DjangoAuthUser' |
| 67 |
#: Activate Kerberos authentication (not compatible with federate mode or auth class |
| 68 |
#: requiring access to the user credential to retrieve user attributes). |
| 69 |
#: See https://web.mit.edu/kerberos/krb5-1.13/doc/admin/env_variables.html |
| 70 |
#: for environment variables allowing to configure the underlying GSSAPI C library |
| 71 |
#: Username retrieved form kerberos auth MUST match username used by the ``CAS_AUTH_CLASS`` |
| 72 |
CAS_AUTH_GSSAPI_ENABLE = False |
| 73 |
#: SPN to use for Kerberos authentication (must be available in the loaded keytab) |
| 74 |
CAS_AUTH_GSSAPI_SERVICENAME = "host/[email protected]" |
| 75 |
#: Path to certificate authorities file. Usually on linux the local CAs are in |
| 76 |
#: /etc/ssl/certs/ca-certificates.crt. ``True`` tell requests to use its internal certificat |
| 77 |
#: authorities. |
| 78 |
CAS_PROXY_CA_CERTIFICATE_PATH = True |
| 79 |
#: Maximum number of parallel single log out requests send |
| 80 |
#: if more requests need to be send, there are queued |
| 81 |
CAS_SLO_MAX_PARALLEL_REQUESTS = 10 |
| 82 |
#: Timeout for a single SLO request in seconds. |
| 83 |
CAS_SLO_TIMEOUT = 5 |
| 84 |
#: Shared to transmit then using the view :class:`cas_server.views.Auth` |
| 85 |
CAS_AUTH_SHARED_SECRET = '' |
| 86 |
#: Max time after with the user MUST reauthenticate. Let it to `None` for no max time. |
| 87 |
#: This can be used to force refreshing cached informations only available upon user authentication |
| 88 |
#: like the user attributes in federation mode or with the ldap auth in bind mode. |
| 89 |
CAS_TGT_VALIDITY = None |
| 90 |
|
| 91 |
|
| 92 |
#: Number of seconds the service tickets and proxy tickets are valid. This is the maximal time |
| 93 |
#: between ticket issuance by the CAS and ticket validation by an application. |
| 94 |
CAS_TICKET_VALIDITY = 60 |
| 95 |
#: Number of seconds the proxy granting tickets are valid. |
| 96 |
CAS_PGT_VALIDITY = 3600 |
| 97 |
#: Number of seconds a ticket is kept in the database before sending Single Log Out request and |
| 98 |
#: being cleared. |
| 99 |
CAS_TICKET_TIMEOUT = 24*3600 |
| 100 |
|
| 101 |
|
| 102 |
#: All CAS implementation MUST support ST and PT up to 32 chars, |
| 103 |
#: PGT and PGTIOU up to 64 chars and it is RECOMMENDED that all |
| 104 |
#: tickets up to 256 chars are supports so we use 64 for the default |
| 105 |
#: len. |
| 106 |
CAS_TICKET_LEN = 64 |
| 107 |
|
| 108 |
#: alias of :obj:`settings.CAS_TICKET_LEN` |
| 109 |
CAS_LT_LEN = getattr(settings, 'CAS_TICKET_LEN', CAS_TICKET_LEN) |
| 110 |
#: alias of :obj:`settings.CAS_TICKET_LEN` |
| 111 |
#: Services MUST be able to accept service tickets of up to 32 characters in length. |
| 112 |
CAS_ST_LEN = getattr(settings, 'CAS_TICKET_LEN', CAS_TICKET_LEN) |
| 113 |
#: alias of :obj:`settings.CAS_TICKET_LEN` |
| 114 |
#: Back-end services MUST be able to accept proxy tickets of up to 32 characters. |
| 115 |
CAS_PT_LEN = getattr(settings, 'CAS_TICKET_LEN', CAS_TICKET_LEN) |
| 116 |
#: alias of :obj:`settings.CAS_TICKET_LEN` |
| 117 |
#: Services MUST be able to handle proxy-granting tickets of up to 64 |
| 118 |
CAS_PGT_LEN = getattr(settings, 'CAS_TICKET_LEN', CAS_TICKET_LEN) |
| 119 |
#: alias of :obj:`settings.CAS_TICKET_LEN` |
| 120 |
#: Services MUST be able to handle PGTIOUs of up to 64 characters in length. |
| 121 |
CAS_PGTIOU_LEN = getattr(settings, 'CAS_TICKET_LEN', CAS_TICKET_LEN) |
| 122 |
|
| 123 |
#: Prefix of login tickets. |
| 124 |
CAS_LOGIN_TICKET_PREFIX = u'LT' |
| 125 |
#: Prefix of service tickets. Service tickets MUST begin with the characters ST so you should not |
| 126 |
#: change this. |
| 127 |
CAS_SERVICE_TICKET_PREFIX = u'ST' |
| 128 |
#: Prefix of proxy ticket. Proxy tickets SHOULD begin with the characters, PT. |
| 129 |
CAS_PROXY_TICKET_PREFIX = u'PT' |
| 130 |
#: Prefix of proxy granting ticket. Proxy-granting tickets SHOULD begin with the characters PGT. |
| 131 |
CAS_PROXY_GRANTING_TICKET_PREFIX = u'PGT' |
| 132 |
#: Prefix of proxy granting ticket IOU. Proxy-granting ticket IOUs SHOULD begin with the characters |
| 133 |
#: PGTIOU. |
| 134 |
CAS_PROXY_GRANTING_TICKET_IOU_PREFIX = u'PGTIOU' |
| 135 |
|
| 136 |
|
| 137 |
#: Host for the SQL server. |
| 138 |
CAS_SQL_HOST = 'localhost' |
| 139 |
#: Username for connecting to the SQL server. |
| 140 |
CAS_SQL_USERNAME = '' |
| 141 |
#: Password for connecting to the SQL server. |
| 142 |
CAS_SQL_PASSWORD = '' |
| 143 |
#: Database name. |
| 144 |
CAS_SQL_DBNAME = '' |
| 145 |
#: Database charset. |
| 146 |
CAS_SQL_DBCHARSET = 'utf8' |
| 147 |
|
| 148 |
#: The query performed upon user authentication. |
| 149 |
CAS_SQL_USER_QUERY = 'SELECT user AS username, pass AS password, users.* FROM users WHERE user = %s' |
| 150 |
#: The method used to check the user password. Must be one of ``"crypt"``, ``"ldap"``, |
| 151 |
#: ``"hex_md5"``, ``"hex_sha1"``, ``"hex_sha224"``, ``"hex_sha256"``, ``"hex_sha384"``, |
| 152 |
#: ``"hex_sha512"``, ``"plain"``. |
| 153 |
CAS_SQL_PASSWORD_CHECK = 'crypt' |
| 154 |
#: charset the SQL users passwords was hash with |
| 155 |
CAS_SQL_PASSWORD_CHARSET = "utf-8" |
| 156 |
|
| 157 |
|
| 158 |
#: Address of the LDAP server |
| 159 |
CAS_LDAP_SERVER = 'localhost' |
| 160 |
#: LDAP user bind address, for example ``"cn=admin,dc=crans,dc=org"`` for connecting to the LDAP |
| 161 |
#: server. |
| 162 |
CAS_LDAP_USER = None |
| 163 |
#: LDAP connection password |
| 164 |
CAS_LDAP_PASSWORD = None |
| 165 |
#: LDAP seach base DN, for example ``"ou=data,dc=crans,dc=org"``. |
| 166 |
CAS_LDAP_BASE_DN = None |
| 167 |
#: LDAP search filter for searching user by username. User inputed usernames are escaped using |
| 168 |
#: :func:`ldap3.utils.conv.escape_bytes`. |
| 169 |
CAS_LDAP_USER_QUERY = "(uid=%(username)s)" |
| 170 |
#: LDAP attribute used for users usernames |
| 171 |
CAS_LDAP_USERNAME_ATTR = "uid" |
| 172 |
#: LDAP attribute used for users passwords |
| 173 |
CAS_LDAP_PASSWORD_ATTR = "userPassword" |
| 174 |
#: The method used to check the user password. Must be one of ``"crypt"``, ``"ldap"``, |
| 175 |
#: ``"hex_md5"``, ``"hex_sha1"``, ``"hex_sha224"``, ``"hex_sha256"``, ``"hex_sha384"``, |
| 176 |
#: ``"hex_sha512"``, ``"plain"``, ``"bind"``. |
| 177 |
CAS_LDAP_PASSWORD_CHECK = "ldap" |
| 178 |
#: charset the LDAP users passwords was hash with |
| 179 |
CAS_LDAP_PASSWORD_CHARSET = "utf-8" |
| 180 |
#: This parameter is only used then ``CAS_LDAP_PASSWORD_CHECK`` is set to ``"bind"``. |
| 181 |
#: |
| 182 |
#: * if ``0`` the user attributes are retrieved by connecting to the ldap as ``CAS_LDAP_USER``. |
| 183 |
#: * if ``1`` the user attributes are retrieve then the user authenticate using |
| 184 |
#: the user credentials. These attributes are then cached for the session. |
| 185 |
#: |
| 186 |
#: The default is ``0``. |
| 187 |
CAS_LDAP_ATTRS_VIEW = 0 |
| 188 |
|
| 189 |
|
| 190 |
#: Username of the test user. |
| 191 |
CAS_TEST_USER = 'test' |
| 192 |
#: Password of the test user. |
| 193 |
CAS_TEST_PASSWORD = 'test' |
| 194 |
#: Attributes of the test user. |
| 195 |
CAS_TEST_ATTRIBUTES = { |
| 196 |
'nom': 'Nymous', |
| 197 |
'prenom': 'Ano', |
| 198 |
'email': '[email protected]', |
| 199 |
'alias': ['demo1', 'demo2'] |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
#: A :class:`bool` for activatinc the hability to fetch tickets using javascript. |
| 204 |
CAS_ENABLE_AJAX_AUTH = False |
| 205 |
|
| 206 |
|
| 207 |
#: A :class:`bool` for activating the federated mode |
| 208 |
CAS_FEDERATE = False |
| 209 |
#: Time after witch the cookie use for “remember my identity provider” expire (one week). |
| 210 |
CAS_FEDERATE_REMEMBER_TIMEOUT = 604800 |
| 211 |
|
| 212 |
#: A :class:`bool` for diplaying a warning on html pages then a new version of the application |
| 213 |
#: is avaible. Once closed by a user, it is not displayed to this user until the next new version. |
| 214 |
CAS_NEW_VERSION_HTML_WARNING = True |
| 215 |
#: A :class:`bool` for sending emails to ``settings.ADMINS`` when a new version is available. |
| 216 |
CAS_NEW_VERSION_EMAIL_WARNING = True |
| 217 |
#: URL to the pypi json of the application. Used to retreive the version number of the last version. |
| 218 |
#: You should not change it. |
| 219 |
CAS_NEW_VERSION_JSON_URL = "https://pypi.org/pypi/django-cas-server/json" |
| 220 |
|
| 221 |
#: If the service message should be displayed on the login page |
| 222 |
CAS_SHOW_SERVICE_MESSAGES = True |
| 223 |
|
| 224 |
#: Messages displayed in a info-box on the html pages of the default templates. |
| 225 |
#: ``CAS_INFO_MESSAGES`` is a :class:`dict` mapping message name to a message :class:`dict`. |
| 226 |
#: A message :class:`dict` has 3 keys: |
| 227 |
#: |
| 228 |
#: * ``message``: A :class:`unicode`, the message to display, potentially wrapped around |
| 229 |
#: ugettex_lazy |
| 230 |
#: * ``discardable``: A :class:`bool`, specify if the users can close the message info-box |
| 231 |
#: * ``type``: One of info, success, info, warning, danger. The type of the info-box. |
| 232 |
#: |
| 233 |
#: ``CAS_INFO_MESSAGES`` contains by default one message, ``cas_explained``, which explain |
| 234 |
#: roughly the purpose of a CAS. |
| 235 |
CAS_INFO_MESSAGES = { |
| 236 |
"cas_explained": { |
| 237 |
"message": _( |
| 238 |
u"The Central Authentication Service grants you access to most of our websites by " |
| 239 |
u"authenticating only once, so you don't need to type your credentials again unless " |
| 240 |
u"your session expires or you logout." |
| 241 |
), |
| 242 |
"discardable": True, |
| 243 |
"type": "info", # one of info, success, info, warning, danger |
| 244 |
}, |
| 245 |
} |
| 246 |
#: :class:`list` of message names. Order in which info-box messages are displayed. |
| 247 |
#: Let the list empty to disable messages display. |
| 248 |
CAS_INFO_MESSAGES_ORDER = [] |
| 249 |
|
| 250 |
#: :class:`bool` If `True` Django session cookie will be removed on logout from CAS server |
| 251 |
CAS_REMOVE_DJANGO_SESSION_COOKIE_ON_LOGOUT = False |
| 252 |
#: :class:`bool` If `True` Django csrf cookie will be removed on logout from CAS server |
| 253 |
CAS_REMOVE_DJANGO_CSRF_COOKIE_ON_LOGOUT = False |
| 254 |
#: :class:`bool` If `True` Django language cookie will be removed on logout from CAS server |
| 255 |
CAS_REMOVE_DJANGO_LANGUAGE_COOKIE_ON_LOGOUT = False |
| 256 |
|
| 257 |
#: A dotted path to a form or a form used on the login page to retrieve user credentials |
| 258 |
CAS_USER_CREDENTIAL_FORM = "cas_server.forms.UserCredential" |
| 259 |
#: A dotted path to a form or a form used on warn page before emitting a ticket |
| 260 |
CAS_WARN_FORM = "cas_server.forms.WarnForm" |
| 261 |
#: A dotted path to a form or a form used on the login page to select another CAS in federated mode |
| 262 |
CAS_FEDERATE_SELECT_FORM = "cas_server.forms.FederateSelect" |
| 263 |
#: A dotted path to a form or a form used on the login page in federated mode |
| 264 |
CAS_FEDERATE_USER_CREDENTIAL_FORM = "cas_server.forms.FederateUserCredential" |
| 265 |
#: A dotted path to a form or a form for Tickets in the admin interface |
| 266 |
CAS_TICKET_FORM = "cas_server.forms.TicketForm" |
| 267 |
|
| 268 |
GLOBALS = globals().copy() |
| 269 |
for name, default_value in GLOBALS.items(): |
| 270 |
# only care about parameter begining by CAS_ |
| 271 |
if name.startswith("CAS_"): |
| 272 |
# get the current setting value, falling back to default_value |
| 273 |
value = getattr(settings, name, default_value) |
| 274 |
# set the setting value to its value if defined, else to the default_value. |
| 275 |
setattr(settings, name, value) |
| 276 |
|
| 277 |
# Allow the user defined CAS_COMPONENT_URLS to omit not changed values |
| 278 |
MERGED_CAS_COMPONENT_URLS = CAS_COMPONENT_URLS.copy() |
| 279 |
MERGED_CAS_COMPONENT_URLS.update(settings.CAS_COMPONENT_URLS) |
| 280 |
settings.CAS_COMPONENT_URLS = MERGED_CAS_COMPONENT_URLS |
| 281 |
|
| 282 |
# if the federated mode is enabled, we must use the :class`cas_server.auth.CASFederateAuth` auth |
| 283 |
# backend. |
| 284 |
if settings.CAS_FEDERATE: |
| 285 |
settings.CAS_AUTH_CLASS = "cas_server.auth.CASFederateAuth" |
| 286 |
|
| 287 |
|
| 288 |
#: SessionStore class depending of :django:setting:`SESSION_ENGINE` |
| 289 |
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore |