com.ecyrd.jspwiki.auth.user
Interface UserDatabase

All Known Implementing Classes:
AbstractUserDatabase, JDBCUserDatabase, UserManager.DummyUserDatabase, XMLUserDatabase

public interface UserDatabase

Defines an interface for loading, persisting and storing users.

Since:
2.3
Author:
Janne Jalkanen, Andrew Jaquith

Method Summary
 void commit()
          Deprecated. there is no need to call this method because the save, rename and delete methods contain their own commit logic
 void deleteByLoginName(String loginName)
          Looks up and deletes the first UserProfile in the user database that matches a profile having a given login name.
 UserProfile find(String index)
          Looks up and returns the first UserProfile in the user database that whose login name, full name, or wiki name matches the supplied string.
 UserProfile findByEmail(String index)
          Looks up and returns the first UserProfile in the user database that matches a profile having a given e-mail address.
 UserProfile findByFullName(String index)
          Looks up and returns the first UserProfile in the user database that matches a profile having a given full name.
 UserProfile findByLoginName(String index)
          Looks up and returns the first UserProfile in the user database that matches a profile having a given login name.
 UserProfile findByUid(String uid)
          Looks up and returns the first UserProfile in the user database that matches a profile having a given unique ID (uid).
 UserProfile findByWikiName(String index)
          Looks up and returns the first UserProfile in the user database that matches a profile having a given wiki name.
 Principal[] getPrincipals(String identifier)
           Looks up the Principals representing a user from the user database.
 Principal[] getWikiNames()
          Returns all WikiNames that are stored in the UserDatabase as an array of Principal objects.
 void initialize(WikiEngine engine, Properties props)
          Initializes the user database based on values from a Properties object.
 UserProfile newProfile()
          Factory method that instantiates a new user profile.
 void rename(String loginName, String newName)
          Renames a UserProfile in the user database by changing the profile's login name.
 void save(UserProfile profile)
           Saves a UserProfileto the user database, overwriting the existing profile if it exists.
 boolean validatePassword(String loginName, String password)
          Determines whether a supplied user password is valid, given a login name and password.
 

Method Detail

commit

void commit()
            throws WikiSecurityException
Deprecated. there is no need to call this method because the save, rename and delete methods contain their own commit logic

No-op method that in previous versions of JSPWiki was intended to atomically commit changes to the user database. Now, the rename(String, String), save(UserProfile) and deleteByLoginName(String) methods are atomic themselves.

Throws:
WikiSecurityException

deleteByLoginName

void deleteByLoginName(String loginName)
                       throws NoSuchPrincipalException,
                              WikiSecurityException
Looks up and deletes the first UserProfile in the user database that matches a profile having a given login name. If the user database does not contain a user with a matching attribute, throws a NoSuchPrincipalException. This method is intended to be atomic; results cannot be partially committed. If the commit fails, it should roll back its state appropriately. Implementing classes that persist to the file system may wish to make this method synchronized.

Parameters:
loginName - the login name of the user profile that shall be deleted
Throws:
NoSuchPrincipalException
WikiSecurityException

getPrincipals

Principal[] getPrincipals(String identifier)
                          throws NoSuchPrincipalException

Looks up the Principals representing a user from the user database. These are defined as a set of Principals manufactured from the login name, full name, and wiki name. The order of the Principals returned is not significant. If the user database does not contain a user with the supplied identifier, throws a NoSuchPrincipalException.

Note that if an implememtation wishes to mark one of the returned Principals as representing the user's common name, it should instantiate this Principal using WikiPrincipal.WikiPrincipal(String, String) with the type parameter set to WikiPrincipal.WIKI_NAME. The method WikiSession.getUserPrincipal() will return this principal as the "primary" principal. Note that this method can also be used to mark a WikiPrincipal as a login name or a wiki name.

Parameters:
identifier - the name of the user to retrieve; this corresponds to value returned by the user profile's UserProfile.getLoginName() method.
Returns:
the array of Principals representing the user's identities
Throws:
NoSuchPrincipalException

getWikiNames

Principal[] getWikiNames()
                         throws WikiSecurityException
Returns all WikiNames that are stored in the UserDatabase as an array of Principal objects. If the database does not contain any profiles, this method will return a zero-length array.

Returns:
the WikiNames
Throws:
WikiSecurityException

find

UserProfile find(String index)
                 throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that whose login name, full name, or wiki name matches the supplied string. This method provides a "forgiving" search algorithm for resolving Principal names when the exact profile attribute that supplied the name is unknown.

Parameters:
index - the login name, full name, or wiki name
Throws:
NoSuchPrincipalException

findByEmail

UserProfile findByEmail(String index)
                        throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that matches a profile having a given e-mail address. If the user database does not contain a user with a matching attribute, throws a NoSuchPrincipalException.

Parameters:
index - the e-mail address of the desired user profile
Returns:
the user profile
Throws:
NoSuchPrincipalException

findByLoginName

UserProfile findByLoginName(String index)
                            throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that matches a profile having a given login name. If the user database does not contain a user with a matching attribute, throws a NoSuchPrincipalException.

Parameters:
index - the login name of the desired user profile
Returns:
the user profile
Throws:
NoSuchPrincipalException

findByUid

UserProfile findByUid(String uid)
                      throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that matches a profile having a given unique ID (uid). If the user database does not contain a user with a unique ID, it throws a NoSuchPrincipalException.

Parameters:
uid - the unique identifier of the desired user profile
Returns:
the user profile
Throws:
NoSuchPrincipalException
Since:
2.8

findByWikiName

UserProfile findByWikiName(String index)
                           throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that matches a profile having a given wiki name. If the user database does not contain a user with a matching attribute, throws a NoSuchPrincipalException.

Parameters:
index - the wiki name of the desired user profile
Returns:
the user profile
Throws:
NoSuchPrincipalException

findByFullName

UserProfile findByFullName(String index)
                           throws NoSuchPrincipalException
Looks up and returns the first UserProfile in the user database that matches a profile having a given full name. If the user database does not contain a user with a matching attribute, throws a NoSuchPrincipalException.

Parameters:
index - the fill name of the desired user profile
Returns:
the user profile
Throws:
NoSuchPrincipalException

initialize

void initialize(WikiEngine engine,
                Properties props)
                throws NoRequiredPropertyException
Initializes the user database based on values from a Properties object.

Throws:
NoRequiredPropertyException

newProfile

UserProfile newProfile()
Factory method that instantiates a new user profile. The UserProfile.isNew() method of profiles created using this method should return true.


rename

void rename(String loginName,
            String newName)
            throws NoSuchPrincipalException,
                   DuplicateUserException,
                   WikiSecurityException

Renames a UserProfile in the user database by changing the profile's login name. Because the login name is the profile's unique identifier, implementations should verify that the identifier is "safe" to change before actually changing it. Specifically: the profile with the supplied login name must already exist, and the proposed new name must not be in use by another profile.

This method is intended to be atomic; results cannot be partially committed. If the commit fails, it should roll back its state appropriately. Implementing classes that persist to the file system may wish to make this method synchronized.

Parameters:
loginName - the existing login name for the profile
newName - the proposed new login name
Throws:
NoSuchPrincipalException - if the user profile identified by loginName does not exist
DuplicateUserException - if another user profile with the proposed new login name already exists
WikiSecurityException - if the profile cannot be renamed for any reason, such as an I/O error, database connection failure or lack of support for renames.

save

void save(UserProfile profile)
          throws WikiSecurityException

Saves a UserProfileto the user database, overwriting the existing profile if it exists. The user name under which the profile should be saved is returned by the supplied profile's UserProfile.getLoginName() method.

The database implementation is responsible for detecting potential duplicate user profiles; specifically, the login name, wiki name, and full name must be unique. The implementation is not required to check for validity of passwords or e-mail addresses. Special case: if the profile already exists and the password is null, it should retain its previous value, rather than being set to null.

Implementations are required to time-stamp the creation or modification fields of the UserProfile./p>

This method is intended to be atomic; results cannot be partially committed. If the commit fails, it should roll back its state appropriately. Implementing classes that persist to the file system may wish to make this method synchronized.

Parameters:
profile - the user profile to save
Throws:
WikiSecurityException - if the profile cannot be saved

validatePassword

boolean validatePassword(String loginName,
                         String password)
Determines whether a supplied user password is valid, given a login name and password. It is up to the implementing class to determine how the comparison should be made. For example, the password might be hashed before comparing it to the value persisted in the back-end data store.

Parameters:
loginName - the login name
password - the password
Returns:
true if the password is valid, false otherwise