Commit ed2ca9b0 by Ed Crewe

switch on proxy auth if PT ticket

parent c59bbaf1
...@@ -96,6 +96,7 @@ def verify_proxy_ticket(ticket, service): ...@@ -96,6 +96,7 @@ 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 = []
if len(tree[0]) > 1:
for element in tree[0][1]: for element in tree[0][1]:
proxies.append(element.text) proxies.append(element.text)
return {"username": username, "proxies": proxies} return {"username": username, "proxies": proxies}
...@@ -112,13 +113,18 @@ if settings.CAS_VERSION not in _PROTOCOLS: ...@@ -112,13 +113,18 @@ 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'):
authdict = verify_proxy_ticket(ticket, service)
if authdict:
username = authdict.get('username','')
else:
username = _verify(ticket, service) username = _verify(ticket, service)
if not username: if not username:
return None return None
......
...@@ -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:
try:
pt_ticket = self.find_in_dom(page,['cas:proxySuccess', pt_ticket = self.find_in_dom(page,['cas:proxySuccess',
'cas:proxyTicket']) 'cas:proxyTicket'])
return pt_ticket 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