3.5 KiB
3.5 KiB
Opus Magnum Submitter with CAS Authentication
A simple Django application that demonstrates CAS (Central Authentication Service) integration with PolyLAN's CAS server at https://polylan.ch/cas/.
Features
- 🔐 CAS authentication with PolyLAN
- 👤 Automatic user creation with custom attributes
- 🏷️ CAS groups and permissions storage
- 🏠 Protected home page requiring authentication
- 🌍 Public page accessible without authentication
- 🚪 Clean login/logout functionality
- 📱 Responsive web interface
- 🛠️ Admin interface for user management
Quick Start
-
Install dependencies:
pip install -e . -
Run database migrations:
cd opus_submitter uv run manage.py migrate -
Create a superuser (optional, for admin access):
uv run manage.py createsuperuser -
Start the development server:
uv run manage.py runserver localhost:7777 -
Access the application:
- Open your browser to http://localhost:7777/
- Try the public page: http://localhost:7777/public/
- Login with CAS to access protected features
- Admin interface: http://localhost:7777/admin/ (requires superuser)
How It Works
Authentication Flow
- User visits a protected page (e.g., home page)
- Django redirects to
/cas/login/ - CAS redirects to PolyLAN CAS server:
https://polylan.ch/cas/login - User enters credentials on PolyLAN
- CAS validates credentials and redirects back with a service ticket
- Django validates the ticket with the CAS server
- User is authenticated and redirected to the requested page
Configuration
The CAS configuration is in opus_submitter/settings.py:
# CAS Authentication Settings
CAS_SERVER_URL = 'https://polylan.ch/cas/'
CAS_VERSION = '3'
CAS_CREATE_USER = True
CAS_LOGOUT_COMPLETELY = True
URLs
/- Protected home page (requires authentication)/public/- Public page (no authentication required)/cas/login/- CAS login endpoint/cas/logout/- CAS logout endpoint/admin/- Django admin (requires staff privileges)
Project Structure
opus_submitter/
├── manage.py
├── opus_submitter/
│ ├── __init__.py
│ ├── settings.py # Django settings with CAS configuration
│ ├── urls.py # URL routing with CAS endpoints
│ ├── wsgi.py
│ └── asgi.py
└── templates/
├── base.html # Base template with navigation
├── home.html # Protected home page
└── public.html # Public page
Dependencies
- Django 5.2.7+
- django-cas-ng 5.0.1+ (CAS client for Django)
- requests 2.31.0+ (HTTP library for CAS communication)
Development
To modify the CAS configuration:
- Edit
CAS_SERVER_URLinsettings.pyif using a different CAS server - Adjust
CAS_VERSIONif needed (supports CAS 1.0, 2.0, and 3.0) - Set
CAS_CREATE_USER = Falseif you don't want automatic user creation
Testing
- Visit http://127.0.0.1:8000/public/ (should work without login)
- Visit http://127.0.0.1:8000/ (should redirect to CAS login)
- Login with your PolyLAN credentials
- Verify you're redirected back and can see user information
- Test logout functionality
Notes
- This is a development setup with
DEBUG = True - For production, update
SECRET_KEY, setDEBUG = False, and configureALLOWED_HOSTS - The application automatically creates Django users from CAS authentication
- User information is populated from CAS attributes when available