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 from sets import Set as set
18
19 from OFS.Folder import Folder
20 from Products.PluggableAuthService import plugins
21 from Products.PluggableAuthService import interfaces
22 from Products.PluggableAuthService import PluggableAuthService
23
24 ZENOSS_ROLES = ['ZenUser', 'ZenManager']
25
26
36
37
39 """
40 Note: copied and adapted from AccessControl.User.BasicUser
41
42 If there are no users or only one user in this user folder,
43 populates from the 'inituser' file in the instance home.
44 We have to do this even when there is already a user
45 just in case the initial user ignored the setup messages.
46 We don't do it for more than one user to avoid
47 abuse of this mechanism.
48 Called only by OFS.Application.initialize().
49 """
50 from AccessControl.User import readUserAccessFile
51
52 plugins = self.plugins.listPlugins(
53 interfaces.plugins.IUserEnumerationPlugin)
54
55 userCounts = [ len(plugin.listUserInfo()) for id, plugin in plugins if hasattr(plugin, "listUserInfo")]
56
57 if len(userCounts) <= 1:
58 info = readUserAccessFile('inituser')
59 if info:
60 import App.config
61 name, password, domains, remote_user_mode = info
62 userManagers = self.plugins.listPlugins(interfaces.plugins.IUserAdderPlugin)
63 roleManagers = self.plugins.listPlugins(interfaces.plugins.IRolesPlugin)
64 for pluginId, userPlugin in userManagers:
65
66 try:
67 userPlugin.removeUser(name)
68 except KeyError:
69
70 pass
71
72 userPlugin.doAddUser(name, password)
73
74 for pluginId, rolePlugin in roleManagers:
75 rolePlugin.assignRoleToPrincipal('Manager', name)
76 cfg = App.config.getConfiguration()
77
78 try:
79 os.remove(os.path.join(cfg.instancehome, 'inituser'))
80 except:
81 pass
82
83
93
94
96 acl = context.acl_users
97 id = 'basicAuthHelper'
98 if not hasattr(acl, id):
99 plugins.HTTPBasicAuthHelper.addHTTPBasicAuthHelper(acl, id)
100 interfaces = []
101 physPath = '/'.join(context.getPhysicalPath())
102 if physPath == '':
103 interfaces = ['IExtractionPlugin', 'IChallengePlugin',
104 'ICredentialsResetPlugin']
105 elif physPath == '/zport':
106 interfaces = ['IExtractionPlugin', 'IChallengePlugin']
107 acl.basicAuthHelper.manage_activateInterfaces(interfaces)
108
109
111 acl = context.acl_users
112 id = 'cookieAuthHelper'
113 if not hasattr(acl, id):
114 plugins.CookieAuthHelper.addCookieAuthHelper(acl, id)
115 interfaces = []
116
117
118 physPath = '/'.join(context.getPhysicalPath())
119 if physPath == '':
120 interfaces = ['IExtractionPlugin']
121 elif physPath == '/zport':
122 interfaces = ['IExtractionPlugin', 'ICredentialsUpdatePlugin',
123 'ICredentialsResetPlugin', 'IChallengePlugin']
124 acl.cookieAuthHelper.manage_activateInterfaces(interfaces)
125
126
128 acl = context.acl_users
129 id = 'roleManager'
130 if not hasattr(acl, id):
131 plugins.ZODBRoleManager.addZODBRoleManager(acl, id)
132 acl.roleManager.manage_activateInterfaces(['IRolesPlugin',
133 'IRoleEnumerationPlugin', 'IRoleAssignerPlugin'])
134
135 for role in ZENOSS_ROLES:
136 try:
137 acl.roleManager.addRole(role)
138 except KeyError:
139
140 pass
141
142
144 acl = context.acl_users
145 id = 'userManager'
146 if not hasattr(acl, id):
147 plugins.ZODBUserManager.addZODBUserManager(acl, id)
148 acl.userManager.manage_activateInterfaces(['IAuthenticationPlugin',
149 'IUserEnumerationPlugin', 'IUserAdderPlugin'])
150
151
153 acl = context.acl_users
154 id = 'requestTypeSniffer'
155 if not hasattr(acl, id):
156 plugins.RequestTypeSniffer.addRequestTypeSnifferPlugin(acl, id)
157 acl.requestTypeSniffer.manage_activateInterfaces(['IRequestTypeSniffer'])
158
159
161 acl = context.acl_users
162 id = 'protocolChooser'
163 if not hasattr(acl, id):
164 plugins.ChallengeProtocolChooser.addChallengeProtocolChooserPlugin(acl,
165 id)
166 acl.protocolChooser.manage_activateInterfaces([
167 'IChallengeProtocolChooser'])
168 protocolMapping = {}
169
170 physPath = '/'.join(context.getPhysicalPath())
171 if physPath == '':
172 protocolMapping = {
173 'Browser': ['http'],
174 'FTP': ['http'],
175 'WebDAV': ['http'],
176 'XML-RPC': ['http'],
177 }
178 elif physPath == '/zport':
179 protocolMapping = {
180 'FTP': ['http'],
181 'WebDAV': ['http'],
182 'XML-RPC': ['http'],
183 }
184
185 icookie = plugins.CookieAuthHelper.ICookieAuthHelper
186 ichallenge = interfaces.plugins.IChallengePlugin
187 challenge = [ p for id, p in acl.plugins.listPlugins(ichallenge) ]
188
189 cookiePlugins = [ p for p in challenge if icookie.providedBy(p) ]
190
191
192
193
194 cookie = cookiePlugins[0]
195 index = challenge.index(cookie)
196 for i in xrange(index):
197 acl.plugins.movePluginsUp(ichallenge, [cookie.id])
198 acl.protocolChooser.manage_updateProtocolMapping(protocolMapping)
199
200
210
211
241
242
279