Changeset 8799 for mauRepo


Ignore:
Timestamp:
02/09/13 12:25:31 (6 years ago)
Author:
mnagni
Message:

Incomplete - # 22802: [CEDA Site Python Port] Login - no message is displayed when the user enters the wrong password
 http://team.ceda.ac.uk/trac/ceda/ticket/22802

Better cookie management

Location:
mauRepo/dj_security_middleware/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security_middleware/trunk/README

    r8795 r8799  
    2323The middleware is configurable through the local_setting.py 
    2424 
    25 1) DJ_SECURITY_LOGIN_SERVICE specifies where the URL where authentication service  
     251) SECURITY_LOGIN_SERVICE specifies where the URL where authentication service  
    2626is listening (say http://my.domain.ac.uk/login) 
    2727 
     
    38381) AUTH_TKT (default='auth_tkt'): the name of the cookie generated after the authentication succeed 
    3939 
    40 2) COOKIE_DOMAIN (default='.rl.ac.uk'): the domain where the AUTH_TKT will belong 
     402) COOKIE_DOMAIN (default= the SECURITY_LOGIN_SERVICE host): the domain where the AUTH_TKT will belong 
    4141 
    42423) SECURITY_SHAREDSECRET (default='sharedsecret') to specify  
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/__init__.py

    r8797 r8799  
    66import socket 
    77import urlparse 
     8from dj_security_middleware.exception import DJMiddlewareException 
     9 
     10LOGIN_SERVICE_ERROR = 'No LOGIN_SETTING parameter is defined in the \ 
     11application settings.py file. Please define a proper URL to the \ 
     12authenticating service' 
    813 
    914# Get an instance of a logger 
    1015LOGGER = logging.getLogger(__name__) 
     16 
     17def login_service(): 
     18    try: 
     19        return getattr(settings, 'SECURITY_LOGIN_SERVICE') 
     20    except AttributeError: 
     21        raise DJMiddlewareException(LOGIN_SERVICE_ERROR)  
    1122 
    1223def auth_tkt_name(): 
     
    1425 
    1526def cookie_domain(): 
    16     return getattr(settings, 'COOKIE_DOMAIN', '.rl.ac.uk') 
     27    try: 
     28        return getattr(settings, 'COOKIE_DOMAIN') 
     29    except AttributeError: 
     30        netloc = urlparse.urlparse(login_service()).netloc 
     31        if netloc.find(':') > 0: 
     32            return netloc[:netloc.index(':')] 
     33        return netloc 
    1734 
    1835def reset_password(): 
     
    6784            % (user.userkey, getattr("user", "accountid", "NotAssigned")))                
    6885    LOGGER.info("Created authTicket for %s from %s" % (user.accountid, remote_ip)) 
    69     idomain = getattr(settings, 'COOKIE_DOMAIN', None) 
    7086    response.set_cookie(auth_tkt_name(),  
    7187                        token.cookie_value(),  
    72                         domain = idomain) 
     88                        domain = cookie_domain()) 
    7389    LOGGER.debug("Set authTicket in response for %s from %s to domain %s"  
    74                  % (user.accountid, remote_ip, idomain)) 
     90                 % (user.accountid, remote_ip, cookie_domain())) 
    7591    return response 
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/middleware.py

    r8795 r8799  
    4040from dj_security_middleware.exception import DJMiddlewareException,\ 
    4141    MissingCookieException 
    42 from dj_security_middleware import _get_host_ip, security_filter, auth_tkt_name,\ 
    43     shared_secret, token_field_name, redirect_field_name, cookie_domain 
     42from dj_security_middleware import _get_host_ip, security_filter, \ 
     43auth_tkt_name, shared_secret, token_field_name, redirect_field_name, \ 
     44cookie_domain, login_service 
    4445 
    4546import socket 
     
    4748import re 
    4849import urllib 
    49  
    50 LOGIN_SERVICE_ERROR = 'No LOGIN_SETTING parameter is defined in the \ 
    51 application settings.py file. Please define a proper URL to the \ 
    52 authenticating service' 
    5350 
    5451DJ_SECURITY_SHAREDSECRET_ERROR = 'No SECURITY_SHAREDSECRET parameter \ 
     
    8582 
    8683    def process_request(self, request): 
     84        login_service()  
     85         
    8786        #Has to process a reset password request?  
    8887        if len(request.REQUEST.get(LOGOUT, '')) > 0: 
     
    103102            return 
    104103         
    105         if not getattr(settings, 'DJ_SECURITY_LOGIN_SERVICE', None): 
    106             raise DJMiddlewareException(LOGIN_SERVICE_ERROR)   
    107          
    108104        custom_auth = getattr(settings, 'DJ_SECURITY_AUTH_CHECK', None) 
    109105        if custom_auth: 
     
    122118            qs = {redirect_field_name():  
    123119                  urllib.quote_plus((_build_url(request)))}              
    124             url = '%s?%s' % (settings.DJ_SECURITY_LOGIN_SERVICE,  
     120            url = '%s?%s' % (login_service(),  
    125121                             urlencode(qs)) 
    126122            timestamp, userid, tokens, user_data = _is_authenticated(request) 
Note: See TracChangeset for help on using the changeset viewer.