none
[openafs-wiki.git] / TWiki / TWikiUsersDotPm.mdwn
1 # <a name="Package &lt;code&gt;TWiki::Users="></a> Package =TWiki::Users
2
3 This package provides services for the lookup and manipulation of login and wiki names of users, and their authentication.
4
5 It is a Facade that presents a common interface to the User Mapping and Password modules. The rest of the core should **only** use the methods of this package, and should **never** call the mapping or password managers directly.
6
7 TWiki uses the concept of a _login name_ which is used to authenticate a user. A login name maps to a _wiki name_ that is used to identify the user for display. Each login name is unique to a single user, though several login names may map to the same wiki name.
8
9 Using this module (and the associated plug-in user mapper) TWiki supports the concept of _groups_. Groups are sets of login names that are treated equally for the purposes of access control. Group names do not have to be wiki names, though it is helpful for display if they are.
10
11 Internally in the code TWiki uses something referred to as a \_canonical user id\_ or just _user id_. The user id is also used externally to uniquely identify the user when (for example) recording topic histories. The user id is **usually** just the login name, but it doesn't need to be. It just has to be a unique 7-bit alphanumeric and underscore string that can be mapped to/from login and wiki names by the user mapper.
12
13 The canonical user id should **never** be seen by a user. On the other hand, core code should never use anything **but** a canonical user id to refer to a user.
14
15 **Terminology**
16
17 - A **login name** is the name used to log in to TWiki. Each login name is assumed to be unique to a human. The Password module is responsible for authenticating and manipulating login names.
18 - A **canonical user id** is an internal TWiki representation of a user. Each canonical user id maps 1:1 to a login name.
19 - A **wikiname** is how a user is displayed. Many user ids may map to a single wikiname. The user mapping module is responsible for mapping the user id to a wikiname.
20 - A **group id** represents a group of users and other groups. The user mapping module is responsible for mapping from a group id to a list of canonical user ids for the users in that group.
21 - An **email** is an email address asscoiated with a **login name**. A single login name may have many emails.
22
23 **NOTE:**
24
25 - wherever the code references $user, its a canonical\_id
26 - wherever the code references $group, its a group\_name
27
28 <div>
29   <ul>
30     <li><a href="#Package =TWiki::Users="> Package TWiki::Users</a><ul>
31         <li><a href="#ClassMethod <strong>new</strong> ($session)"> ClassMethod new <tt>($session)</tt></a></li>
32         <li><a href="#ObjectMethod <strong>finish</strong> ()"> ObjectMethod finish <tt>()</tt></a></li>
33         <li><a href="#ObjectMethod *login_TemplateName"> ObjectMethod loginTemplateName <tt>() -&gt; templateFile</tt></a></li>
34         <li><a href="#ObjectMethod *supportsRegistrati"> ObjectMethod supportsRegistration <tt>() -&gt; boolean</tt></a></li>
35         <li><a href="#ObjectMethod <strong>initialiseUser</strong> ($"> ObjectMethod initialiseUser <tt>($login) -&gt; cUID</tt></a></li>
36         <li><a href="#randomPassword()"> randomPassword()</a></li>
37         <li><a href="#ObjectMethod <strong>addUser</strong> ($login,$"> ObjectMethod addUser <tt>($login,$wikiname,$password,$emails) -&gt; $cUID</tt></a></li>
38         <li><a href="#StaticMethod <strong>forceCUID</strong> ($cUID)"> StaticMethod forceCUID <tt>($cUID) -&gt; $cUID</tt></a></li>
39         <li><a href="#ObjectMethod *get_CanonicalUserI"> ObjectMethod getCanonicalUserID <tt>($login) -&gt; $user</tt></a></li>
40         <li><a href="#ObjectMethod *find_UserByWikiNam"> ObjectMethod findUserByWikiName <tt>($wn) -&gt; \@users</tt></a></li>
41         <li><a href="#ObjectMethod *find_UserByEmail*"> ObjectMethod findUserByEmail <tt>($email) -&gt; \@users</tt></a></li>
42         <li><a href="#ObjectMethod <strong>getEmails</strong> ($user)"> ObjectMethod getEmails <tt>($user) -&gt; @emailAddress</tt></a></li>
43         <li><a href="#ObjectMethod <strong>setEmails</strong> ($user,"> ObjectMethod setEmails <tt>($user,@emails)</tt></a></li>
44         <li><a href="#ObjectMethod <strong>isAdmin</strong> ($cUID) -"> ObjectMethod isAdmin <tt>($cUID) -&gt; $boolean</tt></a></li>
45         <li><a href="#ObjectMethod <strong>is_InList</strong> ($user,"> ObjectMethod isInList <tt>($user,$list) -&gt; $boolean</tt></a></li>
46         <li><a href="#ObjectMethod <strong>get_LoginName</strong> ($c"> ObjectMethod getLoginName <tt>($cUID) -&gt; $string</tt></a></li>
47         <li><a href="#ObjectMethod <strong>get_WikiName</strong> ($cU"> ObjectMethod getWikiName <tt>($cUID) -&gt; $wikiName</tt></a></li>
48         <li><a href="#ObjectMethod <strong>web_DotWikiName</strong> ("> ObjectMethod webDotWikiName <tt>($user) -&gt; $webDotWiki</tt></a></li>
49         <li><a href="#ObjectMethod <strong>userExists</strong> ($cUID"> ObjectMethod userExists <tt>($cUID) -&gt; $boolean</tt></a></li>
50         <li><a href="#ObjectMethod <strong>eachUser</strong> () -> $i"> ObjectMethod eachUser <tt>() -&gt; $iterator</tt></a></li>
51         <li><a href="#ObjectMethod <strong>eachGroup</strong> () -> $"> ObjectMethod eachGroup <tt>() -&gt; $iterator</tt></a></li>
52         <li><a href="#ObjectMethod *each_GroupMember*"> ObjectMethod eachGroupMember <tt>($group) -&gt; $iterator</tt></a></li>
53         <li><a href="#ObjectMethod <strong>isGroup</strong> ($user) -"> ObjectMethod isGroup <tt>($user) -&gt; boolean</tt></a></li>
54         <li><a href="#ObjectMethod <strong>is_InGroup</strong> ($user"> ObjectMethod isInGroup <tt>($user,$group) -&gt; $boolean</tt></a></li>
55         <li><a href="#ObjectMethod <strong>eachMembership</strong> ($"> ObjectMethod eachMembership <tt>($cUID) -&gt; $iterator</tt></a></li>
56         <li><a href="#ObjectMethod <strong>checkPassword</strong> ($u"> ObjectMethod checkPassword <tt>($userName,$passwordU) -&gt; $boolean</tt></a></li>
57         <li><a href="#ObjectMethod <strong>setPassword</strong> ($use"> ObjectMethod setPassword <tt>($user,$newPassU,$oldPassU) -&gt; $boolean</tt></a></li>
58         <li><a href="#ObjectMethod <strong>passwordError</strong> ()"> ObjectMethod passwordError <tt>() -&gt; $string</tt></a></li>
59         <li><a href="#ObjectMethod <strong>removeUser</strong> ($user"> ObjectMethod removeUser <tt>($user) -&gt; $boolean</tt></a></li>
60         <li><a href="#ObjectMethod *ASSERT_IS_CANONICA"> ObjectMethod ASSERT_IS_CANONICAL_USER_ID <tt>($user_id) -&gt; $boolean</tt></a></li>
61         <li><a href="#ObjectMethod *ASSERT_IS_USER_LOG"> ObjectMethod ASSERT_IS_USER_LOGIN_ID <tt>($user_login) -&gt; $boolean</tt></a></li>
62         <li><a href="#ObjectMethod *ASSERT_IS_USER_DIS"> ObjectMethod ASSERT_IS_USER_DISPLAY_NAME <tt>($user_display) -&gt; $boolean</tt></a></li>
63       </ul>
64     </li>
65   </ul>
66 </div>
67
68 ## <a name="ClassMethod &lt;strong&gt;new&lt;/strong&gt; ($session)"></a> [[ClassMethod]] **new** `($session)`
69
70 Construct the user management object that is the facade to the [[BaseUserMapping]] and the user mapping chosen in the configuration.
71
72 ## <a name="ObjectMethod &lt;strong&gt;finish&lt;/strong&gt; ()"></a> [[ObjectMethod]] **finish** `()`
73
74 Break circular references.
75
76 ## <a name="ObjectMethod &lt;strong&gt;login_TemplateName"></a> [[ObjectMethod]] \*loginTemplateName `() -> templateFile`
77
78 allows [[UserMappings]] to come with customised login screens - that should preffereably only over-ride the UI function
79
80 ## <a name="ObjectMethod &lt;strong&gt;supportsRegistrati"></a> [[ObjectMethod]] \*supportsRegistration `() -> boolean`
81
82 #return 1 if the main [[UserMapper]] supports registration (ie can create new users)
83
84 ## <a name="ObjectMethod &lt;strong&gt;initialiseUser&lt;/strong&gt; ($"></a> [[ObjectMethod]] **initialiseUser** `($login) -> cUID`
85
86 ## <a name="randomPassword()"></a> randomPassword()
87
88 Static function that returns a random password
89
90 ## <a name="ObjectMethod &lt;strong&gt;addUser&lt;/strong&gt; ($login,$"></a> [[ObjectMethod]] **addUser** `($login,$wikiname,$password,$emails) -> $cUID`
91
92 - `$login` - user login name. If `undef`, `$wikiname` will be used as the login name.
93 - `$wikiname` - user wikiname. If `undef`, the user mapper will be asked to provide it.
94 - `$password` - password. If undef, a password will be generated.
95
96 Add a new TWiki user identity, returning the canonical user id for the new user. Used ONLY for user registration.
97
98 The user is added to the password system (if there is one, and if it accepts changes). If the user already exists in the password system, then the password is checked and an exception thrown if it doesn't match. If there is no existing user, and no password is given, a random password is generated.
99
100 $login can be undef; $wikiname must always have a value.
101
102 The return value is the canonical user id that is used by TWiki to identify the user.
103
104 ## <a name="StaticMethod &lt;strong&gt;forceCUID&lt;/strong&gt; ($cUID)"></a> [[StaticMethod]] **forceCUID** `($cUID) -> $cUID`
105
106 This function ensures that any cUID's are able to be used for rcs, and other internals not capable of coping with user identifications that contain more than 7 bit ascii.
107
108 repeated calls must result in the same result (sorry, can't spell the word for it)so the '\_' must not be re-encoded
109
110 Please, call this function in any custom Usermapper to simplifyyour mapping code.
111
112 ## <a name="ObjectMethod &lt;strong&gt;get_CanonicalUserI"></a> [[ObjectMethod]] \*getCanonicalUserID `($login) -> $user`
113
114 Works out the unique TWiki identifier for the user who logs in with the given login. The canonical user ID is an alphanumeric string that is unique to the login name, and can be mapped back to a login name and the corresponding wiki name using the methods of this class.
115
116 returns undef if the user does not exist.
117
118 ## <a name="ObjectMethod &lt;strong&gt;find_UserByWikiNam"></a> [[ObjectMethod]] \*findUserByWikiName `($wn) -> \@users`
119
120 - `$wn` - wikiname to look up
121
122 Return a list of canonical user names for the users that have this wikiname. Since a single wikiname might be used by multiple login ids, we need a list.
123
124 If $wn is the name of a group, the group will **not** be expanded.
125
126 ## <a name="ObjectMethod &lt;strong&gt;find_UserByEmail*"></a><a name="ObjectMethod *find_UserByEmail&lt;/strong&gt; "></a> [[ObjectMethod]] **findUserByEmail** `($email) -> \@users`
127
128 - `$email` - email address to look up
129
130 Return a list of canonical user names for the users that have this email registered with the user mapping managers.
131
132 ## <a name="ObjectMethod &lt;strong&gt;getEmails&lt;/strong&gt; ($user)"></a> [[ObjectMethod]] **getEmails** `($user) -> @emailAddress`
133
134 If this is a user, return their email addresses. If it is a group, return the addresses of everyone in the group.
135
136 The password manager and user mapping manager are both consulted for emails for each user (where they are actually found is implementation defined).
137
138 Duplicates are removed from the list.
139
140 ## <a name="ObjectMethod &lt;strong&gt;setEmails&lt;/strong&gt; ($user,"></a> [[ObjectMethod]] **setEmails** `($user,@emails)`
141
142 Set the email address(es) for the given user. The password manager is tried first, and if it doesn't want to know the user mapping manager is tried.
143
144 ## <a name="ObjectMethod &lt;strong&gt;isAdmin&lt;/strong&gt; ($cUID) -"></a> [[ObjectMethod]] **isAdmin** `($cUID) -> $boolean`
145
146 True if the user is an admin
147
148 - is $TWiki::cfg\{SuperAdminGroup\}
149 - is a member of the $TWiki::cfg\{SuperAdminGroup\}
150
151 ## <a name="ObjectMethod &lt;strong&gt;is_InList&lt;/strong&gt; ($user,"></a> [[ObjectMethod]] **isInList** `($user,$list) -> $boolean`
152
153 Return true if $user is in a list of user **wikinames** and group ids.
154
155 $list is a comma-separated wikiname and group list. The list may contain the conventional web specifiers (which are ignored).
156
157 ## <a name="ObjectMethod &lt;strong&gt;get_LoginName&lt;/strong&gt; ($c"></a> [[ObjectMethod]] **getLoginName** `($cUID) -> $string`
158
159 Get the login name of a user.
160
161 ## <a name="ObjectMethod &lt;strong&gt;get_WikiName&lt;/strong&gt; ($cU"></a> [[ObjectMethod]] **getWikiName** `($cUID) -> $wikiName`
162
163 Get the wikiname to display for a canonical user identifier.
164
165 can return undef if the user is not in the mapping system (or the special case from initialiseUser)
166
167 ## <a name="ObjectMethod &lt;strong&gt;web_DotWikiName&lt;/strong&gt; ("></a> [[ObjectMethod]] **webDotWikiName** `($user) -> $webDotWiki`
168
169 Return the fully qualified wikiname of the user
170
171 ## <a name="ObjectMethod &lt;strong&gt;userExists&lt;/strong&gt; ($cUID"></a> [[ObjectMethod]] **userExists** `($cUID) -> $boolean`
172
173 Determine if the user already exists or not. A user exists if they are known to to the user mapper.
174
175 ## <a name="ObjectMethod &lt;strong&gt;eachUser&lt;/strong&gt; () - $it"></a> [[ObjectMethod]] **eachUser** `() -> $iterator`
176
177 Get an iterator over the list of all the registered users **not** including groups.
178
179 list of canonical\_ids ???
180
181 Use it as follows:
182
183         my $iterator = $umm->eachUser();
184         while ($iterator->hasNext()) {
185             my $user = $iterator->next();
186             ...
187         }
188
189 ## <a name="ObjectMethod &lt;strong&gt;eachGroup&lt;/strong&gt; () - $i"></a> [[ObjectMethod]] **eachGroup** `() -> $iterator`
190
191 Get an iterator over the list of all the groups.
192
193 ## <a name="ObjectMethod &lt;strong&gt;each_GroupMember*"></a><a name="ObjectMethod *each_GroupMember&lt;/strong&gt; "></a> [[ObjectMethod]] **eachGroupMember** `($group) -> $iterator`
194
195 Return a iterator of user ids that are members of this group. Should only be called on groups.
196
197 Note that groups may be defined recursively, so a group may contain other groups. This method should **only** return users i.e. all contained groups should be fully expanded.
198
199 ## <a name="ObjectMethod &lt;strong&gt;isGroup&lt;/strong&gt; ($user) -"></a> [[ObjectMethod]] **isGroup** `($user) -> boolean`
200
201 Establish if a user refers to a group or not.
202
203 The default implementation is to check if the wikiname of the user ends with 'Group'. Subclasses may override this behaviour to provide alternative interpretations. The $TWiki::cfg\{SuperAdminGroup\} is recognized as a group no matter what it's name is.
204
205 QUESTION: is the $user parameter here a string, or a canonical\_id??
206
207 ## <a name="ObjectMethod &lt;strong&gt;is_InGroup&lt;/strong&gt; ($user"></a> [[ObjectMethod]] **isInGroup** `($user,$group) -> $boolean`
208
209 Test if user is in the given group.
210
211 ## <a name="ObjectMethod &lt;strong&gt;eachMembership&lt;/strong&gt; ($"></a> [[ObjectMethod]] **eachMembership** `($cUID) -> $iterator`
212
213 Return an iterator over the groups that $cUID is a member of.
214
215 ## <a name="ObjectMethod &lt;strong&gt;checkPassword&lt;/strong&gt; ($u"></a> [[ObjectMethod]] **checkPassword** `($userName,$passwordU) -> $boolean`
216
217 Finds if the password is valid for the given user.
218
219 Returns 1 on success, undef on failure.
220
221 TODO: add special check for [[BaseMapping]] admin user's login, and if its there (and we're in sudo\_context?) use that..
222
223 ## <a name="ObjectMethod &lt;strong&gt;setPassword&lt;/strong&gt; ($use"></a> [[ObjectMethod]] **setPassword** `($user,$newPassU,$oldPassU) -> $boolean`
224
225 If the $oldPassU matches matches the user's password, then it will replace it with $newPassU.
226
227 If $oldPassU is not correct and not 1, will return 0.
228
229 If $oldPassU is 1, will force the change irrespective of the existing password, adding the user if necessary.
230
231 Otherwise returns 1 on success, undef on failure.
232
233 ## <a name="ObjectMethod &lt;strong&gt;passwordError&lt;/strong&gt; ()"></a><a name="ObjectMethod &lt;strong&gt;passwordError&lt;/strong&gt; () "></a> [[ObjectMethod]] **passwordError** `() -> $string`
234
235 returns a string indicating the error that happened in the password handlers TODO: these delayed error's should be replaced with Exceptions.
236
237 returns undef if no error
238
239 ## <a name="ObjectMethod &lt;strong&gt;removeUser&lt;/strong&gt; ($user"></a> [[ObjectMethod]] **removeUser** `($user) -> $boolean`
240
241 Delete the users entry. Removes the user from the password manager and user mapping manager. Does **not** remove their personal topics, which may still be linked.
242
243 ## <a name="ObjectMethod &lt;strong&gt;ASSERT_IS_CANONICA"></a> [[ObjectMethod]] \*ASSERT\_IS\_CANONICAL\_USER\_ID `($user_id) -> $boolean`
244
245 used for debugging to ensure we are actually passing a canonical\_id
246
247 These ASSERTS have been disabled, as they have been made dangerous and misleading due to the legacy cUID code
248
249 ## <a name="ObjectMethod &lt;strong&gt;ASSERT_IS_USER_LOG"></a> [[ObjectMethod]] \*ASSERT\_IS\_USER\_LOGIN\_ID `($user_login) -> $boolean`
250
251 used for debugging to ensure we are actually passing a user login
252
253 These ASSERTS have been disabled, as they have been made dangerous and misleading due to the legacy cUID code
254
255 ## <a name="ObjectMethod &lt;strong&gt;ASSERT_IS_USER_DIS"></a> [[ObjectMethod]] \*ASSERT\_IS\_USER\_DISPLAY\_NAME `($user_display) -> $boolean`
256
257 used for debugging to ensure we are actually passing a user display\_name (commonly a [[WikiWord]] Name)
258
259 These ASSERTS have been disabled, as they have been made dangerous and misleading due to the legacy cUID code