head	1.3;
access;
symbols;
locks; strict;
comment	@# @;


1.3
date	2011.08.21.04.16.08;	author TWikiContributor;	state Exp;
branches;
next	1.2;

1.2
date	2008.08.03.22.17.41;	author TWikiContributor;	state Exp;
branches;
next	1.1;

1.1
date	2008.01.22.03.21.24;	author TWikiContributor;	state Exp;
branches;
next	;


desc
@buildrelease
@


1.3
log
@buildrelease
@
text
@---+ Package =TWiki::UserMapping=

This is a virtual base class (a.k.a an interface) for all user mappers. It is
*not* useable as a mapping in TWiki - use the BaseUserMapping for default
behaviour.

User mapping is the process by which TWiki maps from a username (a login name)
to a display name and back. It is also where groups are maintained.

See TWiki::Users::BaseUserMapping and TWiki::Users::TWikiUserMapping for
the default implementations of this interface.

If you want to write a user mapper, you will need to implement the methods
described in this class.

User mappings work by mapping both login names and display names to a
_canonical user id_. This user id is composed from a prefix that defines
the mapper in use (something like 'BaseUserMapping_' or 'LdapUserMapping_')
and a unique user id that the mapper uses to identify the user.

The null prefix is reserver for the TWikiUserMapping for compatibility
with old TWiki releases.

__Note:__ in all the following documentation, =$cUID= refers to a
*canonical user id*.


%TOC%

---++ PROTECTED ClassMethod new ($session, $mapping_id)

Construct a user mapping object, using the given mapping id.


---++ ObjectMethod *finish* <tt>()</tt>
Break circular references.



---++ ObjectMethod *loginTemplateName* <tt>() -> $templateFile</tt>

Allows UserMappings to come with customised login screens - that should
preferably only over-ride the UI function

Default is "login"



---++ ObjectMethod *supportsRegistration* <tt>() -> $boolean</tt>

Return true if the UserMapper supports registration (ie can create new users)

Default is *false*



---++ ObjectMethod *handlesUser* <tt>($cUID,$login,$wikiname) -> $boolean</tt>

Called by the TWiki::Users object to determine which loaded mapping
to use for a given user (must be fast).

The user can be identified by any of $cUID, $login or $wikiname. Any of
these parameters may be undef, and they should be tested in order; cUID
first, then login, then wikiname.



---++ ObjectMethod *login2cUID* <tt>($login,$dontcheck) -> cUID</tt>

Convert a login name to the corresponding canonical user name. The
canonical name can be any string of 7-bit alphanumeric and underscore
characters, and must map 1:1 to the login name.
(undef on failure)

(if $dontcheck is true, return a cUID for a nonexistant user too.
This is used for registration)

Subclasses *must* implement this method.

Note: This method was previously (in TWiki 4.2.0) known as getCanonicalUserID.
The name was changed to avoid confusion with TWiki::Users::getCanonicalUserID,
which has a more generic function. However to support older user mappers,
getCanonicalUserID will still be called if login2cUID is not defined.



---++ ObjectMethod *getLoginName* <tt>($cUID) -> login</tt>

Converts an internal cUID to that user's login
(undef on failure)

Subclasses *must* implement this method.



---++ ObjectMethod *addUser* <tt>($login,$wikiname,$password,$emails,$mcp) -> $cUID</tt>

Add a user to the persistant mapping that maps from usernames to wikinames
and vice-versa.

$login and $wikiname must be acceptable to $TWiki::cfg{NameFilter}.
$login must *always* be specified. $wikiname may be undef, in which case
the user mapper should make one up.

This function must return a canonical user id that it uses to uniquely
identify the user. This can be the login name, or the wikiname if they
are all guaranteed unigue, or some other string consisting only of 7-bit
alphanumerics and underscores.

If you fail to create a new user (for eg your Mapper has read only access),
<pre>
    throw Error::Simple('Failed to add user: '.$error);
</pre>
where $error is a descriptive string.

Throws an Error::Simple if user adding is not supported (the default).



---++ ObjectMethod *removeUser* <tt>($cUID) -> $boolean</tt>

Delete the users entry from this mapper. Throws an Error::Simple if
user removal is not supported (the default).



---++ ObjectMethod *getWikiName* <tt>($cUID) -> $wikiname</tt>

Map a canonical user name to a wikiname.

Returns the $cUID by default.



---++ ObjectMethod *userExists* <tt>($cUID) -> $boolean</tt>

Determine if the user already exists or not. Whether a user exists
or not is determined by the password manager.

Subclasses *must* implement this method.



---++ ObjectMethod *eachUser* <tt>() -> TWiki::ListIteratorofcUIDs</tt>

Get an iterator over the list of all the registered users *not* including
groups.

Subclasses *must* implement this method.



---++ ObjectMethod *eachGroupMember* <tt>($group) -> TWiki::ListIteratorofcUIDs</tt>

Return a iterator over the canonical user ids of users that are members
of this group. Should only be called on groups.

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.

Subclasses *must* implement this method.



---++ ObjectMethod *isGroup* <tt>($name) -> boolean</tt>

Establish if a user refers to a group or not. If $name is not
a group name it will probably be a canonical user id, though that
should not be assumed.

Subclasses *must* implement this method.



---++ ObjectMethod *eachGroup* <tt>() -> TWiki::ListIteratorofgroupnames</tt>

Get an iterator over the list of all the groups.

Subclasses *must* implement this method.



---++ ObjectMethod *eachMembership* <tt>($cUID) -> TWiki::ListIteratorofgroupsthisuserisin</tt>

Return an iterator over the names of groups that $cUID is a member of.

Subclasses *must* implement this method.



---++ ObjectMethod *isAdmin* <tt>($cUID) -> $boolean</tt>

True if the user is an administrator.



---++ ObjectMethod *isInGroup* <tt>($cUID,$group) -> $bool</tt>

Test if the user identified by $cUID is in the given group. The default
implementation iterates over all the members of $group, which is rather
inefficient.



---++ ObjectMethod *findUserByEmail* <tt>($email) -> \@@users</tt>
   * =$email= - email address to look up
Return a list of canonical user names for the users that have this email
registered with the password manager or the user mapping manager.



---++ ObjectMethod *getEmails* <tt>($name) -> @@emailAddress</tt>

If $name is a cUID, return that user's email addresses. If it is a group,
return the addresses of everyone in the group.

Duplicates should be removed from the list.



---++ ObjectMethod *setEmails* <tt>($cUID,@@emails)</tt>

Set the email address(es) for the given user.



---++ ObjectMethod *getMustChangePassword* <tt>($cUID) -> $flag</tt>

Returns 1 if the $cUID must change the password, else 0. Returns undef if $cUID not found.



---++ ObjectMethod *getUserData* <tt>($cUID) -> $dataRef</tt>

Return a reference to an array of hashes with user data, used to manage 
users. Each item is a hash with:

   * ={name}= - name of field, such as "email"
   * ={title}= - title of field, such as "E-mail"
   * ={value}= - value of field, such as "jimmy@@example.com"
   * ={type}= - type of field: =text=, =password=, =checkbox=, =label=
   * ={size}= - size of field, such as =40=
   * ={note}= - comment note, if any

User management forms can be build dynamically from this data structure.
Each password manager may return a different set of fields.



---++ ObjectMethod *setUserData* <tt>($cUID,$dataRef)</tt>

Set the user data of a user. Same array of hashes as getUserData is 
assumed, although only ={name}= and ={value}= are used.



---++ ObjectMethod *findUserByWikiName* <tt>($wikiname) -> listofcUIDsassociatedwiththatwikiname</tt>
   * =$wikiname= - wikiname to look up
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.

Note that if $wikiname is the name of a group, the group will *not* be
expanded.

Subclasses *must* implement this method.



---++ ObjectMethod *checkPassword* <tt>($login,$passwordU) -> $boolean</tt>

Finds if the password is valid for the given login. This is called using
a login name rather than a cUID because the user may not have been mapped
at the time it is called.

Returns 1 on success, undef on failure.

Default behaviour is to return 1.



---++ ObjectMethod *setPassword* <tt>($cUID,$newPassU,$oldPassU) -> $boolean</tt>

If the $oldPassU matches matches the user's password, then it will
replace it with $newPassU.

If $oldPassU is not correct and not 1, will return 0.

If $oldPassU is 1, will force the change irrespective of
the existing password, adding the user if necessary.

Otherwise returns 1 on success, undef on failure.

Default behaviour is to fail.



---++ ObjectMethod *passwordError* <tt>() -> $string</tt>

Returns a string indicating the error that happened in the password handlers
TODO: these delayed errors should be replaced with Exceptions.

returns undef if no error (the default)


@


1.2
log
@buildrelease
@
text
@d96 1
a96 1
---++ ObjectMethod *addUser* <tt>($login,$wikiname,$password,$emails) -> $cUID</tt>
d228 30
@


1.1
log
@buildrelease
@
text
@d24 1
a24 1
__Note:__ in all the following documentation, =$user= refers to a
d62 3
a64 1
Default is *false*
d68 1
a68 1
---++ ObjectMethod *getCanonicalUserID* <tt>($login,$dontcheck) -> cUID</tt>
d72 1
a72 1
characters, and must correspond 1:1 to the login name.
d75 2
a76 1
(if dontcheck is true, return a cUID for a nonexistant user too - used for registration)
d80 4
d96 1
a96 1
---++ ObjectMethod *addUser* <tt>($login,$wikiname,$password,$emails) -> cUID</tt>
d99 1
a99 1
and vice-versa, via a *canonical user id* (cUID).
d120 1
a120 1
---++ ObjectMethod *removeUser* <tt>($user) -> $boolean</tt>
d127 1
a127 1
---++ ObjectMethod *getWikiName* <tt>($cUID) -> wikiname</tt>
d144 1
a144 1
---++ ObjectMethod *eachUser* <tt>() -> listIteratorofcUIDs</tt>
d146 2
a147 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d155 6
a160 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d166 1
a166 1
---++ ObjectMethod *isGroup* <tt>($user) -> boolean</tt>
d168 3
a170 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d176 1
a176 1
---++ ObjectMethod *eachGroup* <tt>() -> ListIteratorofgroupnames</tt>
d178 1
a178 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d184 1
a184 1
---++ ObjectMethod *eachMembership* <tt>($cUID) -> ListIteratorofgroupsthisuserisin</tt>
d186 1
a186 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d192 1
a192 1
---++ ObjectMethod *isAdmin* <tt>($user) -> $boolean</tt>
d194 1
a194 1
True if the user is an administrator. Default is *false*
d198 1
a198 1
---++ ObjectMethod *isInGroup* <tt>($user,$group,$scanning) -> bool</tt>
d200 3
a202 4
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.

Default is *false*
a210 2
Returns an empty list by default.

d213 1
a213 1
---++ ObjectMethod *getEmails* <tt>($user) -> @@emailAddress</tt>
d215 1
a215 1
If this is a user, return their email addresses. If it is a group,
a219 1
By default, returns the empty list.
d222 1
d224 1
a224 3
---++ ObjectMethod *setEmails* <tt>($user,@@emails)</tt>

Set the email address(es) for the given user. Does nothing by default.
d229 3
d233 2
a234 2
Called from TWiki::Users. See the documentation of the corresponding
method in that module for details.
d240 1
a240 1
---++ ObjectMethod *checkPassword* <tt>($userName,$passwordU) -> $boolean</tt>
d242 3
a244 1
Finds if the password is valid for the given user.
d252 1
a252 1
---++ ObjectMethod *setPassword* <tt>($user,$newPassU,$oldPassU) -> $boolean</tt>
d273 1
a273 22
returns undef if no error 9the default)



---++ ObjectMethod *ASSERT_IS_CANONICAL_USER_ID* <tt>($user_id) -> $boolean</tt>

Used for debugging to ensure we are actually passing a canonical_id



---++ ObjectMethod *ASSERT_IS_USER_LOGIN_ID* <tt>($user_login) -> $boolean</tt>

Used for debugging to ensure we are actually passing a user login



---++ ObjectMethod *ASSERT_IS_USER_DISPLAY_NAME* <tt>($user_display) -> $boolean</tt>

Used for debugging to ensure we are actually passing a user display_name
(commonly a WikiWord Name)

Returns true by default.
@
