Package Products :: Package ZenUtils :: Package patches :: Module pasmonkey
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenUtils.patches.pasmonkey

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 or (at your 
  8  # option) any later version as published by the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  ''' 
 15  This module contains monkey patches we needed to make to PAS when we switched 
 16  from native ZODB-managed authentication to pluggable authentication. 
 17   
 18  This module needs to be imported by ZenUtils/__init__.py. 
 19   
 20  Related tickets: 
 21    http://dev.zenoss.org/trac/ticket/379 
 22    http://dev.zenoss.org/trac/ticket/402 
 23    http://dev.zenoss.org/trac/ticket/443 
 24    http://dev.zenoss.org/trac/ticket/1042 
 25    http://dev.zenoss.org/trac/ticket/4225 
 26  ''' 
 27   
 28  # monkey patch PAS to allow inituser files, but check to see if we need to 
 29  # actually apply the patch, first -- support may have been added at some point 
 30  from Products.PluggableAuthService import PluggableAuthService 
 31  from Products.ZenUtils.Security import _createInitialUser 
 32  pas = PluggableAuthService.PluggableAuthService 
 33  if not hasattr(pas, '_createInitialUser'): 
 34      pas._createInitialUser =  _createInitialUser 
 35   
 36  # monkey patches for the PAS login form 
 37  from Products.PluggableAuthService.plugins import CookieAuthHelper 
 38  import urlparse 
 39  from cgi import parse_qs 
 40   
41 -def manage_afterAdd(self, item, container):
42 """We don't want CookieAuthHelper setting the login attribute, we we'll 43 override manage_afterAdd(). 44 45 For now, the only thing that manage_afterAdd does is set the login_form 46 attribute, but we will need to check this after every upgrade of the PAS. 47 """ 48 pass
49 50 CookieAuthHelper.CookieAuthHelper.manage_afterAdd = manage_afterAdd 51
52 -def login(self):
53 """ 54 Set a cookie and redirect to the url that we tried to 55 authenticate against originally. 56 57 FIXME - I don't think we need this any more now that the EULA is gone -EAD 58 """ 59 import urllib 60 61 request = self.REQUEST 62 response = request['RESPONSE'] 63 64 login = request.get('__ac_name', '') 65 password = request.get('__ac_password', '') 66 submitted = request.get('submitted', '') 67 68 pas_instance = self._getPAS() 69 70 if pas_instance is not None: 71 pas_instance.updateCredentials(request, response, login, password) 72 73 came_from = request.form.get('came_from') or '' 74 if came_from: 75 parts = urlparse.urlsplit(came_from) 76 querydict = parse_qs(parts[3]) 77 querydict.pop('terms', None) 78 if 'submitted' not in querydict.keys(): 79 querydict['submitted'] = submitted 80 newqs = urllib.urlencode(querydict, doseq=True) 81 parts = parts[:3] + (newqs,) + parts[4:] 82 came_from = urlparse.urlunsplit(parts) 83 else: 84 submittedQs = 'submitted=%s' % submitted 85 came_from = '/zport/dmd?%s' % submittedQs 86 if not self.dmd.acceptedTerms: 87 url = "%s/zenoss_terms/?came_from=%s" % ( 88 self.absolute_url(), urllib.quote(came_from)) 89 else: 90 url = came_from 91 92 if self.dmd.uuid is None: 93 from uuid import uuid1 94 self.dmd.uuid = str(uuid1()) 95 return response.redirect(url)
96 97 CookieAuthHelper.CookieAuthHelper.login = login 98 99
100 -def termsCheck(self):
101 """ Check to see if the user has accepted the Zenoss terms. 102 """ 103 request = self.REQUEST 104 response = request['RESPONSE'] 105 106 acceptStatus = request.form.get('terms') or '' 107 url = request.form.get('came_from') or self.absolute_url() 108 109 if acceptStatus != 'Accept': 110 self.resetCredentials(request, response) 111 if '?' in url: 112 url += '&' 113 else: 114 url += '?' 115 url += 'terms=Decline' 116 else: 117 self.dmd.acceptedTerms = True 118 from uuid import uuid1 119 self.dmd.uuid = str(uuid1()) 120 return response.redirect(url)
121 122 CookieAuthHelper.CookieAuthHelper.termsCheck = termsCheck 123