From 6824b7957b2cb7d6ed399aaaf6e9151bb6d2b058 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Fri, 12 Feb 2016 11:50:03 -0500 Subject: [PATCH 1/9] Changed getElementsByTagNameNS Changed getElementsByTagNameNS to getElementsByTagName --- ftw/casauth/cas.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index 9c61fcb..4d14020 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -46,11 +46,9 @@ def validate_ticket(ticket, cas_server_url, service_url): doc = parseString(resp_data) except ExpatError: return False - auth_success = doc.getElementsByTagNameNS(CAS_NS, - 'authenticationSuccess') + auth_success = doc.getElementsByTagName('authenticationSuccess') if not auth_success: - auth_fail = doc.getElementsByTagNameNS(CAS_NS, - 'authenticationFailure') + auth_fail = doc.getElementsByTagName('authenticationFailure') if auth_fail: logger.info( "Authentication failed: Service ticket validation returned" @@ -60,7 +58,7 @@ def validate_ticket(ticket, cas_server_url, service_url): " ticket.") return False - userid = auth_success[0].getElementsByTagNameNS(CAS_NS, 'user') + userid = auth_success[0].getElementsByTagNameNS('user') if not userid: return False userid = userid[0].firstChild.data From be19a26bb43671428e40afa273298505833f209c Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Fri, 12 Feb 2016 15:45:53 -0500 Subject: [PATCH 2/9] latest --- .idea/vcs.xml | 6 ++++++ ftw/casauth/cas.py | 1 + setup.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index 4d14020..895f608 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -47,6 +47,7 @@ def validate_ticket(ticket, cas_server_url, service_url): except ExpatError: return False auth_success = doc.getElementsByTagName('authenticationSuccess') + print doc if not auth_success: auth_fail = doc.getElementsByTagName('authenticationFailure') if auth_fail: diff --git a/setup.py b/setup.py index 9532d12..da715f5 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os import sys -version = '1.0.1.dev0' +version = '1.0.1.pe82.2' tests_require = [ 'plone.app.testing', From a4d5f942fd320209aa8c560b98fa036bdc594580 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Fri, 12 Feb 2016 15:46:29 -0500 Subject: [PATCH 3/9] .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ef4c0a0..81ef8b7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ eggs/ parts/ src/ var/ +.idea +.gitignore From ce6a8546bbc402caead11e7253bc29715bf53292 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Fri, 12 Feb 2016 16:29:14 -0500 Subject: [PATCH 4/9] print auth_success added --- ftw/casauth/cas.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index 895f608..b21df85 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -47,7 +47,10 @@ def validate_ticket(ticket, cas_server_url, service_url): except ExpatError: return False auth_success = doc.getElementsByTagName('authenticationSuccess') + + print auth_success print doc + if not auth_success: auth_fail = doc.getElementsByTagName('authenticationFailure') if auth_fail: From b6dae953ebd0e3fa3692cec79510585a6befc452 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Fri, 12 Feb 2016 16:34:19 -0500 Subject: [PATCH 5/9] changed to logger --- ftw/casauth/cas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index b21df85..7db83ba 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -48,8 +48,8 @@ def validate_ticket(ticket, cas_server_url, service_url): return False auth_success = doc.getElementsByTagName('authenticationSuccess') - print auth_success - print doc + print logger.info(auth_success) + print logger.info(doc) if not auth_success: auth_fail = doc.getElementsByTagName('authenticationFailure') From 2fe62e9e88ea044676bcefd1a8fc9e95e5e61cf0 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Tue, 16 Feb 2016 14:40:57 -0500 Subject: [PATCH 6/9] latest --- ftw/casauth/cas.py | 13 ++++++++----- ftw/casauth/plugin.py | 3 ++- setup.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index 7db83ba..95f806e 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -2,7 +2,7 @@ import urllib import urllib2 from logging import getLogger -from xml.dom.minidom import parseString +from xml.dom.minidom import parseString, parse from xml.parsers.expat import ExpatError if USE_CUSTOM_HTTPS_HANDLER: @@ -10,21 +10,23 @@ else: from urllib2 import HTTPSHandler -CAS_NS = "http://www.yale.edu/tp/cas" - logger = getLogger('ftw.casauth') def validate_ticket(ticket, cas_server_url, service_url): """Validates a CAS service ticket and returns the authenticated userid. """ + logger.info("ticket:{}, cas_server_url: {}, service_url: {}".format(ticket, cas_server_url, service_url)) validate_url = '%s/serviceValidate?service=%s&ticket=%s' % ( cas_server_url, urllib.quote(service_url), ticket, ) + logger.info("Validate URL: " + validate_url) + logger.info("somemore stuff") opener = urllib2.build_opener(HTTPSHandler) + try: resp = opener.open(validate_url) except urllib2.HTTPError as e: @@ -48,8 +50,9 @@ def validate_ticket(ticket, cas_server_url, service_url): return False auth_success = doc.getElementsByTagName('authenticationSuccess') - print logger.info(auth_success) - print logger.info(doc) + logger.info(auth_success) + + logger.info(resp_data) if not auth_success: auth_fail = doc.getElementsByTagName('authenticationFailure') diff --git a/ftw/casauth/plugin.py b/ftw/casauth/plugin.py index 8a383ec..e01d64f 100644 --- a/ftw/casauth/plugin.py +++ b/ftw/casauth/plugin.py @@ -128,5 +128,6 @@ def manage_updateConfig(self, REQUEST): def _service_url(self, request): url = request['ACTUAL_URL'] if request['QUERY_STRING']: - url = '%s?%s' % (url, request['QUERY_STRING']) + #url = '%s?%s' % (url, request['QUERY_STRING']) + pass return url diff --git a/setup.py b/setup.py index da715f5..29b9af4 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os import sys -version = '1.0.1.pe82.2' +version = '1.1.2' tests_require = [ 'plone.app.testing', From 6bfd3ce032cee75e34fc0509306aae95af1db511 Mon Sep 17 00:00:00 2001 From: Pooya Eslami Date: Thu, 18 Feb 2016 09:51:52 -0500 Subject: [PATCH 7/9] Bug fixed and better logging --- ftw/casauth/cas.py | 18 ++++++++---------- setup.py | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ftw/casauth/cas.py b/ftw/casauth/cas.py index 95f806e..91d46c4 100644 --- a/ftw/casauth/cas.py +++ b/ftw/casauth/cas.py @@ -16,7 +16,6 @@ def validate_ticket(ticket, cas_server_url, service_url): """Validates a CAS service ticket and returns the authenticated userid. """ - logger.info("ticket:{}, cas_server_url: {}, service_url: {}".format(ticket, cas_server_url, service_url)) validate_url = '%s/serviceValidate?service=%s&ticket=%s' % ( cas_server_url, urllib.quote(service_url), @@ -24,7 +23,6 @@ def validate_ticket(ticket, cas_server_url, service_url): ) logger.info("Validate URL: " + validate_url) - logger.info("somemore stuff") opener = urllib2.build_opener(HTTPSHandler) try: @@ -46,17 +44,15 @@ def validate_ticket(ticket, cas_server_url, service_url): resp_data = resp.read() try: doc = parseString(resp_data) - except ExpatError: + except ExpatError as exp: + logger.info("ExpatError: %s" % exp.message) return False - auth_success = doc.getElementsByTagName('authenticationSuccess') - - logger.info(auth_success) - - logger.info(resp_data) + auth_success = doc.getElementsByTagName('cas:authenticationSuccess') if not auth_success: - auth_fail = doc.getElementsByTagName('authenticationFailure') + auth_fail = doc.getElementsByTagName('cas:authenticationFailure') if auth_fail: + logger.info('auth_fail is true, doc = {}'.format(doc.toprettyxml())) logger.info( "Authentication failed: Service ticket validation returned" " '%s'." % auth_fail[0].getAttribute('code')) @@ -65,9 +61,11 @@ def validate_ticket(ticket, cas_server_url, service_url): " ticket.") return False - userid = auth_success[0].getElementsByTagNameNS('user') + userid = auth_success[0].getElementsByTagName('cas:user') if not userid: return False userid = userid[0].firstChild.data + logger.info("Validated User ID: %s" % userid) + return userid diff --git a/setup.py b/setup.py index 29b9af4..f6069c9 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os import sys -version = '1.1.2' +version = '1.1.5' tests_require = [ 'plone.app.testing', From 51abc7286e92b663fb1406947ca66c0e2bcd9808 Mon Sep 17 00:00:00 2001 From: pe82 Date: Thu, 18 Feb 2016 09:56:44 -0500 Subject: [PATCH 8/9] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index f7542ef..7930ac2 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +8,7 @@ against a CAS (Central Autentication Server). It currently supports CAS 2.0 and CAS 3.0 protocols. +(pe82/ftw.casauth) Was debugged and tested with Plone 5 and CAS 3.3. Installation ============ From d735f1bb655c5f44b0a29ec228dd6114c2e3d7bc Mon Sep 17 00:00:00 2001 From: pe82 Date: Thu, 18 Feb 2016 09:57:24 -0500 Subject: [PATCH 9/9] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 7930ac2..0719faf 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ against a CAS (Central Autentication Server). It currently supports CAS 2.0 and CAS 3.0 protocols. -(pe82/ftw.casauth) Was debugged and tested with Plone 5 and CAS 3.3. +(pe82/ftw.casauth) Was debugged for and tested with Plone 5 and CAS 3.3. Installation ============