From: Radek Czajka Date: Sat, 20 Sep 2014 22:11:53 +0000 (+0200) Subject: Can't have ForeignKey from PGT to ST, if ST is deleted immediately. X-Git-Tag: 22.4~10^2~3 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/2cf88a572643b5e54858f5d3b00d188b8e7230ed?ds=sidebyside;hp=--cc Can't have ForeignKey from PGT to ST, if ST is deleted immediately. --- 2cf88a572643b5e54858f5d3b00d188b8e7230ed diff --git a/cas_provider/migrations/0002_auto_20140920_1644.py b/cas_provider/migrations/0002_auto_20140920_1644.py new file mode 100644 index 0000000..5948a66 --- /dev/null +++ b/cas_provider/migrations/0002_auto_20140920_1644.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('cas_provider', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='proxygrantingticket', + name='serviceTicket', + ), + migrations.AddField( + model_name='proxygrantingticket', + name='pgt', + field=models.ForeignKey(to='cas_provider.ProxyGrantingTicket', null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='proxygrantingticket', + name='service', + field=models.URLField(null=True, verbose_name='service'), + preserve_default=True, + ), + migrations.AddField( + model_name='proxygrantingticket', + name='user', + field=models.ForeignKey(default=0, verbose_name='user', to=settings.AUTH_USER_MODEL), + preserve_default=False, + ), + ] diff --git a/cas_provider/models.py b/cas_provider/models.py index 43463d5..12fed4c 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -65,7 +65,9 @@ class LoginTicket(BaseTicket): class ProxyGrantingTicket(BaseTicket): - serviceTicket = models.ForeignKey(ServiceTicket, null=True) + user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user')) + service = models.URLField(_('service'), null=True) + pgt = models.ForeignKey('self', null=True) pgtiou = models.CharField(max_length=256, verbose_name=_('PGTiou')) prefix = 'PGT' diff --git a/cas_provider/views.py b/cas_provider/views.py index 0f53d38..126e3d1 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -239,7 +239,7 @@ def proxy(request): return _cas2_error_response(INVALID_TICKET) pt = ProxyTicket.objects.create(proxyGrantingTicket=proxyGrantingTicket, - user=proxyGrantingTicket.serviceTicket.user, + user=proxyGrantingTicket.user, service=targetService) return _cas2_proxy_success(pt.ticket) @@ -276,13 +276,9 @@ def ticket_validate(service, ticket_string, pgtUrl): if hasattr(ticket, 'proxyticket'): pgt = ticket.proxyticket.proxyGrantingTicket # I am issued by this proxy granting ticket - if hasattr(pgt.serviceTicket, 'proxyticket'): - while pgt: - if hasattr(pgt.serviceTicket, 'proxyticket'): - proxies += (pgt.serviceTicket.service,) - pgt = pgt.serviceTicket.proxyticket.proxyGrantingTicket - else: - pgt = None + while pgt.pgt is not None: + proxies += (pgt.service,) + pgt = pgt.pgt user = ticket.user ticket.delete() @@ -315,12 +311,10 @@ def generate_proxy_granting_ticket(pgt_url, ticket): uri = list(urlsplit(pgt_url)) pgt = ProxyGrantingTicket() - pgt.serviceTicket = ticket - pgt.targetService = pgt_url - - if hasattr(ticket, 'proxyGrantingTicket'): - # here we got a proxy ticket! tata! - pgt.pgt = ticket.proxyGrantingTicket + pgt.user = ticket.user + pgt.service = ticket.service + # Remember if it's a chained PGT. + pgt.pgt = getattr(ticket, 'proxyGrantingTicket', None) params = {'pgtId': pgt.ticket, 'pgtIou': pgt.pgtiou}