Changeset 8742


Ignore:
Timestamp:
26/03/13 16:12:12 (6 years ago)
Author:
mnagni
Message:

Incomplete - # 22698: [CEDA Site Python Port] MyCEDA Login needs to be more user-friendly
 http://team.ceda.ac.uk/trac/ceda/ticket/22698

Location:
mauRepo/dj_security_middleware/trunk/dj_security_middleware
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/README

    r8696 r8742  
    1717returned by the authentication service and from this moment the underlying  
    1818application is responsible for them.  
     19 
     20If the request, GET or POST, contains a parameter 'logout' with value different from '' 
     21then the 'auth_tkt' will be removed from the next response  
    1922 
    2023The configuration is quite straightforward. In your Django app settings.py add: 
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/dj_security_middleware/middleware.py

    r8725 r8742  
    4343import re 
    4444import base64 
     45from django.contrib.auth.views import logout 
     46from cookielib import CookieJar 
    4547 
    4648# Get an instance of a logger 
     
    6163is defined in the application settings.py file. \ 
    6264Please define it accordingly to the machine/proxy seen by the LOGIN_SERVICE' 
     65 
     66AUTH_TKT = 'auth_tkt' 
    6367 
    6468class DJ_Security_Middleware(object): 
     
    110114        return HttpResponseRedirect(url)            
    111115             
     116    def process_response(self, request, response): 
     117        if len(request.REQUEST.get('logout', '')) > 0: 
     118            response.delete_cookie(AUTH_TKT) 
     119        return response  
    112120 
    113121def _build_ret_url(request): 
     
    127135        ** raise ** a DJ_SecurityException if the ticket is not valid 
    128136    """  
    129     if 'auth_tkt' in request.COOKIES: 
     137    if AUTH_TKT in request.COOKIES: 
    130138        LOGGER.debug("Found auth_tkt: %s in cookies" % (request.COOKIES.get('auth_tkt'))) 
    131139        try: 
     
    133141            return auth_tkt.parse_ticket( 
    134142                    settings.DJ_SECURITY_SHAREDSECRET,  
    135                     request.COOKIES.get('auth_tkt', ''),  
     143                    request.COOKIES.get(AUTH_TKT, ''),  
    136144                    _get_host_ip()) 
    137145        except BadTicket as ex: 
    138             raise DJMiddlewareException(ex) 
    139         finally: 
    140             request.COOKIES.pop('auth_tkt', None)  
     146            raise DJMiddlewareException(ex)  
    141147    raise MissingCookieException(AUTHENTICATION_COOKIE_MISSING) 
    142148    
     
    195201        if re.match(ifilter, string): 
    196202            return True 
     203         
     204def logout(request): 
     205    """ 
     206        Removes the authenticated user's ID from the request and flushes their 
     207        session data, plus remove the auth_cookie 
     208    """ 
     209    logout(request) 
     210    CookieJar.clear(name = 'auth_tkt') 
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/setup.py

    r8655 r8742  
    2626 
    2727    # Adds dependencies     
    28     install_requires = ['Django', \ 
     28    install_requires = ['psycopg2', 
     29                        'Django==1.4.5', \ 
    2930                        'Paste==1.7.5.1'], 
    3031) 
Note: See TracChangeset for help on using the changeset viewer.