add a single_log_out parametters on Ticket for query optimisation
This commit is contained in:
parent
c9629f65ae
commit
7e2917e977
3 changed files with 49 additions and 14 deletions
32
cas_server/migrations/0015_auto_20150528_1202.py
Normal file
32
cas_server/migrations/0015_auto_20150528_1202.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cas_server', '0014_auto_20150528_0012'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='proxygrantingticket',
|
||||
name='single_log_out',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='proxyticket',
|
||||
name='single_log_out',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='serviceticket',
|
||||
name='single_log_out',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -17,10 +17,10 @@ from django.db import models
|
|||
from django.contrib import messages
|
||||
from picklefield.fields import PickledObjectField
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
|
||||
import re
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
|
||||
|
@ -69,15 +69,15 @@ class User(models.Model):
|
|||
"""Sending SLO request to all services the user logged in"""
|
||||
async_list = []
|
||||
session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
|
||||
for ticket in ServiceTicket.objects.filter(user=self, validate=True):
|
||||
async_list.append(ticket.logout(request, session))
|
||||
ticket.delete()
|
||||
for ticket in ProxyTicket.objects.filter(user=self, validate=True):
|
||||
async_list.append(ticket.logout(request, session))
|
||||
ticket.delete()
|
||||
for ticket in ProxyGrantingTicket.objects.filter(user=self, validate=True):
|
||||
async_list.append(ticket.logout(request, session))
|
||||
ticket.delete()
|
||||
ticket_classes = [ServiceTicket, ProxyTicket, ProxyGrantingTicket]
|
||||
for ticket_class in ticket_classes:
|
||||
for ticket in ticket_class.objects.filter(
|
||||
user=self,
|
||||
validate=True,
|
||||
single_log_out=True
|
||||
):
|
||||
async_list.append(ticket.logout(request, session))
|
||||
ticket.delete()
|
||||
for future in async_list:
|
||||
if future:
|
||||
try:
|
||||
|
@ -112,7 +112,8 @@ class User(models.Model):
|
|||
attributs=service_attributs,
|
||||
service=service,
|
||||
renew=renew,
|
||||
service_pattern=service_pattern
|
||||
service_pattern=service_pattern,
|
||||
single_log_out=service_pattern.single_log_out
|
||||
)
|
||||
ticket.save()
|
||||
return ticket
|
||||
|
@ -306,13 +307,14 @@ class Ticket(models.Model):
|
|||
service_pattern = models.ForeignKey(ServicePattern, related_name="%(class)s")
|
||||
creation = models.DateTimeField(auto_now_add=True)
|
||||
renew = models.BooleanField(default=False)
|
||||
single_log_out = models.BooleanField(default=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"Ticket(%s, %s)" % (self.user, self.service)
|
||||
|
||||
def logout(self, request, session):
|
||||
"""Send a SLO request to the ticket service"""
|
||||
if self.validate and self.service_pattern.single_log_out:
|
||||
if self.validate and self.single_log_out:
|
||||
xml = """<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
|
||||
ID="%(id)s" Version="2.0" IssueInstant="%(datetime)s">
|
||||
<saml:NameID xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"></saml:NameID>
|
||||
|
@ -320,7 +322,7 @@ class Ticket(models.Model):
|
|||
</samlp:LogoutRequest>""" % \
|
||||
{
|
||||
'id' : os.urandom(20).encode("hex"),
|
||||
'datetime' : int(time.time()),
|
||||
'datetime' : timezone.now().isoformat(),
|
||||
'ticket': self.value
|
||||
}
|
||||
headers = {'Content-Type': 'text/xml'}
|
||||
|
|
|
@ -288,7 +288,8 @@ def ps_validate(request, ticket_type=None):
|
|||
pticket = models.ProxyGrantingTicket.objects.create(
|
||||
user=ticket.user,
|
||||
service=pgt_url,
|
||||
service_pattern=pattern
|
||||
service_pattern=pattern,
|
||||
single_log_out=pattern.single_log_out
|
||||
)
|
||||
url = utils.update_url(pgt_url, {'pgtIou':proxyid, 'pgtId':pticket.value})
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue