Commit ed2ca9b0 by Ed Crewe

switch on proxy auth if PT ticket

parent c59bbaf1
...@@ -96,8 +96,9 @@ def verify_proxy_ticket(ticket, service): ...@@ -96,8 +96,9 @@ def verify_proxy_ticket(ticket, service):
if tree[0].tag.endswith('authenticationSuccess'): if tree[0].tag.endswith('authenticationSuccess'):
username = tree[0][0].text username = tree[0][0].text
proxies = [] proxies = []
for element in tree[0][1]: if len(tree[0]) > 1:
proxies.append(element.text) for element in tree[0][1]:
proxies.append(element.text)
return {"username": username, "proxies": proxies} return {"username": username, "proxies": proxies}
else: else:
return None return None
...@@ -112,14 +113,19 @@ if settings.CAS_VERSION not in _PROTOCOLS: ...@@ -112,14 +113,19 @@ if settings.CAS_VERSION not in _PROTOCOLS:
_verify = _PROTOCOLS[settings.CAS_VERSION] _verify = _PROTOCOLS[settings.CAS_VERSION]
SSO_PROXIED_PATHS = ['http://localhost:56000/portal']
class CASBackend(object): class CASBackend(object):
"""CAS authentication backend""" """CAS authentication backend"""
def authenticate(self, ticket, service): def authenticate(self, ticket, service):
"""Verifies CAS ticket and gets or creates User object""" """Verifies CAS ticket and gets or creates User object"""
if ticket.startswith('PT'):
username = _verify(ticket, service) authdict = verify_proxy_ticket(ticket, service)
if authdict:
username = authdict.get('username','')
else:
username = _verify(ticket, service)
if not username: if not username:
return None return None
try: try:
......
...@@ -253,9 +253,14 @@ class TestCAS(unittest.TestCase): ...@@ -253,9 +253,14 @@ class TestCAS(unittest.TestCase):
return 'FAIL: PTURL=%s not found' % url return 'FAIL: PTURL=%s not found' % url
page = pt.read() page = pt.read()
if page.find('cas:serviceResponse') > -1: if page.find('cas:serviceResponse') > -1:
pt_ticket = self.find_in_dom(page,['cas:proxySuccess', try:
'cas:proxyTicket']) pt_ticket = self.find_in_dom(page,['cas:proxySuccess',
return pt_ticket 'cas:proxyTicket'])
return pt_ticket
except:
print url
print page
return ''
return None return None
...@@ -268,6 +273,7 @@ class TestCAS(unittest.TestCase): ...@@ -268,6 +273,7 @@ class TestCAS(unittest.TestCase):
except: except:
return 'FAIL: PTURL=%s not found' % url return 'FAIL: PTURL=%s not found' % url
page = login.read() page = login.read()
print url
if page.find('cas:authenticationSuccess') > -1: if page.find('cas:authenticationSuccess') > -1:
proxy = self.find_in_dom(page,['cas:proxies', proxy = self.find_in_dom(page,['cas:proxies',
'cas:proxy']) '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