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 as published by
      8  # 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          if querydict.has_key('terms'):
     78              del querydict['terms']
     79          if 'submitted' not in querydict.keys():
     80              querydict['submitted'] = submitted
     81          newqs = urllib.urlencode(querydict, doseq=True)
     82          parts = parts[:3] + (newqs,) + parts[4:]
     83          came_from = urlparse.urlunsplit(parts)
     84      else:
     85          submittedQs = 'submitted=%s' % submitted
     86          came_from = '/zport/dmd?%s' % submittedQs
     87      if not self.dmd.acceptedTerms:
     88          url = "%s/zenoss_terms/?came_from=%s" % (
     89                      self.absolute_url(), urllib.quote(came_from))
     90      else:
     91          url = came_from
     92
     93      if self.dmd.uuid is None:
     94          from uuid.uuid import uuid1
     95          self.dmd.uuid = str(uuid1())
     96      return response.redirect(url)
     97
     98  CookieAuthHelper.CookieAuthHelper.login = login
     99
    100
    101 -def termsCheck(self):
    102      """ Check to see if the user has accepted the Zenoss terms.
    103      """
    104      request = self.REQUEST
    105      response = request['RESPONSE']
    106
    107      acceptStatus = request.form.get('terms') or ''
    108      url = request.form.get('came_from') or self.absolute_url()
    109
    110      if acceptStatus != 'Accept':
    111          self.resetCredentials(request, response)
    112          if '?' in url:
    113              url += '&'
    114          else:
    115              url += '?'
    116          url += 'terms=Decline'
    117      else:
    118          self.dmd.acceptedTerms = True
    119          from uuid.uuid import uuid1
    120          self.dmd.uuid = str(uuid1())
    121      return response.redirect(url)
    122
    123  CookieAuthHelper.CookieAuthHelper.termsCheck = termsCheck
    124