Class AbstractUserDatabase
- All Implemented Interfaces:
UserDatabase
- Direct Known Subclasses:
DummyUserDatabase,JDBCUserDatabase,XMLUserDatabase
public abstract class AbstractUserDatabase extends Object implements UserDatabase
- Since:
- 2.3
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.log4j.Loggerlogprotected static StringSHA_PREFIXprotected static StringSSHA_PREFIX -
Constructor Summary
Constructors Constructor Description AbstractUserDatabase() -
Method Summary
Modifier and Type Method Description UserProfilefind(String index)Looks up and returns the firstUserProfilein the user database that whose login name, full name, or wiki name matches the supplied string.abstract UserProfilefindByEmail(String index)Looks up and returns the firstUserProfilein the user database that matches a profile having a given e-mail address.abstract UserProfilefindByFullName(String index)Looks up and returns the firstUserProfilein the user database that matches a profile having a given full name.abstract UserProfilefindByLoginName(String index)Looks up and returns the firstUserProfilein the user database that matches a profile having a given login name.abstract UserProfilefindByWikiName(String index)Looks up and returns the firstUserProfilein the user database that matches a profile having a given wiki name.protected static StringgenerateUid(UserDatabase db)Generates a new random user identifier (uid) that is guaranteed to be unique.protected StringgetHash(String text)Private method that calculates the salted SHA-1 hash of a givenString.Principal[]getPrincipals(String identifier)Looks up the Principals representing a user from the user database.abstract voidinitialize(Engine engine, Properties props)Initializes the user database based on values from a Properties object.UserProfilenewProfile()Factory method that instantiates a new DefaultUserProfile with a new, distinct unique identifier.protected longparseLong(String value)Parses a long integer from a supplied string, or returns 0 if not parsable.abstract voidsave(UserProfile profile)Saves aUserProfileto the user database, overwriting the existing profile if it exists.booleanvalidatePassword(String loginName, String password)Validates the password for a given user.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.wiki.auth.user.UserDatabase
deleteByLoginName, findByUid, getWikiNames, rename
-
Field Details
-
log
-
SHA_PREFIX
- See Also:
- Constant Field Values
-
SSHA_PREFIX
- See Also:
- Constant Field Values
-
-
Constructor Details
-
AbstractUserDatabase
public AbstractUserDatabase()
-
-
Method Details
-
find
Looks up and returns the firstUserProfilein 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.- Specified by:
findin interfaceUserDatabase- Parameters:
index- the login name, full name, or wiki name- Throws:
NoSuchPrincipalException- See Also:
UserDatabase.find(java.lang.String)
-
findByEmail
Looks up and returns the firstUserProfilein 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 aNoSuchPrincipalException.- Specified by:
findByEmailin interfaceUserDatabase- Parameters:
index- the e-mail address of the desired user profile- Returns:
- the user profile
- Throws:
NoSuchPrincipalException- See Also:
UserDatabase.findByEmail(java.lang.String)
-
findByFullName
Looks up and returns the firstUserProfilein 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 aNoSuchPrincipalException.- Specified by:
findByFullNamein interfaceUserDatabase- Parameters:
index- the fill name of the desired user profile- Returns:
- the user profile
- Throws:
NoSuchPrincipalException- See Also:
UserDatabase.findByFullName(java.lang.String)
-
findByLoginName
Looks up and returns the firstUserProfilein 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 aNoSuchPrincipalException.- Specified by:
findByLoginNamein interfaceUserDatabase- Parameters:
index- the login name of the desired user profile- Returns:
- the user profile
- Throws:
NoSuchPrincipalException- See Also:
UserDatabase.findByLoginName(java.lang.String)
-
findByWikiName
Looks up and returns the firstUserProfilein 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 aNoSuchPrincipalException.- Specified by:
findByWikiNamein interfaceUserDatabase- Parameters:
index- the wiki name of the desired user profile- Returns:
- the user profile
- Throws:
NoSuchPrincipalException- See Also:
UserDatabase.findByWikiName(java.lang.String)
-
getPrincipals
Looks up the Principals representing a user from the user database. These are defined as a set of WikiPrincipals manufactured from the login name, full name, and wiki name. If the user database does not contain a user with the supplied identifier, throws a
NoSuchPrincipalException.When this method creates WikiPrincipals, the Principal containing the user's full name is marked as containing the common name (see
WikiPrincipal(String, String)).- Specified by:
getPrincipalsin interfaceUserDatabase- Parameters:
identifier- the name of the principal to retrieve; this corresponds to value returned by the user profile'sUserProfile.getLoginName()method.- Returns:
- the array of Principals representing the user
- Throws:
NoSuchPrincipalException- If the user database does not contain user with the supplied identifier- See Also:
UserDatabase.getPrincipals(java.lang.String)
-
initialize
public abstract void initialize(Engine engine, Properties props) throws NoRequiredPropertyException, WikiSecurityExceptionInitializes the user database based on values from a Properties object.- Specified by:
initializein interfaceUserDatabase- Throws:
NoRequiredPropertyExceptionWikiSecurityException- See Also:
UserDatabase.initialize(org.apache.wiki.api.core.Engine, java.util.Properties)
-
newProfile
Factory method that instantiates a new DefaultUserProfile with a new, distinct unique identifier.- Specified by:
newProfilein interfaceUserDatabase- Returns:
- A new, empty profile.
-
save
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'sUserProfile.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.- Specified by:
savein interfaceUserDatabase- Parameters:
profile- the user profile to save- Throws:
WikiSecurityException- if the profile cannot be saved- See Also:
UserDatabase.save(org.apache.wiki.auth.user.UserProfile)
-
validatePassword
Validates the password for a given user. If the user does not exist in the user database, this method always returnsfalse. If the user exists, the supplied password is compared to the stored password. Note that if the stored password's value starts with{SHA}, the supplied password is hashed prior to the comparison.- Specified by:
validatePasswordin interfaceUserDatabase- Parameters:
loginName- the user's login namepassword- the user's password (obtained from user input, e.g., a web form)- Returns:
trueif the supplied user password matches the stored password- See Also:
UserDatabase.validatePassword(java.lang.String, java.lang.String)
-
generateUid
Generates a new random user identifier (uid) that is guaranteed to be unique.- Parameters:
db- The database for which the UID should be generated.- Returns:
- A random, unique UID.
-
getHash
Private method that calculates the salted SHA-1 hash of a givenString. Note that as of JSPWiki 2.8, this method calculates a salted hash rather than a plain hash.- Parameters:
text- the text to hash- Returns:
- the result hash
-
parseLong
Parses a long integer from a supplied string, or returns 0 if not parsable.- Parameters:
value- the string to parse- Returns:
- the value parsed
-