2009-12-02 05:36:57 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2009-10-13 06:35:20 +00:00
|
|
|
|
2008-09-26 14:23:55 +00:00
|
|
|
class authorizer:
|
2008-10-29 21:45:02 +00:00
|
|
|
read_perms = "elr"
|
|
|
|
write_perms = "adfmw"
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.password = ''
|
|
|
|
|
|
|
|
def validate_authentication(self, username, password):
|
|
|
|
"""Return True if the supplied username and password match the
|
|
|
|
stored credentials."""
|
|
|
|
self.password = password
|
|
|
|
return True
|
|
|
|
|
|
|
|
def impersonate_user(self, username, password):
|
|
|
|
"""Impersonate another user (noop).
|
|
|
|
|
|
|
|
It is always called before accessing the filesystem.
|
|
|
|
By default it does nothing. The subclass overriding this
|
|
|
|
method is expected to provide a mechanism to change the
|
|
|
|
current user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def terminate_impersonation(self):
|
|
|
|
"""Terminate impersonation (noop).
|
|
|
|
|
|
|
|
It is always called after having accessed the filesystem.
|
|
|
|
By default it does nothing. The subclass overriding this
|
|
|
|
method is expected to provide a mechanism to switch back
|
|
|
|
to the original user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def has_user(self, username):
|
|
|
|
"""Whether the username exists in the virtual users table."""
|
|
|
|
if username=='anonymous':
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def has_perm(self, username, perm, path=None):
|
|
|
|
"""Whether the user has permission over path (an absolute
|
|
|
|
pathname of a file or a directory).
|
|
|
|
|
|
|
|
Expected perm argument is one of the following letters:
|
|
|
|
"elradfmw".
|
|
|
|
"""
|
|
|
|
paths = path.split('/')
|
|
|
|
if not len(paths)>2:
|
|
|
|
return True
|
2009-12-02 05:36:57 +00:00
|
|
|
db_name = paths[1]
|
2008-10-29 21:45:02 +00:00
|
|
|
res = security.login(db_name, username, self.password)
|
|
|
|
return bool(res)
|
|
|
|
|
|
|
|
def get_perms(self, username):
|
|
|
|
"""Return current user permissions."""
|
|
|
|
return 'elr'
|
|
|
|
|
|
|
|
def get_home_dir(self, username):
|
|
|
|
"""Return the user's home directory."""
|
|
|
|
return '/'
|
|
|
|
|
|
|
|
def get_msg_login(self, username):
|
|
|
|
"""Return the user's login message."""
|
|
|
|
return 'Welcome on OpenERP document management system.'
|
|
|
|
|
|
|
|
def get_msg_quit(self, username):
|
|
|
|
"""Return the user's quitting message."""
|
|
|
|
return 'Bye.'
|
2008-09-26 14:23:55 +00:00
|
|
|
|
2009-03-03 09:51:57 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|