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