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

Delete Tgt tickets if they are over 2 days old. #5

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions django_cas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django_cas.exceptions import CasTicketException, CasConfigException
# Ed Crewe - add in signals to delete old tickets
from django.db.models.signals import post_save
from datetime import datetime
from datetime import datetime, timedelta
# Single Sign Out
from django.contrib.auth import BACKEND_SESSION_KEY
from django.contrib.auth.signals import user_logged_out, user_logged_in
Expand All @@ -23,6 +23,7 @@
class Tgt(models.Model):
username = models.CharField(max_length=255, unique=True)
tgt = models.CharField(max_length=255)
created = models.DateTimeField(auto_now=True)

def get_proxy_ticket_for(self, service):
"""Verifies CAS 2.0+ XML-based authentication ticket.
Expand Down Expand Up @@ -73,16 +74,16 @@ def get_tgt_for(user):


def delete_old_tickets(**kwargs):
""" Delete tickets if they are over 2 days old
""" Delete tickets if they are over 2 days old
kwargs = ['raw', 'signal', 'instance', 'sender', 'created']
"""
sender = kwargs.get('sender', None)
now = datetime.now()
expire = datetime(now.year, now.month, now.day - 2)
expire = now - timedelta(days=2)
sender.objects.filter(created__lt=expire).delete()

post_save.connect(delete_old_tickets, sender=PgtIOU)
#post_save.connect(delete_old_tickets, sender=Tgt)
post_save.connect(delete_old_tickets, sender=Tgt)

#Import CASBackend after Tgt and PgtIOU class declaration
from django_cas.backends import CASBackend
Expand Down