Commit dd4f5983 authored by 's avatar

*** empty log message ***

parent 6432f4ef
"""Access control support""" """Access control support"""
__version__='$Revision: 1.11 $'[11:-2] __version__='$Revision: 1.12 $'[11:-2]
from Globals import HTMLFile, MessageDialog from Globals import HTMLFile, MessageDialog
...@@ -17,13 +17,13 @@ class RoleManager: ...@@ -17,13 +17,13 @@ class RoleManager:
('Add properties', []), ('Add properties', []),
('Change properties', []), ('Change properties', []),
('Delete properties', []), ('Delete properties', []),
('Default permission',['']), ('Shared permission',['']),
) )
__ac_types__=(('Full Access', map(lambda x: x[0], __ac_permissions__)), __ac_types__=(('Full Access', map(lambda x: x[0], __ac_permissions__)),
) )
__ac_roles__=('Manager', 'Anonymous') __ac_roles__=('Manager', 'Anonymous', 'Shared')
def access_info(self): def access_info(self):
# Return access summary info # Return access summary info
...@@ -32,8 +32,6 @@ class RoleManager: ...@@ -32,8 +32,6 @@ class RoleManager:
name=t.name name=t.name
for role in t.getRoles(): for role in t.getRoles():
data[role]=name data[role]=name
# try: del data['Manager']
# except: pass
keys=data.keys() keys=data.keys()
for i in range(len(keys)): for i in range(len(keys)):
key=keys[i] key=keys[i]
......
"""Access control package""" """Access control package"""
__version__='$Revision: 1.32 $'[11:-2] __version__='$Revision: 1.33 $'[11:-2]
from PersistentMapping import PersistentMapping from PersistentMapping import PersistentMapping
...@@ -25,13 +25,35 @@ class User(Implicit, Persistent): ...@@ -25,13 +25,35 @@ class User(Implicit, Persistent):
def authenticate(self, password): def authenticate(self, password):
return password==self.__ return password==self.__
def hasRole(self,inst,roles=None): def hasRole(self,parent,roles=None):
if roles is None: obj=parent
return 1 obj_roles=roles
for role in roles: usr_roles=self.roles
if role in self.roles:
while 1:
if (obj_roles is None) or ('Anonymous' in obj_roles):
return 1 return 1
return 0 for role in obj_roles:
if role in usr_roles:
return 1
if 'Shared' in obj_roles:
if not hasattr(obj, 'aq_parent'):
return 0
obj=obj.aq_parent
if hasattr(obj, '__roles__'):
obj_roles=obj.__roles__
else:
obj_roles=['Shared',]
continue
return 0
# if (roles is None) or ('Anonymous' in roles):
# return 1
# for role in roles:
# if role in self.roles:
# return 1
# return 0
def __len__(self): return 1 def __len__(self): return 1
def __str__(self): return self.name def __str__(self): return self.name
...@@ -87,25 +109,35 @@ class UserFolder(Implicit, Persistent, Navigation, Tabs, Item, ...@@ -87,25 +109,35 @@ class UserFolder(Implicit, Persistent, Navigation, Tabs, Item,
return keys return keys
def validate(self,request,auth='',roles=None): def validate(self,request,auth='',roles=None):
parent=request['PARENTS'][0]
# If no authorization, only nobody can match
if not auth: if not auth:
if roles is None: if nobody.hasRole(parent, roles):
return nobody return nobody
return None return None
# Only do basic authentication
if lower(auth[:6])!='basic ': if lower(auth[:6])!='basic ':
return None return None
name,password=tuple(split(decodestring(split(auth)[-1]), ':')) name,password=tuple(split(decodestring(split(auth)[-1]), ':'))
# Check for superuser
if self._isTop() and (name==super.name) and \ if self._isTop() and (name==super.name) and \
super.authenticate(password): super.authenticate(password):
return super return super
# Try to get user
try: user=self.data[name] try: user=self.data[name]
except: return None except: return None
# Try to authenticate user
if not user.authenticate(password): if not user.authenticate(password):
return None return None
if roles is None:
# Try to authorize user
if user.hasRole(parent, roles):
return user return user
for role in roles:
if role in user.roles:
return user
return None return None
_mainUser=HTMLFile('mainUser', globals()) _mainUser=HTMLFile('mainUser', globals())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment