Package couchdbkit :: Package ext :: Package pylons :: Package auth :: Module adapters
[hide private]
[frames] | no frames]

Source Code for Module couchdbkit.ext.pylons.auth.adapters

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of couchdbkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  from repoze.what.adapters import BaseSourceAdapter 
 7  from repoze.who.interfaces import IAuthenticator 
 8  from repoze.who.interfaces import IMetadataProvider 
 9  from zope.interface import implements 
10   
11 -class GroupAdapter(BaseSourceAdapter):
12 """Group adapter. Use 'auth/group_users' to retrieve group's users"""
13 - def __init__(self, user_class):
14 self.user_class = user_class
15
16 - def _get_all_sections(self):
17 raise NotImplementedError()
18
19 - def _get_section_items(self, section):
20 raise NotImplementedError()
21
22 - def _find_sections(self, hint):
23 """ 24 Returns the group ids that the user is part of. 25 """ 26 user = self.user_class.get(hint['repoze.what.userid']) 27 return user.groups
28
29 - def _include_items(self, section, items):
30 raise NotImplementedError()
31
32 - def _item_is_included(self, section, item):
33 raise NotImplementedError()
34
35 - def _section_exists(self, section):
36 raise NotImplementedError()
37
38 -class PermissionAdapter(BaseSourceAdapter):
39 - def __init__(self, db):
40 self.db = db
41
42 - def _get_all_sections(self):
43 raise NotImplementedError()
44
45 - def _get_section_items(self, section):
46 raise NotImplementedError()
47
48 - def _find_sections(self, hint):
49 results = self.db.view('group/show_permissions', startkey=hint).all() 50 return [x["value"] for x in results]
51
52 - def _include_items(self, section, items):
53 raise NotImplementedError()
54
55 - def _item_is_included(self, section, item):
56 raise NotImplementedError()
57
58 - def _section_exists(self, section):
59 raise NotImplementedError()
60
61 -class Authenticator(object):
62 implements(IAuthenticator) 63
64 - def __init__(self, user_class):
65 self.user_class = user_class
66
67 - def authenticate(self, environ, identity):
68 login = identity.get('login', '') 69 password = identity.get('password', '') 70 71 user = self.user_class.authenticate(login, password) 72 if not user: 73 return None 74 identity['login'] = str(user.login) 75 identity['user'] = user 76 return user._id
77
78 -class MDPlugin(object):
79 implements(IMetadataProvider) 80
81 - def __init__(self, user_class):
82 self.user_class = user_class
83
84 - def add_metadata(self, environ, identity):
85 if 'user' not in identity: 86 uid = identity['repoze.who.userid'] 87 if uid: 88 user = self.user_class.get(uid) 89 identity['user'] = user
90