Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager Class Reference
Inheritance diagram for PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager:
Inheritance graph
[legend]
Collaboration diagram for PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def authenticateCredentials
def enumerateUsers
def doAddUser
def listUserIds
def getUserInfo
def listUserInfo
def getUserIdForLogin
def getLoginForUserId
def addUser
def updateUser
def removeUser
def updateUserPassword
def manage_addUser
def manage_updateUserPassword
def manage_updateUser
def manage_removeUsers
def getOwnUserInfo
def manage_updatePassword

Public Attributes

 id
 title

Static Public Attributes

string meta_type = 'ZODB User Manager'
tuple security = ClassSecurityInfo()
tuple manage_options
tuple manage_widgets
tuple manage_users
tuple manage_updateUserPassword = postonly(manage_updateUserPassword)
tuple manage_removeUsers = postonly(manage_removeUsers)
tuple manage_updatePasswordForm
tuple manage_updatePassword = postonly(manage_updatePassword)

Private Member Functions

def _pw_encrypt

Private Attributes

 _id
 _user_passwords
 _login_to_userid
 _userid_to_login

Detailed Description

PAS plugin for managing users in the ZODB.

Definition at line 67 of file ZODBUserManager.py.


Constructor & Destructor Documentation

Definition at line 76 of file ZODBUserManager.py.

00076 
00077     def __init__(self, id, title=None):
00078 
00079         self._id = self.id = id
00080         self.title = title
00081 
00082         self._user_passwords = OOBTree()
00083         self._login_to_userid = OOBTree()
00084         self._userid_to_login = OOBTree()


Member Function Documentation

Returns the AuthEncoding encrypted password

If 'password' is already encrypted, it is returned
as is and not encrypted again.

Definition at line 331 of file ZODBUserManager.py.

00331 
00332     def _pw_encrypt( self, password ):
00333         """Returns the AuthEncoding encrypted password
00334 
00335         If 'password' is already encrypted, it is returned
00336         as is and not encrypted again.
00337         """
00338         if AuthEncoding.is_encrypted( password ):
00339             return password
00340         return AuthEncoding.pw_encrypt( password )

Here is the caller graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.addUser (   self,
  user_id,
  login_name,
  password 
)

Definition at line 277 of file ZODBUserManager.py.

00277 
00278     def addUser( self, user_id, login_name, password ):
00279 
00280         if self._user_passwords.get( user_id ) is not None:
00281             raise KeyError, 'Duplicate user ID: %s' % user_id
00282 
00283         if self._login_to_userid.get( login_name ) is not None:
00284             raise KeyError, 'Duplicate login name: %s' % login_name
00285 
00286         self._user_passwords[ user_id ] = self._pw_encrypt( password)
00287         self._login_to_userid[ login_name ] = user_id
00288         self._userid_to_login[ user_id ] = login_name
00289 
00290         # enumerateUsers return value has changed
00291         view_name = createViewName('enumerateUsers')
00292         self.ZCacheable_invalidate(view_name=view_name)

Here is the call graph for this function:

Here is the caller graph for this function:

See IAuthenticationPlugin.

o We expect the credentials to be those returned by
  ILoginPasswordExtractionPlugin.

Definition at line 89 of file ZODBUserManager.py.

00089 
00090     def authenticateCredentials( self, credentials ):
00091 
00092         """ See IAuthenticationPlugin.
00093 
00094         o We expect the credentials to be those returned by
00095           ILoginPasswordExtractionPlugin.
00096         """
00097         login = credentials.get( 'login' )
00098         password = credentials.get( 'password' )
00099 
00100         if login is None or password is None:
00101             return None
00102 
00103         userid = self._login_to_userid.get( login, login )
00104 
00105         reference = self._user_passwords.get(userid)
00106 
00107         if reference is None:
00108             return None
00109         
00110         if AuthEncoding.is_encrypted( reference ):
00111             if AuthEncoding.pw_validate( reference, password ):
00112                 return userid, login
00113 
00114         # Support previous naive behavior
00115         digested = sha.sha( password ).hexdigest()
00116 
00117         if reference == digested:
00118             return userid, login
00119 
00120         return None

Here is the call graph for this function:

Definition at line 219 of file ZODBUserManager.py.

00219 
00220     def doAddUser( self, login, password ):
00221         try:
00222             self.addUser( login, login, password )
00223         except KeyError:
00224             return False
00225         return True

Here is the call graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.enumerateUsers (   self,
  id = None,
  login = None,
  exact_match = False,
  sort_by = None,
  max_results = None,
  kw 
)
See IUserEnumerationPlugin.

Definition at line 132 of file ZODBUserManager.py.

00132 
00133                       ):
00134 
00135         """ See IUserEnumerationPlugin.
00136         """
00137         user_info = []
00138         user_ids = []
00139         plugin_id = self.getId()
00140         view_name = createViewName('enumerateUsers', id or login)
00141 
00142 
00143         if isinstance( id, basestring ):
00144             id = [ id ]
00145 
00146         if isinstance( login, basestring ):
00147             login = [ login ]
00148 
00149         # Look in the cache first...
00150         keywords = copy.deepcopy(kw)
00151         keywords.update( { 'id' : id
00152                          , 'login' : login
00153                          , 'exact_match' : exact_match
00154                          , 'sort_by' : sort_by
00155                          , 'max_results' : max_results
00156                          }
00157                        )
00158         cached_info = self.ZCacheable_get( view_name=view_name
00159                                          , keywords=keywords
00160                                          , default=None
00161                                          )
00162         if cached_info is not None:
00163             return tuple(cached_info)
00164 
00165         terms = id or login
00166 
00167         if exact_match:
00168             if terms:
00169 
00170                 if id:
00171                     # if we're doing an exact match based on id, it
00172                     # absolutely will have been qualified (if we have a
00173                     # prefix), so we can ignore any that don't begin with
00174                     # our prefix
00175                     id = [ x for x in id if x.startswith(self.prefix) ]
00176                     user_ids.extend( [ x[len(self.prefix):] for x in id ] )
00177                 elif login:
00178                     user_ids.extend( [ self._login_to_userid.get( x )
00179                                        for x in login ] )
00180 
00181                 # we're claiming an exact match search, if we still don't
00182                 # have anything, better bail.
00183                 if not user_ids:
00184                     return ()
00185             else:
00186                 # insane - exact match with neither login nor id
00187                 return ()
00188 
00189         if user_ids:
00190             user_filter = None
00191 
00192         else:   # Searching
00193             user_ids = self.listUserIds()
00194             user_filter = _ZODBUserFilter( id, login, **kw )
00195 
00196         for user_id in user_ids:
00197 
00198             if self._userid_to_login.get( user_id ):
00199                 e_url = '%s/manage_users' % self.getId()
00200                 qs = 'user_id=%s' % user_id
00201 
00202                 info = { 'id' : self.prefix + user_id
00203                        , 'login' : self._userid_to_login[ user_id ]
00204                        , 'pluginid' : plugin_id
00205                        , 'editurl' : '%s?%s' % (e_url, qs)
00206                        } 
00207 
00208                 if not user_filter or user_filter( info ):
00209                     user_info.append( info )
00210 
00211         # Put the computed value into the cache
00212         self.ZCacheable_set(user_info, view_name=view_name, keywords=keywords)
00213 
00214         return tuple( user_info )

Here is the caller graph for this function:

user_id -> login_name

o Raise KeyError if no user exists for that ID.

Definition at line 268 of file ZODBUserManager.py.

00268 
00269     def getLoginForUserId( self, user_id ):
00270 
00271         """ user_id -> login_name
00272 
00273         o Raise KeyError if no user exists for that ID.
00274         """
00275         return self._userid_to_login[ user_id ]

Here is the caller graph for this function:

Return current user's info.

Definition at line 466 of file ZODBUserManager.py.

00466 
00467     def getOwnUserInfo( self ):
00468 
00469         """ Return current user's info.
00470         """
00471         user_id = getSecurityManager().getUser().getId()
00472 
00473         return self.getUserInfo( user_id )

Here is the call graph for this function:

login_name -> user_id

o Raise KeyError if no user exists for the login name.

Definition at line 259 of file ZODBUserManager.py.

00259 
00260     def getUserIdForLogin( self, login_name ):
00261 
00262         """ login_name -> user_id
00263 
00264         o Raise KeyError if no user exists for the login name.
00265         """
00266         return self._login_to_userid[ login_name ]

user_id -> {}

Definition at line 237 of file ZODBUserManager.py.

00237 
00238     def getUserInfo( self, user_id ):
00239 
00240         """ user_id -> {}
00241         """
00242         return { 'user_id' : user_id
00243                , 'login_name' : self._userid_to_login[ user_id ]
00244                , 'pluginid' : self.getId()
00245                }

Here is the caller graph for this function:

-> ( user_id_1, ... user_id_n )

Definition at line 230 of file ZODBUserManager.py.

00230 
00231     def listUserIds( self ):
00232 
00233         """ -> ( user_id_1, ... user_id_n )
00234         """
00235         return self._user_passwords.keys()

Here is the caller graph for this function:

-> ( {}, ...{} )

o Return one mapping per user, with the following keys:

  - 'user_id' 
  - 'login_name'

Definition at line 247 of file ZODBUserManager.py.

00247 
00248     def listUserInfo( self ):
00249 
00250         """ -> ( {}, ...{} )
00251 
00252         o Return one mapping per user, with the following keys:
00253 
00254           - 'user_id' 
00255           - 'login_name'
00256         """
00257         return [ self.getUserInfo( x ) for x in self._user_passwords.keys() ]

Here is the call graph for this function:

Here is the caller graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.manage_addUser (   self,
  user_id,
  login_name,
  password,
  confirm,
  RESPONSE = None 
)
Add a user via the ZMI.

Definition at line 371 of file ZODBUserManager.py.

00371 
00372                       ):
00373         """ Add a user via the ZMI.
00374         """
00375         if password != confirm:
00376             message = 'password+and+confirm+do+not+match'
00377 
00378         else:
00379         
00380             if not login_name:
00381                 login_name = user_id
00382 
00383             # XXX:  validate 'user_id', 'login_name' against policies?
00384 
00385             self.addUser( user_id, login_name, password )
00386 
00387             message = 'User+added'
00388 
00389         if RESPONSE is not None:
00390             RESPONSE.redirect( '%s/manage_users?manage_tabs_message=%s'
00391                              % ( self.absolute_url(), message )
00392                              )

Here is the call graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.manage_removeUsers (   self,
  user_ids,
  RESPONSE = None,
  REQUEST = None 
)
Remove one or more users via the ZMI.

Definition at line 441 of file ZODBUserManager.py.

00441 
00442                           ):
00443         """ Remove one or more users via the ZMI.
00444         """
00445         user_ids = filter( None, user_ids )
00446 
00447         if not user_ids:
00448             message = 'no+users+selected'
00449 
00450         else:
00451         
00452             for user_id in user_ids:
00453                 self.removeUser( user_id )
00454 
00455             message = 'Users+removed'
00456 
00457         if RESPONSE is not None:
00458             RESPONSE.redirect( '%s/manage_users?manage_tabs_message=%s'
00459                              % ( self.absolute_url(), message )
                             )

Here is the call graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.manage_updatePassword (   self,
  login_name,
  password,
  confirm,
  RESPONSE = None,
  REQUEST = None 
)
Update the current user's password and login name.

Definition at line 487 of file ZODBUserManager.py.

00487 
00488                              ):
00489         """ Update the current user's password and login name.
00490         """
00491         user_id = getSecurityManager().getUser().getId()
00492         if password != confirm:
00493             message = 'password+and+confirm+do+not+match'
00494 
00495         else:
00496         
00497             if not login_name:
00498                 login_name = user_id
00499 
00500             # XXX:  validate 'user_id', 'login_name' against policies?
00501             self.updateUser( user_id, login_name )
00502             self.updateUserPassword( user_id, password )
00503 
00504             message = 'password+updated'
00505 
00506         if RESPONSE is not None:
00507             RESPONSE.redirect( '%s/manage_updatePasswordForm'
00508                                '?manage_tabs_message=%s'
00509                              % ( self.absolute_url(), message )
                             )

Here is the call graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.manage_updateUser (   self,
  user_id,
  login_name,
  RESPONSE = None 
)
Update a user's login name via the ZMI.

Definition at line 419 of file ZODBUserManager.py.

00419 
00420     def manage_updateUser(self, user_id, login_name, RESPONSE=None):
00421         """ Update a user's login name via the ZMI.
00422         """
00423         if not login_name:
00424             login_name = user_id
00425 
00426         # XXX:  validate 'user_id', 'login_name' against policies?
00427 
00428         self.updateUser(user_id, login_name)
00429 
00430         message = 'Login+name+updated'
00431 
00432         if RESPONSE is not None:
00433             RESPONSE.redirect( '%s/manage_users?manage_tabs_message=%s'
00434                              % ( self.absolute_url(), message )
00435                              )

Here is the call graph for this function:

def PluggableAuthService.plugins.ZODBUserManager.ZODBUserManager.manage_updateUserPassword (   self,
  user_id,
  password,
  confirm,
  RESPONSE = None,
  REQUEST = None 
)
Update a user's login name / password via the ZMI.

Definition at line 400 of file ZODBUserManager.py.

00400 
00401                                  ):
00402         """ Update a user's login name / password via the ZMI.
00403         """
00404         if password and password != confirm:
00405             message = 'password+and+confirm+do+not+match'
00406 
00407         else:
00408         
00409             self.updateUserPassword( user_id, password )
00410 
00411             message = 'password+updated'
00412 
00413         if RESPONSE is not None:
00414             RESPONSE.redirect( '%s/manage_users?manage_tabs_message=%s'
00415                              % ( self.absolute_url(), message )
                             )

Here is the call graph for this function:

Definition at line 304 of file ZODBUserManager.py.

00304 
00305     def removeUser( self, user_id ):
00306 
00307         if self._user_passwords.get( user_id ) is None:
00308             raise KeyError, 'Invalid user ID: %s' % user_id
00309 
00310         login_name = self._userid_to_login[ user_id ]
00311 
00312         del self._user_passwords[ user_id ]
00313         del self._login_to_userid[ login_name ]
00314         del self._userid_to_login[ user_id ]
00315 
00316         # Also, remove from the cache
00317         view_name = createViewName('enumerateUsers')
00318         self.ZCacheable_invalidate(view_name=view_name)
00319         view_name = createViewName('enumerateUsers', user_id)
00320         self.ZCacheable_invalidate(view_name=view_name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 294 of file ZODBUserManager.py.

00294 
00295     def updateUser(self, user_id, login_name):
00296 
00297         # The following raises a KeyError if the user_id is invalid
00298         old_login = self.getLoginForUserId(user_id)
00299 
00300         del self._login_to_userid[old_login]
00301         self._login_to_userid[login_name] = user_id
00302         self._userid_to_login[user_id] = login_name

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 322 of file ZODBUserManager.py.

00322 
00323     def updateUserPassword( self, user_id, password ):
00324 
00325         if self._user_passwords.get( user_id ) is None:
00326             raise KeyError, 'Invalid user ID: %s' % user_id
00327 
00328         if password:
00329             self._user_passwords[ user_id ] = self._pw_encrypt( password )

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 78 of file ZODBUserManager.py.

Definition at line 82 of file ZODBUserManager.py.

Definition at line 81 of file ZODBUserManager.py.

Definition at line 83 of file ZODBUserManager.py.

Definition at line 78 of file ZODBUserManager.py.

Initial value:
( ( { 'label': 'Users', 
                           'action': 'manage_users', }
                         ,
                       )
                     + BasePlugin.manage_options
                     + Cacheable.manage_options
                     )

Definition at line 344 of file ZODBUserManager.py.

Definition at line 460 of file ZODBUserManager.py.

Definition at line 510 of file ZODBUserManager.py.

Initial value:
PageTemplateFile( 'www/zuPasswd'
                                   , globals()
                                   , __name__='manage_updatePasswordForm'
                                   )

Definition at line 475 of file ZODBUserManager.py.

Definition at line 416 of file ZODBUserManager.py.

Initial value:
PageTemplateFile( 'www/zuUsers'
                                   , globals()
                                   , __name__='manage_users'
                                   )

Definition at line 359 of file ZODBUserManager.py.

Initial value:
PageTemplateFile( 'www/zuWidgets'
                                     , globals()
                                     , __name__='manage_widgets'
                                     )

Definition at line 353 of file ZODBUserManager.py.

Definition at line 72 of file ZODBUserManager.py.

Definition at line 74 of file ZODBUserManager.py.

Definition at line 79 of file ZODBUserManager.py.


The documentation for this class was generated from the following file: