Package: pucas
django-pucasis a reusableDjangoapplication to simplify logging
into a Django application with CAS usingdjango-cas-ng.  Login and
creation of user accounts is handled by django-cas-ng; pucas adds
support for prepopulating user account data based on an LDAP search.pucasshould be pronounced likepookasfor the Celtic spirit creature.django-pucasis tested against:Django3.2-4.0Python3.9-3.11django-pucasrequiresdjango-cas-ng3.6 or greater.InstallationUse pip to install:pip install pucasYou can also install from Github.  Use@masteror@0.5to install a
specific tagged release or branch (e.g., for the lastest code ondevelop):pip install git+https://github.com/Princeton-CDH/django-pucas.git@develop#egg=pucasConfigurationAdd both django-cas-ng and pucas to installed apps; enable authentication
middleware and django-cas-ng authentication backend:INSTALLED_APPS = (
    ...
    'django_cas_ng',
    'pucas',
    ...
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    ...
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django_cas_ng.backends.CASBackend',
)Include the default django-cas-ng login and logout urls provided with pucas,
or configure them as needed based on the documentation:urlpatterns = [
    ...
    url(r'^accounts/', include('pucas.cas_urls')),
    ...
]Add required configurations tosettings.py:CAS_SERVER_URL- Base URL of your CAS sourceConfigure LDAP settings as needed to populate user attributes:PUCAS_LDAP = {
    'SERVERS': ['ldap1', 'ldap2'],
    'SEARCH_BASE': 'ou=users,dc=example,dc=com',
    'SEARCH_FILTER': "(uid=%(user)s)",
    # attributes to request from the LDAP server
    'ATTRIBUTES': ['givenName', 'sn', 'mail'],
    # mapping of User attributes to LDAP attributes
    # if passed list for the value, the first attribute to return a
    # value will be used
    'ATTRIBUTE_MAP': {
        'first_name': 'givenName',
        'last_name': 'sn',
        'email': ['mail', 'eduPersonPrincipalName']
    },
    # Optional local method to do additional user initialization
    # not handled by attribute map.  Method should take a user
    # object and ldap search result.
    'EXTRA_USER_INIT': 'myproj.myapp.models.init_profile_from_ldap'
    'BIND_DN': 'uid=username,o=your org,c=country_code',
    'BIND_PASSWORD': 'secreupasswordforyourldap',
}Note:BIND_DNandBIND_PASSWORDare optional if you wantto bind anonymously. Add them if they are required by your LDAP.
This supports user/pass authentication.Run migrations to create database tables required by django-cas-ng:python manage.py migrateTo make CAS login available on the Django admin login form, extend the
default admin login form and include or adapt the provided CAS login
template snippet.  An example admin login form is included atpucas/templates/pucas/sample-admin-login.html; copy this toadmin/login.htmlwithin a valid template directory and modify
as needed.An example of a login template with local branding is provided atpucas/templates/pucas/sample-pu-login.htmlusing re-usable template
snippets that can be adapted or re-used as appropriate.Note that login templates have not yet been updated for Django 3.x.UsageUsers can login with CAS and have a Django user account automatically
created and populated with LDAP data based on the settings.Two manage commands are provided, for convenience.Usepython manage.py ldapsearch netid1 netid2 netid3for testing
your LDAP configuration and attributes.Usepython manage.py createcasuser netidto initialize a new
CAS account and populate data from LDAP without requiring the user
to login first, as an aid to managing accounts and permissions.
The optional flag--adminwill give the new account superuser
permissionsDevelopment instructionsThis git repository uses git flow branching conventions, withmainas the current production release branch.Initial setup and installation:recommended: create and activate a python 3.5 virtualenv:virtualenv pucas -p python3.5
source pucas/bin/activatepip install the package with its python dependencies:pip install -e .Unit TestingUnit tests are written withpy.testbut use some
Django test classes for compatibility with django test suites.  Running
the tests requires a minimal settings file for Django required configurations.Copy sample test settings and add a secret key:cp ci/testsettings.py testsettings.pyTo run the tests, either use the configured setup.py test command:python setup.py testOr install test requirements and use py.test directly:pip install -e '.[test]'
py.testLicensedjango-pucasis distributed under the Apache 2.0 License.©2016 Trustees of Princeton University.  Permission granted via
Princeton Docket #18-3398-1 for distribution online under a standard Open Source
license.  Ownership rights transferred to Rebecca Koeser provided software
is distributed online via open source.