Changeset 8683 for mauRepo/dj_security_middleware/trunk/dj_security_middleware/dj_security_middleware/middleware.py
- Timestamp:
- 15/11/12 10:37:06 (8 years ago)
- Location:
- mauRepo/dj_security_middleware/trunk/dj_security_middleware
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/dj_security_middleware/trunk/dj_security_middleware
- Property svn:ignore
-
old new 2 2 3 3 dist 4 5 .settings 6 7 .project 8 9 .pydevproject
-
- Property svn:ignore
-
mauRepo/dj_security_middleware/trunk/dj_security_middleware/dj_security_middleware/middleware.py
r8675 r8683 31 31 @author: mnagni 32 32 ''' 33 from django.http import HttpResponseRedirect34 33 from paste.auth import auth_tkt 35 34 from paste.auth.auth_tkt import BadTicket … … 39 38 from django.utils.html import escape 40 39 from django.utils.http import urlencode 40 from django.http import HttpResponseRedirect 41 import socket 41 42 42 43 import logging … … 69 70 """ 70 71 def process_request(self, request): 71 if not settings.DJ_SECURITY_LOGIN_SERVICE:72 if not getattr(settings, 'DJ_SECURITY_LOGIN_SERVICE', None): 72 73 raise DJMiddlewareException(LOGIN_SERVICE_ERROR) 73 if not settings.DJ_SECURITY_SHAREDSECRET: 74 raise DJMiddlewareException(DJ_SECURITY_SHAREDSECRET_ERROR) 74 if not getattr(settings, 'DJ_SECURITY_SHAREDSECRET', None): 75 raise DJMiddlewareException(DJ_SECURITY_SHAREDSECRET_ERROR) 76 77 custom_auth = getattr(settings, 'DJ_SECURITY_AUTH_CHECK', None) 78 if custom_auth: 79 try: 80 if custom_auth(request): 81 return 82 #Cannot specify the Exception type as don't know the 83 # exceptions type raised by custom_auth 84 except Exception: 85 pass 86 75 87 #if not settings.DJ_MIDDLEWARE_IP: 76 88 # raise DJMiddlewareException(DJ_MIDDLEWARE_IP_ERROR) … … 78 90 try: 79 91 timestamp, userid, tokens, user_data = _is_authenticated(request) 80 except (MissingCookieException, DJMiddlewareException): 92 request.authenticated_user = {'timestamp': timestamp, \ 93 'userid': userid, \ 94 'tokens': tokens, \ 95 'user_data': user_data} 96 except (MissingCookieException, DJMiddlewareException): 81 97 url = '%s?%s' % (settings.DJ_SECURITY_LOGIN_SERVICE, _build_ret_url(request)) 82 return HttpResponseRedirect(url) 98 return HttpResponseRedirect(url) 99 83 100 84 101 def _build_ret_url(request): … … 98 115 ** raise ** a DJ_SecurityException if the ticket is not valid 99 116 """ 100 if request.COOKIES.has_key('auth_tkt'):117 if 'auth_tkt' in request.COOKIES: 101 118 try: 102 119 return auth_tkt.parse_ticket( 103 120 settings.DJ_SECURITY_SHAREDSECRET, 104 request.COOKIES['auth_tkt'], _get_host_ip()) 121 getattr(request.COOKIES, 'auth_tkt', ''), 122 _get_host_ip()) 105 123 except BadTicket as ex: 106 raise DJMiddlewareException(ex) 124 raise DJMiddlewareException(ex) 125 finally: 126 request.COOKIES.pop('auth_tkt', None) 107 127 raise MissingCookieException(AUTHENTICATION_COOKIE_MISSING) 108 128 109 129 def _get_hostname(): 110 import socket111 ret = 'localhost'112 130 try: 113 131 hostname = socket.gethostname() 114 ret =socket.gethostbyname_ex(hostname)[0]132 return socket.gethostbyname_ex(hostname)[0] 115 133 except Exception: 116 pass 117 return ret 134 return 'localhost' 118 135 119 136 def _get_host_ip(): … … 121 138 return settings.DJ_MIDDLEWARE_IP 122 139 123 import urlparse124 import socket125 140 remote_urls = socket.getaddrinfo(socket.gethostname(), None) 126 141 for remote_url in remote_urls:
Note: See TracChangeset
for help on using the changeset viewer.