Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for Plone5 and CAS 3.3 #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ eggs/
parts/
src/
var/
.idea
.gitignore
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 for and tested with Plone 5 and CAS 3.3.

Installation
============
Expand Down
21 changes: 12 additions & 9 deletions ftw/casauth/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
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:
from ftw.casauth.https import HTTPSHandler
else:
from urllib2 import HTTPSHandler

CAS_NS = "http://www.yale.edu/tp/cas"

logger = getLogger('ftw.casauth')


Expand All @@ -24,7 +22,9 @@ def validate_ticket(ticket, cas_server_url, service_url):
ticket,
)

logger.info("Validate URL: " + validate_url)
opener = urllib2.build_opener(HTTPSHandler)

try:
resp = opener.open(validate_url)
except urllib2.HTTPError as e:
Expand All @@ -44,14 +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.getElementsByTagNameNS(CAS_NS,
'authenticationSuccess')
auth_success = doc.getElementsByTagName('cas:authenticationSuccess')

if not auth_success:
auth_fail = doc.getElementsByTagNameNS(CAS_NS,
'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'))
Expand All @@ -60,9 +61,11 @@ def validate_ticket(ticket, cas_server_url, service_url):
" ticket.")
return False

userid = auth_success[0].getElementsByTagNameNS(CAS_NS, '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
3 changes: 2 additions & 1 deletion ftw/casauth/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys

version = '1.0.1.dev0'
version = '1.1.5'

tests_require = [
'plone.app.testing',
Expand Down