Commit ed2ca9b0 by Ed Crewe

switch on proxy auth if PT ticket

parent c59bbaf1
......@@ -96,8 +96,9 @@ def verify_proxy_ticket(ticket, service):
if tree[0].tag.endswith('authenticationSuccess'):
username = tree[0][0].text
proxies = []
for element in tree[0][1]:
proxies.append(element.text)
if len(tree[0]) > 1:
for element in tree[0][1]:
proxies.append(element.text)
return {"username": username, "proxies": proxies}
else:
return None
......@@ -112,14 +113,19 @@ if settings.CAS_VERSION not in _PROTOCOLS:
_verify = _PROTOCOLS[settings.CAS_VERSION]
SSO_PROXIED_PATHS = ['http://localhost:56000/portal']
class CASBackend(object):
"""CAS authentication backend"""
def authenticate(self, ticket, service):
"""Verifies CAS ticket and gets or creates User object"""
username = _verify(ticket, service)
if ticket.startswith('PT'):
authdict = verify_proxy_ticket(ticket, service)
if authdict:
username = authdict.get('username','')
else:
username = _verify(ticket, service)
if not username:
return None
try:
......
......@@ -253,9 +253,14 @@ class TestCAS(unittest.TestCase):
return 'FAIL: PTURL=%s not found' % url
page = pt.read()
if page.find('cas:serviceResponse') > -1:
pt_ticket = self.find_in_dom(page,['cas:proxySuccess',
'cas:proxyTicket'])
return pt_ticket
try:
pt_ticket = self.find_in_dom(page,['cas:proxySuccess',
'cas:proxyTicket'])
return pt_ticket
except:
print url
print page
return ''
return None
......@@ -268,6 +273,7 @@ class TestCAS(unittest.TestCase):
except:
return 'FAIL: PTURL=%s not found' % url
page = login.read()
print url
if page.find('cas:authenticationSuccess') > -1:
proxy = self.find_in_dom(page,['cas:proxies',
'cas:proxy'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment