diff --git a/cms/djangoapps/contentstore/views/public.py b/cms/djangoapps/contentstore/views/public.py index 63f95084aa..da805a7bd7 100644 --- a/cms/djangoapps/contentstore/views/public.py +++ b/cms/djangoapps/contentstore/views/public.py @@ -44,6 +44,10 @@ def login_page(request): # to course now that the user is authenticated via # the decorator. return redirect('/course') + if settings.FEATURES.get('AUTH_USE_CAS'): + # If CAS is enabled, redirect auth handling to there + return redirect(reverse('cas-login')) + return render_to_response( 'login.html', { diff --git a/cms/envs/aws.py b/cms/envs/aws.py index 3147ad3cd7..383d6925e0 100644 --- a/cms/envs/aws.py +++ b/cms/envs/aws.py @@ -181,6 +181,16 @@ PLATFORM_NAME = ENV_TOKENS.get('PLATFORM_NAME', 'edX') if "TRACKING_IGNORE_URL_PATTERNS" in ENV_TOKENS: TRACKING_IGNORE_URL_PATTERNS = ENV_TOKENS.get("TRACKING_IGNORE_URL_PATTERNS") +# Django CAS external authentication settings +CAS_EXTRA_LOGIN_PARAMS = ENV_TOKENS.get("CAS_EXTRA_LOGIN_PARAMS", None) +if FEATURES.get('AUTH_USE_CAS'): + CAS_SERVER_URL = ENV_TOKENS.get("CAS_SERVER_URL", None) + AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'django_cas.backends.CASBackend', + ) + INSTALLED_APPS += ('django_cas',) + MIDDLEWARE_CLASSES += ('django_cas.middleware.CASMiddleware',) ################ SECURE AUTH ITEMS ############################### # Secret things: passwords, access keys, etc. diff --git a/cms/urls.py b/cms/urls.py index 65d19e83f7..063995117e 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -115,6 +115,12 @@ if settings.FEATURES.get('ENABLE_SERVICE_STATUS'): url(r'^status/', include('service_status.urls')), ) +if settings.FEATURES.get('AUTH_USE_CAS'): + urlpatterns += ( + url(r'^cas-auth/login/$', 'external_auth.views.cas_login', name="cas-login"), + url(r'^cas-auth/logout/$', 'django_cas.views.logout', {'next_page': '/'}, name="cas-logout"), + ) + urlpatterns += patterns('', url(r'^admin/', include(admin.site.urls)),) # enable automatic login diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 2c802d3f4f..eacad70210 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -344,6 +344,9 @@ def signin_user(request): # branding and allow that to process the login if it # is enabled and the header is in the request. return redirect(reverse('root')) + if settings.FEATURES.get('AUTH_USE_CAS'): + # If CAS is enabled, redirect auth handling to there + return redirect(reverse('cas-login')) if request.user.is_authenticated(): return redirect(reverse('dashboard')) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index ee424f84cc..373704b5e2 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -258,6 +258,17 @@ SSL_AUTH_EMAIL_DOMAIN = ENV_TOKENS.get("SSL_AUTH_EMAIL_DOMAIN", "MIT.EDU") SSL_AUTH_DN_FORMAT_STRING = ENV_TOKENS.get("SSL_AUTH_DN_FORMAT_STRING", "/C=US/ST=Massachusetts/O=Massachusetts Institute of Technology/OU=Client CA v1/CN={0}/emailAddress={1}") +# Django CAS external authentication settings +CAS_EXTRA_LOGIN_PARAMS = ENV_TOKENS.get("CAS_EXTRA_LOGIN_PARAMS", None) +if FEATURES.get('AUTH_USE_CAS'): + CAS_SERVER_URL = ENV_TOKENS.get("CAS_SERVER_URL", None) + AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'django_cas.backends.CASBackend', + ) + INSTALLED_APPS += ('django_cas',) + MIDDLEWARE_CLASSES += ('django_cas.middleware.CASMiddleware',) + HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS = ENV_TOKENS.get('HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS',{}) ############################## SECURE AUTH ITEMS ############### diff --git a/lms/envs/common.py b/lms/envs/common.py index 1b8ebb3eae..d08f4be9ac 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1199,17 +1199,6 @@ VERIFY_STUDENT = { if FEATURES.get('CLASS_DASHBOARD'): INSTALLED_APPS += ('class_dashboard',) -######################## CAS authentication ########################### - -if FEATURES.get('AUTH_USE_CAS'): - CAS_SERVER_URL = 'https://provide_your_cas_url_here' - AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'django_cas.backends.CASBackend', - ) - INSTALLED_APPS += ('django_cas',) - MIDDLEWARE_CLASSES += ('django_cas.middleware.CASMiddleware',) - ###################### Registration ################################## # For each of the fields, give one of the following values: