Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-cas
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-cas
Commits
e3e7b55c
Commit
e3e7b55c
authored
Oct 10, 2011
by
Sebastian Annies
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow login via ?ticket=ST-* or PT-*
parent
fdc4f9c5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
20 deletions
+15
-20
django_cas/middleware.py
+15
-20
No files found.
django_cas/middleware.py
View file @
e3e7b55c
"""CAS authentication middleware"""
from
urllib
import
urlencode
from
django.http
import
HttpResponseRedirect
,
HttpResponseForbidden
from
django.conf
import
settings
from
django.contrib.auth
import
REDIRECT_FIELD_NAME
from
django.contrib.auth
import
logout
as
do_logout
from
django.contrib.auth.views
import
login
,
logout
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponseRedirect
,
HttpResponseForbidden
from
django_cas.exceptions
import
CasTicketException
from
django_cas.views
import
login
as
cas_login
,
logout
as
cas_logout
from
django_cas.views
import
login
as
cas_login
,
logout
as
cas_logout
,
_service_url
__all__
=
[
'CASMiddleware'
]
...
...
@@ -16,13 +16,18 @@ class CASMiddleware(object):
"""Middleware that allows CAS authentication on admin pages"""
def
process_request
(
self
,
request
):
"""Checks that the authentication middleware is installed"""
"""Logs in the user if a ticket is append as parameter"""
ticket
=
request
.
REQUEST
.
get
(
'ticket'
)
if
ticket
:
from
django.contrib
import
auth
user
=
auth
.
authenticate
(
ticket
=
ticket
,
service
=
_service_url
(
request
))
if
user
is
not
None
:
auth
.
login
(
request
,
user
)
error
=
(
"The Django CAS middleware requires authentication "
"middleware to be installed. Edit your MIDDLEWARE_CLASSES "
"setting to insert 'django.contrib.auth.middleware."
"AuthenticationMiddleware'."
)
assert
hasattr
(
request
,
'user'
),
error
def
process_view
(
self
,
request
,
view_func
,
view_args
,
view_kwargs
):
"""Forwards unauthenticated requests to the admin page to the CAS
...
...
@@ -50,13 +55,3 @@ class CASMiddleware(object):
return
HttpResponseForbidden
(
error
)
params
=
urlencode
({
REDIRECT_FIELD_NAME
:
request
.
get_full_path
()})
return
HttpResponseRedirect
(
reverse
(
cas_login
)
+
'?'
+
params
)
def
process_exception
(
self
,
request
,
exception
):
"""When we get a CasTicketException, that is probably caused by the ticket timing out.
So logout/login and get the same page again."""
if
isinstance
(
exception
,
CasTicketException
):
do_logout
(
request
)
# This assumes that request.path requires authentication.
return
HttpResponseRedirect
(
request
.
path
)
else
:
return
None
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment