Filename | /var/www/foswiki11/lib/Foswiki/Users/BaseUserMapping.pm |
Statements | Executed 13849 statements in 20.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
378 | 1 | 1 | 9.02ms | 9.79ms | findUserByWikiName | Foswiki::Users::BaseUserMapping::
1987 | 2 | 2 | 5.12ms | 5.12ms | handlesUser | Foswiki::Users::BaseUserMapping::
753 | 3 | 3 | 1.40ms | 1.40ms | isGroup | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 1.07ms | 8.86ms | BEGIN@33 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 730µs | 782µs | BEGIN@39 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 65µs | 74µs | new | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 47µs | 52µs | finish | Foswiki::Users::BaseUserMapping::
4 | 1 | 1 | 44µs | 82µs | eachGroupMember | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 16µs | 122µs | isAdmin | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 14µs | 28µs | BEGIN@30 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 11µs | 26µs | BEGIN@36 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 10µs | 40µs | BEGIN@38 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 10µs | 15µs | BEGIN@31 | Foswiki::Users::BaseUserMapping::
1 | 1 | 1 | 4µs | 4µs | BEGIN@37 | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | __ANON__[:342] | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | checkPassword | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | eachGroup | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | eachMembership | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | eachUser | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | getEmails | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | getLoginName | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | getWikiName | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | groupAllowsChange | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | login2cUID | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | loginTemplateName | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | passwordError | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | setPassword | Foswiki::Users::BaseUserMapping::
0 | 0 | 0 | 0s | 0s | userExists | Foswiki::Users::BaseUserMapping::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::Users::BaseUserMapping | ||||
6 | |||||
7 | User mapping is the process by which Foswiki maps from a username | ||||
8 | (a login name) | ||||
9 | to a display name and back. It is also where groups are maintained. | ||||
10 | |||||
11 | The BaseMapper provides support for a small number of predefined users. | ||||
12 | No registration - this is a read only usermapper. It uses the mapper | ||||
13 | prefix 'BaseUserMapping_'. | ||||
14 | |||||
15 | ---++ Users | ||||
16 | * $Foswiki::cfg{AdminUserLogin} - uses the password that | ||||
17 | was set in Configure (IF its not null) | ||||
18 | * $Foswiki::cfg{DefaultUserLogin} - WikiGuest | ||||
19 | * UnknownUser | ||||
20 | * ProjectContributor | ||||
21 | * $Foswiki::cfg{Register}{RegistrationAgentWikiName} | ||||
22 | |||||
23 | ---+++ Groups | ||||
24 | * $Foswiki::cfg{SuperAdminGroup} | ||||
25 | * BaseGroup | ||||
26 | |||||
27 | =cut | ||||
28 | |||||
29 | package Foswiki::Users::BaseUserMapping; | ||||
30 | 2 | 29µs | 2 | 41µs | # spent 28µs (14+14) within Foswiki::Users::BaseUserMapping::BEGIN@30 which was called:
# once (14µs+14µs) by Foswiki::Users::new at line 30 # spent 28µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@30
# spent 14µs making 1 call to strict::import |
31 | 2 | 25µs | 2 | 21µs | # spent 15µs (10+6) within Foswiki::Users::BaseUserMapping::BEGIN@31 which was called:
# once (10µs+6µs) by Foswiki::Users::new at line 31 # spent 15µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@31
# spent 6µs making 1 call to warnings::import |
32 | |||||
33 | 2 | 123µs | 1 | 8.86ms | # spent 8.86ms (1.07+7.79) within Foswiki::Users::BaseUserMapping::BEGIN@33 which was called:
# once (1.07ms+7.79ms) by Foswiki::Users::new at line 33 # spent 8.86ms making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@33 |
34 | 1 | 8µs | our @ISA = ('Foswiki::UserMapping'); | ||
35 | |||||
36 | 2 | 26µs | 2 | 42µs | # spent 26µs (11+16) within Foswiki::Users::BaseUserMapping::BEGIN@36 which was called:
# once (11µs+16µs) by Foswiki::Users::new at line 36 # spent 26µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@36
# spent 16µs making 1 call to Assert::import |
37 | 2 | 24µs | 1 | 4µs | # spent 4µs within Foswiki::Users::BaseUserMapping::BEGIN@37 which was called:
# once (4µs+0s) by Foswiki::Users::new at line 37 # spent 4µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@37 |
38 | 2 | 28µs | 2 | 70µs | # spent 40µs (10+30) within Foswiki::Users::BaseUserMapping::BEGIN@38 which was called:
# once (10µs+30µs) by Foswiki::Users::new at line 38 # spent 40µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@38
# spent 30µs making 1 call to Exporter::import |
39 | 2 | 1.35ms | 2 | 808µs | # spent 782µs (730+52) within Foswiki::Users::BaseUserMapping::BEGIN@39 which was called:
# once (730µs+52µs) by Foswiki::Users::new at line 39 # spent 782µs making 1 call to Foswiki::Users::BaseUserMapping::BEGIN@39
# spent 25µs making 1 call to Exporter::import |
40 | |||||
41 | 1 | 500ns | our $DEFAULT_USER_CUID = 'BaseUserMapping_666'; | ||
42 | 1 | 200ns | our $UNKNOWN_USER_CUID = 'BaseUserMapping_999'; | ||
43 | 1 | 200ns | our %BASE_USERS; | ||
44 | 1 | 100ns | our %BASE_GROUPS; | ||
45 | |||||
46 | =begin TML | ||||
47 | |||||
48 | ---++ ClassMethod new ($session) | ||||
49 | |||||
50 | Construct the BaseUserMapping object | ||||
51 | |||||
52 | =cut | ||||
53 | |||||
54 | # Constructs a new user mapping handler of this type, referring to $session | ||||
55 | # for any required Foswiki services. | ||||
56 | # spent 74µs (65+9) within Foswiki::Users::BaseUserMapping::new which was called:
# once (65µs+9µs) by Foswiki::Users::new at line 92 of /var/www/foswiki11/lib/Foswiki/Users.pm | ||||
57 | 1 | 800ns | my ( $class, $session ) = @_; | ||
58 | |||||
59 | # $DEFAULT_USER_CUID , $UNKNOWN_USER_CUID, %BASE_USERS and %BASE_GROUPS | ||||
60 | # could be initialised statically, but tests have been written that rely | ||||
61 | # on being able to override the $Foswiki::cfg settings that are part of | ||||
62 | # them. Since it's a low cost op to re-initialise them each time this | ||||
63 | # singleton is built, we will contiue to do so (at least until those | ||||
64 | # tests have been revisited) | ||||
65 | 1 | 200ns | $DEFAULT_USER_CUID = 'BaseUserMapping_666'; | ||
66 | 1 | 100ns | $UNKNOWN_USER_CUID = 'BaseUserMapping_999'; | ||
67 | 1 | 12µs | %BASE_USERS = ( | ||
68 | BaseUserMapping_111 => { | ||||
69 | login => 'ProjectContributor', | ||||
70 | wikiname => 'ProjectContributor', | ||||
71 | }, | ||||
72 | BaseUserMapping_222 => { | ||||
73 | login => $Foswiki::cfg{Register}{RegistrationAgentWikiName} | ||||
74 | || 'RegistrationAgent', | ||||
75 | wikiname => $Foswiki::cfg{Register}{RegistrationAgentWikiName} | ||||
76 | || 'RegistrationAgent', | ||||
77 | }, | ||||
78 | BaseUserMapping_333 => { | ||||
79 | login => $Foswiki::cfg{AdminUserLogin} || 'admin', | ||||
80 | wikiname => $Foswiki::cfg{AdminUserWikiName} || 'AdminUser', | ||||
81 | email => $Foswiki::cfg{WebMasterEmail} || 'email not set', | ||||
82 | password => $Foswiki::cfg{Password}, | ||||
83 | }, | ||||
84 | $DEFAULT_USER_CUID => { | ||||
85 | login => $Foswiki::cfg{DefaultUserLogin} || 'guest', | ||||
86 | wikiname => $Foswiki::cfg{DefaultUserWikiName} || 'WikiGuest', | ||||
87 | }, | ||||
88 | $UNKNOWN_USER_CUID => { | ||||
89 | login => 'unknown', | ||||
90 | wikiname => 'UnknownUser', | ||||
91 | } | ||||
92 | ); | ||||
93 | 1 | 3µs | %BASE_GROUPS = ( | ||
94 | $Foswiki::cfg{SuperAdminGroup} => [ | ||||
95 | 'BaseUserMapping_333', | ||||
96 | |||||
97 | # Registration agent was here so registration can still take | ||||
98 | # place on an otherwise locked down USERSWEB. | ||||
99 | # Jan2010: Sven removed it, otherwise anyone registering can add themselves as admin. | ||||
100 | #'BaseUserMapping_222' | ||||
101 | ], | ||||
102 | BaseGroup => [ | ||||
103 | 'BaseUserMapping_333', $DEFAULT_USER_CUID, | ||||
104 | $UNKNOWN_USER_CUID, 'BaseUserMapping_111', | ||||
105 | 'BaseUserMapping_222', | ||||
106 | ], | ||||
107 | |||||
108 | # RegistrationGroup => ['BaseUserMapping_222'] | ||||
109 | ); | ||||
110 | |||||
111 | 1 | 15µs | 1 | 9µs | my $this = $class->SUPER::new( $session, 'BaseUserMapping_' ); # spent 9µs making 1 call to Foswiki::UserMapping::new |
112 | 1 | 600ns | $Foswiki::cfg{Register}{RegistrationAgentWikiName} ||= 'RegistrationAgent'; | ||
113 | |||||
114 | # set up our users | ||||
115 | 1 | 500ns | $this->{L2U} = {}; # login 2 cUID | ||
116 | 1 | 300ns | $this->{U2L} = {}; # cUID 2 login | ||
117 | 1 | 300ns | $this->{W2U} = {}; # wikiname 2 cUID | ||
118 | 1 | 300ns | $this->{U2W} = {}; # cUID 2 wikiname | ||
119 | 1 | 300ns | $this->{U2E} = {}; # cUID 2 email | ||
120 | 1 | 600ns | $this->{L2P} = {}; # login 2 password | ||
121 | |||||
122 | 1 | 7µs | while ( my ( $k, $v ) = each %BASE_USERS ) { | ||
123 | 5 | 3µs | $this->{U2L}->{$k} = $v->{login}; | ||
124 | 5 | 3µs | $this->{U2W}->{$k} = $v->{wikiname}; | ||
125 | 5 | 2µs | $this->{U2E}->{$k} = $v->{email} if defined $v->{email}; | ||
126 | |||||
127 | 5 | 4µs | $this->{L2U}->{ $v->{login} } = $k; | ||
128 | 5 | 2µs | $this->{L2P}->{ $v->{login} } = $v->{password} | ||
129 | if defined $v->{password}; | ||||
130 | |||||
131 | 5 | 3µs | $this->{W2U}->{ $v->{wikiname} } = $k; | ||
132 | } | ||||
133 | |||||
134 | 1 | 2µs | %{ $this->{GROUPS} } = %BASE_GROUPS; | ||
135 | |||||
136 | 1 | 4µs | return $this; | ||
137 | } | ||||
138 | |||||
139 | =begin TML | ||||
140 | |||||
141 | ---++ ObjectMethod finish() | ||||
142 | Break circular references. | ||||
143 | |||||
144 | =cut | ||||
145 | |||||
146 | # Note to developers; please undef *all* fields in the object explicitly, | ||||
147 | # whether they are references or not. That way this method is "golden | ||||
148 | # documentation" of the live fields in the object. | ||||
149 | # spent 52µs (47+5) within Foswiki::Users::BaseUserMapping::finish which was called:
# once (47µs+5µs) by Foswiki::Users::finish at line 163 of /var/www/foswiki11/lib/Foswiki/Users.pm | ||||
150 | 1 | 400ns | my $this = shift; | ||
151 | 1 | 8µs | undef $this->{U2L}; | ||
152 | 1 | 2µs | undef $this->{U2W}; | ||
153 | 1 | 800ns | undef $this->{L2P}; | ||
154 | 1 | 1µs | undef $this->{U2E}; | ||
155 | 1 | 4µs | undef $this->{L2U}; | ||
156 | 1 | 5µs | undef $this->{W2U}; | ||
157 | 1 | 2µs | undef $this->{GROUPS}; | ||
158 | 1 | 22µs | 1 | 5µs | $this->SUPER::finish(); # spent 5µs making 1 call to Foswiki::UserMapping::finish |
159 | } | ||||
160 | |||||
161 | =begin TML | ||||
162 | |||||
163 | ---++ ObjectMethod loginTemplateName () -> templateFile | ||||
164 | |||||
165 | allows UserMappings to come with customised login screens - that should preffereably only over-ride the UI function | ||||
166 | |||||
167 | =cut | ||||
168 | |||||
169 | sub loginTemplateName { | ||||
170 | return 'login.sudo'; | ||||
171 | } | ||||
172 | |||||
173 | =begin TML | ||||
174 | |||||
175 | ---++ ObjectMethod handlesUser ( $cUID, $login, $wikiname) -> $boolean | ||||
176 | |||||
177 | See baseclass for documentation. | ||||
178 | |||||
179 | In the BaseUserMapping case, we know all | ||||
180 | the details of the users we specialise in. | ||||
181 | |||||
182 | =cut | ||||
183 | |||||
184 | # spent 5.12ms within Foswiki::Users::BaseUserMapping::handlesUser which was called 1987 times, avg 3µs/call:
# 1069 times (2.32ms+0s) by Foswiki::Users::TopicUserMapping::_cacheUser at line 1595 of /var/www/foswiki11/lib/Foswiki/Users/TopicUserMapping.pm, avg 2µs/call
# 918 times (2.80ms+0s) by Foswiki::Users::_getMapping at line 211 of /var/www/foswiki11/lib/Foswiki/Users.pm, avg 3µs/call | ||||
185 | 1987 | 1.09ms | my ( $this, $cUID, $login, $wikiname ) = @_; | ||
186 | |||||
187 | 1987 | 316µs | return 1 if ( defined($cUID) && defined( $this->{U2L}{$cUID} ) ); | ||
188 | 1987 | 915µs | return 1 if ( defined($login) && defined( $this->{L2U}{$login} ) ); | ||
189 | 1983 | 1.56ms | return 1 if ( defined($wikiname) && defined( $this->{W2U}{$wikiname} ) ); | ||
190 | |||||
191 | 1659 | 3.80ms | return 0; | ||
192 | } | ||||
193 | |||||
194 | =begin TML | ||||
195 | |||||
196 | ---++ ObjectMethod login2cUID ($login) -> $cUID | ||||
197 | |||||
198 | Convert a login name to the corresponding canonical user name. The | ||||
199 | canonical name can be any string of 7-bit alphanumeric and underscore | ||||
200 | characters, and must correspond 1:1 to the login name. | ||||
201 | (undef on failure) | ||||
202 | |||||
203 | =cut | ||||
204 | |||||
205 | sub login2cUID { | ||||
206 | my ( $this, $login ) = @_; | ||||
207 | |||||
208 | return $this->{L2U}{$login}; | ||||
209 | |||||
210 | #alternative impl - slower, but more re-useable | ||||
211 | #my @list = findUserByWikiName($this, $login); | ||||
212 | #return shift @list; | ||||
213 | } | ||||
214 | |||||
215 | =begin TML | ||||
216 | |||||
217 | ---++ ObjectMethod getLoginName ($cUID) -> login | ||||
218 | |||||
219 | converts an internal cUID to that user's login | ||||
220 | (undef on failure) | ||||
221 | |||||
222 | =cut | ||||
223 | |||||
224 | sub getLoginName { | ||||
225 | my ( $this, $user ) = @_; | ||||
226 | return $this->{U2L}{$user}; | ||||
227 | } | ||||
228 | |||||
229 | =begin TML | ||||
230 | |||||
231 | ---++ ObjectMethod getWikiName ($cUID) -> wikiname | ||||
232 | |||||
233 | Map a canonical user name to a wikiname | ||||
234 | |||||
235 | =cut | ||||
236 | |||||
237 | sub getWikiName { | ||||
238 | my ( $this, $cUID ) = @_; | ||||
239 | return $this->{U2W}->{$cUID} || getLoginName( $this, $cUID ); | ||||
240 | } | ||||
241 | |||||
242 | =begin TML | ||||
243 | |||||
244 | ---++ ObjectMethod userExists( $user ) -> $boolean | ||||
245 | |||||
246 | Determine if the user already exists or not. | ||||
247 | |||||
248 | =cut | ||||
249 | |||||
250 | sub userExists { | ||||
251 | my ( $this, $cUID ) = @_; | ||||
252 | ASSERT($cUID) if DEBUG; | ||||
253 | return 0 unless defined $cUID; | ||||
254 | return $this->{U2L}{$cUID}; | ||||
255 | } | ||||
256 | |||||
257 | =begin TML | ||||
258 | |||||
259 | ---++ ObjectMethod eachUser () -> listIterator of cUIDs | ||||
260 | |||||
261 | See baseclass for documentation. | ||||
262 | |||||
263 | =cut | ||||
264 | |||||
265 | sub eachUser { | ||||
266 | my ($this) = @_; | ||||
267 | |||||
268 | my @list = keys( %{ $this->{U2W} } ); | ||||
269 | require Foswiki::ListIterator; | ||||
270 | return new Foswiki::ListIterator( \@list ); | ||||
271 | } | ||||
272 | |||||
273 | =begin TML | ||||
274 | |||||
275 | ---++ ObjectMethod eachGroupMember ($group) -> listIterator of cUIDs | ||||
276 | |||||
277 | See baseclass for documentation. | ||||
278 | |||||
279 | The basemapper implementation assumes that there are no nested groups in the | ||||
280 | basemapper. | ||||
281 | |||||
282 | =cut | ||||
283 | |||||
284 | # spent 82µs (44+38) within Foswiki::Users::BaseUserMapping::eachGroupMember which was called 4 times, avg 21µs/call:
# 4 times (44µs+38µs) by Foswiki::UserMapping::isInGroup at line 419 of /var/www/foswiki11/lib/Foswiki/UserMapping.pm, avg 21µs/call | ||||
285 | 4 | 3µs | my $this = shift; | ||
286 | 4 | 3µs | my $group = shift; | ||
287 | |||||
288 | 4 | 4µs | my $members = $this->{GROUPS}{$group}; | ||
289 | |||||
290 | #print STDERR "eachGroupMember($group): ".join(',', @{$members}); | ||||
291 | |||||
292 | 4 | 3µs | require Foswiki::ListIterator; | ||
293 | 4 | 25µs | 4 | 38µs | return new Foswiki::ListIterator($members); # spent 38µs making 4 calls to Foswiki::ListIterator::new, avg 10µs/call |
294 | } | ||||
295 | |||||
296 | =begin TML | ||||
297 | |||||
298 | ---++ ObjectMethod isGroup ($name) -> boolean | ||||
299 | |||||
300 | See baseclass for documentation. | ||||
301 | |||||
302 | =cut | ||||
303 | |||||
304 | # spent 1.40ms within Foswiki::Users::BaseUserMapping::isGroup which was called 753 times, avg 2µs/call:
# 378 times (769µs+0s) by Foswiki::Users::BaseUserMapping::findUserByWikiName at line 406, avg 2µs/call
# 374 times (629µs+0s) by Foswiki::Users::isGroup at line 839 of /var/www/foswiki11/lib/Foswiki/Users.pm, avg 2µs/call
# once (7µs+0s) by Foswiki::UserMapping::isInGroup at line 426 of /var/www/foswiki11/lib/Foswiki/UserMapping.pm | ||||
305 | 753 | 319µs | my ( $this, $name ) = @_; | ||
306 | 753 | 130µs | $name ||= ""; | ||
307 | |||||
308 | #TODO: what happens to the code if we implement this using an iterator too? | ||||
309 | 753 | 8.23ms | return ( $this->{GROUPS}->{$name} ); | ||
310 | } | ||||
311 | |||||
312 | =begin TML | ||||
313 | |||||
314 | ---++ ObjectMethod eachGroup () -> ListIterator of groupnames | ||||
315 | |||||
316 | See baseclass for documentation. | ||||
317 | |||||
318 | =cut | ||||
319 | |||||
320 | sub eachGroup { | ||||
321 | my ($this) = @_; | ||||
322 | my @groups = keys( %{ $this->{GROUPS} } ); | ||||
323 | |||||
324 | require Foswiki::ListIterator; | ||||
325 | return new Foswiki::ListIterator( \@groups ); | ||||
326 | } | ||||
327 | |||||
328 | =begin TML | ||||
329 | |||||
330 | ---++ ObjectMethod eachMembership ($cUID) -> ListIterator of groups this user is in | ||||
331 | |||||
332 | See baseclass for documentation. | ||||
333 | |||||
334 | =cut | ||||
335 | |||||
336 | sub eachMembership { | ||||
337 | my ( $this, $cUID ) = @_; | ||||
338 | |||||
339 | my $it = $this->eachGroup(); | ||||
340 | $it->{filter} = sub { | ||||
341 | $this->isInGroup( $cUID, $_[0] ); | ||||
342 | }; | ||||
343 | return $it; | ||||
344 | } | ||||
345 | |||||
346 | =begin TML | ||||
347 | |||||
348 | ---++ ObjectMethod groupAllowsChange($group) -> boolean | ||||
349 | |||||
350 | returns 0 if the group is 'owned by the BaseMapper and it wants to veto adding to that group | ||||
351 | |||||
352 | =cut | ||||
353 | |||||
354 | sub groupAllowsChange { | ||||
355 | my $this = shift; | ||||
356 | my $group = shift; | ||||
357 | ASSERT( defined $group ) if DEBUG; | ||||
358 | |||||
359 | return 0 | ||||
360 | if ( ( $group eq 'BaseGroup' ) | ||||
361 | or ( $group eq 'RegistrationGroup' ) ); | ||||
362 | return 1; | ||||
363 | } | ||||
364 | |||||
365 | =begin TML | ||||
366 | |||||
367 | ---++ ObjectMethod isAdmin( $cUID ) -> $boolean | ||||
368 | |||||
369 | True if the user is an admin | ||||
370 | * is a member of the $Foswiki::cfg{SuperAdminGroup} | ||||
371 | |||||
372 | =cut | ||||
373 | |||||
374 | # spent 122µs (16+106) within Foswiki::Users::BaseUserMapping::isAdmin which was called:
# once (16µs+106µs) by Foswiki::Users::isAdmin at line 626 of /var/www/foswiki11/lib/Foswiki/Users.pm | ||||
375 | 1 | 1µs | my ( $this, $cUID ) = @_; | ||
376 | 1 | 16µs | 1 | 106µs | return $this->isInGroup( $cUID, $Foswiki::cfg{SuperAdminGroup} ); # spent 106µs making 1 call to Foswiki::UserMapping::isInGroup |
377 | } | ||||
378 | |||||
379 | =begin TML | ||||
380 | |||||
381 | ---++ ObjectMethod getEmails($name) -> @emailAddress | ||||
382 | |||||
383 | If $name is a cUID, return their email addresses. If it is a group, | ||||
384 | return the addresses of everyone in the group. | ||||
385 | |||||
386 | =cut | ||||
387 | |||||
388 | sub getEmails { | ||||
389 | my ( $this, $user ) = @_; | ||||
390 | |||||
391 | return $this->{U2E}{$user} || (); | ||||
392 | } | ||||
393 | |||||
394 | =begin TML | ||||
395 | |||||
396 | ---++ ObjectMethod findUserByWikiName ($wikiname) -> list of cUIDs associated with that wikiname | ||||
397 | |||||
398 | See baseclass for documentation. | ||||
399 | |||||
400 | =cut | ||||
401 | |||||
402 | # spent 9.79ms (9.02+769µs) within Foswiki::Users::BaseUserMapping::findUserByWikiName which was called 378 times, avg 26µs/call:
# 378 times (9.02ms+769µs) by Foswiki::Users::findUserByWikiName at line 535 of /var/www/foswiki11/lib/Foswiki/Users.pm, avg 26µs/call | ||||
403 | 378 | 206µs | my ( $this, $wn ) = @_; | ||
404 | 378 | 179µs | my @users = (); | ||
405 | |||||
406 | 378 | 628µs | 378 | 769µs | if ( $this->isGroup($wn) ) { # spent 769µs making 378 calls to Foswiki::Users::BaseUserMapping::isGroup, avg 2µs/call |
407 | push( @users, $wn ); | ||||
408 | } | ||||
409 | else { | ||||
410 | |||||
411 | # Add additional mappings defined in WikiUsers | ||||
412 | 378 | 625µs | if ( $this->{W2U}->{$wn} ) { | ||
413 | push( @users, $this->{W2U}->{$wn} ); | ||||
414 | } | ||||
415 | elsif ( $this->{L2U}->{$wn} ) { | ||||
416 | |||||
417 | # The wikiname is also a login name for the purposes of this | ||||
418 | # mapping. We have to do this because Foswiki defines access controls | ||||
419 | # in terms of mapped users, and if a wikiname is *missing* from the | ||||
420 | # mapping there is "no such user". | ||||
421 | push( @users, $this->{L2U}->{$wn} ); | ||||
422 | } | ||||
423 | } | ||||
424 | 378 | 1.11ms | return \@users; | ||
425 | } | ||||
426 | |||||
427 | =begin TML | ||||
428 | |||||
429 | ---++ ObjectMethod checkPassword( $login, $passwordU ) -> $boolean | ||||
430 | |||||
431 | Finds if the password is valid for the given user. | ||||
432 | |||||
433 | Returns 1 on success, undef on failure. | ||||
434 | |||||
435 | =cut | ||||
436 | |||||
437 | sub checkPassword { | ||||
438 | my ( $this, $login, $pass ) = @_; | ||||
439 | |||||
440 | my $hash = $this->{L2P}->{$login}; | ||||
441 | |||||
442 | if ($hash) { | ||||
443 | if ( length($hash) == 13 ) { | ||||
444 | return 1 if ( crypt( $pass, $hash ) eq $hash ); | ||||
445 | } | ||||
446 | elsif ( length($hash) == 42 ) { | ||||
447 | my $salt = substr( $hash, 0, 10 ); | ||||
448 | return 1 | ||||
449 | if ( $salt . Digest::MD5::md5_hex( $salt . $pass ) eq $hash ); | ||||
450 | } | ||||
451 | else { | ||||
452 | my $salt = substr( $hash, 0, 14 ); | ||||
453 | return 1 | ||||
454 | if ( | ||||
455 | Crypt::PasswdMD5::apache_md5_crypt( $pass, $salt ) eq $hash ); | ||||
456 | } | ||||
457 | } | ||||
458 | |||||
459 | # be a little more helpful to the admin | ||||
460 | if ( $login eq $Foswiki::cfg{AdminUserLogin} && !$hash ) { | ||||
461 | $this->{error} = | ||||
462 | 'To login as ' . $login . ', you must set {Password} in configure.'; | ||||
463 | } | ||||
464 | return 0; | ||||
465 | } | ||||
466 | |||||
467 | =begin TML | ||||
468 | |||||
469 | ---++ ObjectMethod setPassword( $cUID, $newPassU, $oldPassU ) -> $boolean | ||||
470 | |||||
471 | If the $oldPassU matches matches the user's password, then it will | ||||
472 | replace it with $newPassU. | ||||
473 | |||||
474 | If $oldPassU is not correct and not 1, will return 0. | ||||
475 | |||||
476 | If $oldPassU is 1, will force the change irrespective of | ||||
477 | the existing password, adding the user if necessary. | ||||
478 | |||||
479 | Otherwise returns 1 on success, undef on failure. | ||||
480 | |||||
481 | =cut | ||||
482 | |||||
483 | sub setPassword { | ||||
484 | my ( $this, $cUID, $newPassU, $oldPassU ) = @_; | ||||
485 | throw Error::Simple( | ||||
486 | 'cannot change user passwords using Foswiki::BaseUserMapping'); | ||||
487 | } | ||||
488 | |||||
489 | =begin TML | ||||
490 | |||||
491 | ---++ ObjectMethod passwordError( ) -> $string | ||||
492 | |||||
493 | returns a string indicating the error that happened in the password handlers | ||||
494 | TODO: these delayed error's should be replaced with Exceptions. | ||||
495 | |||||
496 | returns undef if no error | ||||
497 | |||||
498 | =cut | ||||
499 | |||||
500 | sub passwordError { | ||||
501 | my $this = shift; | ||||
502 | |||||
503 | return $this->{error}; | ||||
504 | } | ||||
505 | |||||
506 | 1 | 4µs | 1; | ||
507 | __END__ |