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
23b76392
Commit
23b76392
authored
Dec 02, 2010
by
Ed Crewe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix callback to give a response on success or fail
parent
cbfe05d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
16 deletions
+49
-16
django_cas/tests/cas_tests.py
+38
-12
django_cas/views.py
+11
-4
No files found.
django_cas/tests/cas_tests.py
View file @
23b76392
...
...
@@ -58,15 +58,15 @@ class TestCAS(unittest.TestCase):
print
'Test proxy CAS login'
print
'--------------------'
iou
=
self
.
get_proxy_iou
()
if
iou
:
print
'
Got IOU:
%
s'
%
iou
if
iou
.
startswith
(
'PGT'
)
:
print
'
PASS: Got IOU -
%
s for
%
s'
%
(
iou
,
PROXY_URL
)
else
:
print
'Proxy CAS login failed, no IOU'
print
iou
pgt
=
self
.
get_proxy
(
iou
)
if
pgt
:
print
'
Got PGT:
%
s'
%
pgt
if
pgt
.
startswith
(
'PGT'
)
:
print
'
PASS: Got PGT -
%
s'
%
pgt
else
:
print
'Proxy CAS login failed, no PGT'
print
pgt
def
get_auth
(
self
):
""" Get authentication by passing to this script on the command line """
...
...
@@ -147,7 +147,9 @@ class TestCAS(unittest.TestCase):
return
def
get_proxy_iou
(
self
):
""" Use login ticket to get proxy iou """
""" Use login ticket to get proxy iou
NB: SSO server installation may require PROXY_URL/?pgtIou be called at the root
"""
url_args
=
(
CAS_SERVER_URL
,
self
.
ticket
,
APP_URL
,
PROXY_URL
)
url
=
'
%
s/serviceValidate?ticket=
%
s&service=
%
s&pgtUrl=
%
s'
%
url_args
try
:
...
...
@@ -162,16 +164,40 @@ class TestCAS(unittest.TestCase):
if
iou_ticket
:
return
iou_ticket
else
:
return
'FAIL: PGIOU Empty response from
%
s'
%
url
if
page
:
return
"FAIL: NO PGIOU
\n\n
%
s"
%
page
else
:
return
'FAIL: PGIOU Empty response from
%
s'
%
url
else
:
return
'FAIL: PGIOU Response failed authentication'
return
None
def
get_proxy
(
self
,
iou
):
def
get_proxy_pgt
(
self
,
iou
):
""" Get the proxy granting ticket from our django database backend
Assume this is not being hammered with requests so just get latest PGT
should of been created by get_proxy_iou callback request
"""
return
''
url_args
=
(
PROXY_URL
,
PROXY_PATH
,
iou
)
url
=
'
%
s
%
s?pgtIou=
%
s'
%
url_args
try
:
pgt
=
self
.
opener
.
open
(
url
)
except
:
return
'FAIL: PGTURL=
%
s not found'
%
url
page
=
pgt
.
read
()
return
page
if
page
.
find
(
'cas:authenticationSuccess'
)
>
-
1
:
pgt_ticket
=
self
.
find_in_dom
(
page
,[
'cas:serviceResponse'
,
'cas:authenticationSuccess'
,
'cas:proxyGrantingTicket'
])
return
pgt_ticket
return
None
def
get_proxy_pt
(
self
,
iou
):
""" Use login ticket to get proxy """
return
url_args
=
(
PROXY_URL
,
iou
)
url
=
'
%
s
/pgtCallback
?pgtIou=
%
s'
%
url_args
return
''
url_args
=
(
PROXY_URL
,
PROXY_PATH
,
iou
)
url
=
'
%
s
%
s
?pgtIou=
%
s'
%
url_args
try
:
pgt
=
self
.
opener
.
open
(
url
)
except
:
...
...
django_cas/views.py
View file @
23b76392
"""CAS login/logout replacement views"""
from
datetime
import
datetime
from
urllib
import
urlencode
from
urlparse
import
urljoin
...
...
@@ -109,9 +109,11 @@ def logout(request, next_page=None):
def
proxy_callback
(
request
):
"""Handles CAS 2.0+ XML-based proxy callback call.
Stores the proxy granting ticket in the database for
future use.
NB: Use created and set it in python in case database
has issues with setting up the default timestamp value
"""
pgtIou
=
request
.
GET
.
get
(
'pgtIou'
)
tgt
=
request
.
GET
.
get
(
'pgtId'
)
...
...
@@ -119,5 +121,10 @@ def proxy_callback(request):
if
not
(
pgtIou
and
tgt
):
return
HttpResponse
()
PgtIOU
.
objects
.
create
(
tgt
=
tgt
,
pgtIou
=
pgtIou
)
return
HttpResponse
()
try
:
PgtIOU
.
objects
.
create
(
tgt
=
tgt
,
pgtIou
=
pgtIou
,
created
=
datetime
.
now
())
except
:
return
HttpResponse
(
'PGT storage failed for
%
s'
%
str
(
request
.
GET
),
mimetype
=
"text/plain"
)
return
HttpResponse
(
'Success'
,
mimetype
=
"text/plain"
)
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