Ignore:
Timestamp:
8 Jul 2013, 08:35:22 (11 years ago)
Author:
uli
Message:

Support /validate (CAS 1.0).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/server.py

    r10415 r10416  
    5959
    6060
     61def check_service_ticket(db, ticket, service, renew=False):
     62    """Check whether (`ticket`, `service`) represents a valid service
     63    ticket in `db`.
     64
     65    Returns a database set or ``None``.
     66    """
     67    if None in (ticket, service):
     68        return None
     69    ticket, service = str(ticket), str(service)
     70    q = db.query(ServiceTicket).filter(
     71        ServiceTicket.ticket == ticket).filter(
     72        ServiceTicket.service == service).first()
     73    if renew and q.sso:
     74        return None
     75    return q
     76
     77
    6178def create_login_ticket():
    6279    """Create a unique login ticket.
     
    7491    if lt_string is None:
    7592        return False
    76     q = db.query(LoginTicket).filter(LoginTicket.ticket == lt_string)
     93    q = db.query(LoginTicket).filter(LoginTicket.ticket == str(lt_string))
    7794    result = [x for x in q]
    7895    if result:
     
    283300
    284301    def validate(self, req):
    285         return exc.HTTPNotImplemented()
     302        service = req.POST.get('service', req.GET.get('service', None))
     303        ticket = req.POST.get('ticket', req.GET.get('ticket', None))
     304        renew = req.POST.get('renew', req.GET.get('renew', None))
     305        renew = renew is not None
     306        st = check_service_ticket(self.db, ticket, service, renew)
     307        if st is not None:
     308            return Response('yes' + chr(0x0a) + st.user + chr(0x0a))
     309        return Response('no' + chr(0x0a) + chr(0x0a))
    286310
    287311    def logout(self, req):
Note: See TracChangeset for help on using the changeset viewer.