1
2
3
4
5
6
7
8
9
10
11
12
13
14 import os
15 from random import random
16 from datetime import datetime
17 try:
18 set
19 except NameError:
20 from sets import Set as set
21
22 from OFS.Folder import Folder
23 from Products.PluggableAuthService import plugins
24 from Products.PluggableAuthService import interfaces
25 from Products.PluggableAuthService import PluggableAuthService
26
27 from Products import ZenModel
28
29 ZENOSS_ROLES = ['ZenUser', 'ZenManager']
30
31
33 timestamp = datetime.now().strftime('%Y.%d.%m-%H%M%S')
34 randomBit = int(random() * 10000)
35 backupFolderName = 'backup_acl_users_%s-%d' % (timestamp, randomBit)
36 backupFolder = Folder(backupFolderName)
37 backupFolder._setObject('acl_users', context.acl_users)
38 context._setObject(backupFolder.getId(), backupFolder)
39 context._delObject('acl_users')
40 return backupFolderName
41
42
44 """
45 Note: copied and adapted from AccessControl.User.BasicUser
46
47 If there are no users or only one user in this user folder,
48 populates from the 'inituser' file in the instance home.
49 We have to do this even when there is already a user
50 just in case the initial user ignored the setup messages.
51 We don't do it for more than one user to avoid
52 abuse of this mechanism.
53 Called only by OFS.Application.initialize().
54 """
55 from AccessControl.User import readUserAccessFile
56
57 plugins = self.plugins.listPlugins(
58 interfaces.plugins.IUserEnumerationPlugin)
59 userCounts = [ len(plugin.listUserInfo()) for id, plugin in plugins ]
60
61 if len(userCounts) <= 1:
62 info = readUserAccessFile('inituser')
63 if info:
64 import App.config
65 name, password, domains, remote_user_mode = info
66 userManagers = self.plugins.listPlugins(interfaces.plugins.IUserAdderPlugin)
67 roleManagers = self.plugins.listPlugins(interfaces.plugins.IRolesPlugin)
68 for pluginId, userPlugin in userManagers:
69
70 try:
71 userPlugin.removeUser(name)
72 except KeyError:
73
74 pass
75
76 userPlugin.doAddUser(name, password)
77
78 for pluginId, rolePlugin in roleManagers:
79 rolePlugin.assignRoleToPrincipal('Manager', name)
80 cfg = App.config.getConfiguration()
81
82 try:
83 os.remove(os.path.join(cfg.instancehome, 'inituser'))
84 except:
85 pass
86
87
97
98
100 acl = context.acl_users
101 id = 'basicAuthHelper'
102 if not hasattr(acl, id):
103 plugins.HTTPBasicAuthHelper.addHTTPBasicAuthHelper(acl, id)
104 interfaces = []
105 physPath = '/'.join(context.getPhysicalPath())
106 if physPath == '':
107 interfaces = ['IExtractionPlugin', 'IChallengePlugin',
108 'ICredentialsResetPlugin']
109 elif physPath == '/zport':
110 interfaces = ['IExtractionPlugin', 'IChallengePlugin']
111 acl.basicAuthHelper.manage_activateInterfaces(interfaces)
112
113
115 acl = context.acl_users
116 id = 'cookieAuthHelper'
117 if not hasattr(acl, id):
118 plugins.CookieAuthHelper.addCookieAuthHelper(acl, id)
119 interfaces = []
120
121
122 physPath = '/'.join(context.getPhysicalPath())
123 if physPath == '':
124 interfaces = ['IExtractionPlugin']
125 elif physPath == '/zport':
126 interfaces = ['IExtractionPlugin', 'ICredentialsUpdatePlugin',
127 'ICredentialsResetPlugin', 'IChallengePlugin']
128 acl.cookieAuthHelper.manage_activateInterfaces(interfaces)
129
130
132 acl = context.acl_users
133 id = 'roleManager'
134 if not hasattr(acl, id):
135 plugins.ZODBRoleManager.addZODBRoleManager(acl, id)
136 acl.roleManager.manage_activateInterfaces(['IRolesPlugin',
137 'IRoleEnumerationPlugin', 'IRoleAssignerPlugin'])
138
139 for role in ZENOSS_ROLES:
140 try:
141 acl.roleManager.addRole(role)
142 except KeyError:
143
144 pass
145
146
148 acl = context.acl_users
149 id = 'userManager'
150 if not hasattr(acl, id):
151 plugins.ZODBUserManager.addZODBUserManager(acl, id)
152 acl.userManager.manage_activateInterfaces(['IAuthenticationPlugin',
153 'IUserEnumerationPlugin', 'IUserAdderPlugin'])
154
155
157 acl = context.acl_users
158 id = 'requestTypeSniffer'
159 if not hasattr(acl, id):
160 plugins.RequestTypeSniffer.addRequestTypeSnifferPlugin(acl, id)
161 acl.requestTypeSniffer.manage_activateInterfaces(['IRequestTypeSniffer'])
162
163
165 acl = context.acl_users
166 id = 'protocolChooser'
167 if not hasattr(acl, id):
168 plugins.ChallengeProtocolChooser.addChallengeProtocolChooserPlugin(acl,
169 id)
170 acl.protocolChooser.manage_activateInterfaces([
171 'IChallengeProtocolChooser'])
172 protocolMapping = {}
173
174 physPath = '/'.join(context.getPhysicalPath())
175 if physPath == '':
176 protocolMapping = {
177 'Browser': ['http'],
178 'FTP': ['http'],
179 'WebDAV': ['http'],
180 'XML-RPC': ['http'],
181 }
182 elif physPath == '/zport':
183 protocolMapping = {
184 'FTP': ['http'],
185 'WebDAV': ['http'],
186 'XML-RPC': ['http'],
187 }
188
189 icookie = plugins.CookieAuthHelper.ICookieAuthHelper
190 ichallenge = interfaces.plugins.IChallengePlugin
191 challenge = [ p for id, p in acl.plugins.listPlugins(ichallenge) ]
192
193 cookiePlugins = [ p for p in challenge if icookie.providedBy(p) ]
194
195
196
197
198 cookie = cookiePlugins[0]
199 index = challenge.index(cookie)
200 for i in xrange(index):
201 acl.plugins.movePluginsUp(ichallenge, [cookie.id])
202 acl.protocolChooser.manage_updateProtocolMapping(protocolMapping)
203
204
214
215
245
246
283