X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/09adf9da3df6fc5807c5b1710f967b39c101ba6c..611a6c53c6fe16bee0673b0a815d1f35ce303360:/cas_provider/views.py diff --git a/cas_provider/views.py b/cas_provider/views.py index 2769e52..953847b 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -1,3 +1,4 @@ +import logging from lxml import etree from urllib import urlencode import urllib2 @@ -29,6 +30,8 @@ ERROR_MESSAGES = ( ) +logger = logging.getLogger(__name__) + def login(request, template_name='cas/login.html',\ success_redirect=settings.LOGIN_REDIRECT_URL, warn_template_name='cas/warn.html', @@ -101,18 +104,13 @@ def logout(request, template_name='cas/logout.html', def proxy(request): targetService = request.GET['targetService'] - pgtiou = request.GET['pgt'] + pgt_id = request.GET['pgt'] try: - proxyGrantingTicket = ProxyGrantingTicket.objects.get(pgtiou=pgtiou) + proxyGrantingTicket = ProxyGrantingTicket.objects.get(ticket=pgt_id) except ProxyGrantingTicket.DoesNotExist: return _cas2_error_response(INVALID_TICKET) - if not proxyGrantingTicket.targetService == targetService: - return _cas2_error_response(INVALID_SERVICE, - "The PGT was issued for %(original)s but the PT was requested for %(but)s" % dict( - original=proxyGrantingTicket.targetService, but=targetService)) - pt = ProxyTicket.objects.create(proxyGrantingTicket=proxyGrantingTicket, user=proxyGrantingTicket.serviceTicket.user, service=targetService) @@ -135,7 +133,10 @@ def ticket_validate(service, ticket_string, pgtUrl): except ServiceTicket.DoesNotExist: return _cas2_error_response(INVALID_TICKET) - if ticket.service != service: + ticketUrl = urlparse.urlparse(ticket.service) + serviceUrl = urlparse.urlparse(service) + + if not(ticketUrl.hostname == serviceUrl.hostname and ticketUrl.path == serviceUrl.path and ticketUrl.port == serviceUrl.port): return _cas2_error_response(INVALID_SERVICE) pgtIouId = None @@ -196,14 +197,16 @@ def generate_proxy_granting_ticket(pgt_url, ticket): query = dict(urlparse.parse_qsl(uri[4])) query.update(params) - uri[4] = urlencode(query) + uri[3] = urlencode(query) try: response = urllib2.urlopen(urlparse.urlunsplit(uri)) except urllib2.HTTPError, e: if not e.code in proxy_callback_good_status: + logger.debug('Checking Proxy Callback URL {} returned {}. Not issuing PGT.'.format(uri, e.code)) return except urllib2.URLError, e: + logger.debug('Checking Proxy Callback URL {} raised URLError. Not issuing PGT.'.format(uri)) return pgt.save()