public abstract class AbstractUserDatabase extends java.lang.Object implements UserDatabase
| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.logging.log4j.Logger |
LOG |
protected static java.lang.String |
SHA_PREFIX |
protected static java.lang.String |
SHA256_PREFIX |
protected static java.lang.String |
SSHA_PREFIX |
| Constructor and Description |
|---|
AbstractUserDatabase() |
| Modifier and Type | Method and Description |
|---|---|
UserProfile |
find(java.lang.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. |
abstract UserProfile |
findByEmail(java.lang.String index)
Looks up and returns the first
UserProfile in the user database that matches a profile having a given e-mail address. |
abstract UserProfile |
findByFullName(java.lang.String index)
Looks up and returns the first
UserProfile in the user database that matches a profile having a given full name. |
abstract UserProfile |
findByLoginName(java.lang.String index)
Looks up and returns the first
UserProfile in the user database that matches a profile having a given login name. |
abstract UserProfile |
findByWikiName(java.lang.String index)
Looks up and returns the first
UserProfile in the user database that matches a profile having a given wiki name. |
protected static java.lang.String |
generateUid(UserDatabase db)
Generates a new random user identifier (uid) that is guaranteed to be unique.
|
protected java.lang.String |
getHash(java.lang.String text)
Private method that calculates the salted SHA-1 or SHA-256 hash of a given
String. |
java.security.Principal[] |
getPrincipals(java.lang.String identifier)
Looks up the Principals representing a user from the user database.
|
abstract void |
initialize(Engine engine,
java.util.Properties props)
Initializes the user database based on values from a Properties object.
|
UserProfile |
newProfile()
Factory method that instantiates a new DefaultUserProfile with a new, distinct unique identifier.
|
protected long |
parseLong(java.lang.String value)
Parses a long integer from a supplied string, or returns 0 if not parsable.
|
abstract void |
save(UserProfile profile)
Saves a
UserProfileto the user database, overwriting the existing profile if it exists. |
boolean |
validatePassword(java.lang.String loginName,
java.lang.String password)
Validates the password for a given user.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdeleteByLoginName, findByUid, getWikiNames, renameprotected static final org.apache.logging.log4j.Logger LOG
protected static final java.lang.String SHA_PREFIX
protected static final java.lang.String SSHA_PREFIX
protected static final java.lang.String SHA256_PREFIX
public AbstractUserDatabase()
public UserProfile find(java.lang.String index) throws NoSuchPrincipalException
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.find in interface UserDatabaseindex - the login name, full name, or wiki nameNoSuchPrincipalExceptionUserDatabase.find(java.lang.String)public abstract UserProfile findByEmail(java.lang.String index) throws NoSuchPrincipalException
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.findByEmail in interface UserDatabaseindex - the e-mail address of the desired user profileNoSuchPrincipalExceptionUserDatabase.findByEmail(java.lang.String)public abstract UserProfile findByFullName(java.lang.String index) throws NoSuchPrincipalException
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.findByFullName in interface UserDatabaseindex - the fill name of the desired user profileNoSuchPrincipalExceptionUserDatabase.findByFullName(java.lang.String)public abstract UserProfile findByLoginName(java.lang.String index) throws NoSuchPrincipalException
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.findByLoginName in interface UserDatabaseindex - the login name of the desired user profileNoSuchPrincipalExceptionUserDatabase.findByLoginName(java.lang.String)public abstract UserProfile findByWikiName(java.lang.String index) throws NoSuchPrincipalException
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.findByWikiName in interface UserDatabaseindex - the wiki name of the desired user profileNoSuchPrincipalExceptionUserDatabase.findByWikiName(java.lang.String)public java.security.Principal[] getPrincipals(java.lang.String identifier) throws NoSuchPrincipalException
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.WikiPrincipal(String, String)).
getPrincipals in interface UserDatabaseidentifier - the name of the principal to retrieve; this corresponds to
value returned by the user profile's
UserProfile.getLoginName()method.NoSuchPrincipalException - If the user database does not contain user with the supplied identifierUserDatabase.getPrincipals(java.lang.String)public abstract void initialize(Engine engine, java.util.Properties props) throws NoRequiredPropertyException, WikiSecurityException
initialize in interface UserDatabaseNoRequiredPropertyExceptionWikiSecurityExceptionUserDatabase.initialize(org.apache.wiki.api.core.Engine, java.util.Properties)public UserProfile newProfile()
newProfile in interface UserDatabasepublic abstract 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.
save in interface UserDatabaseprofile - the user profile to saveWikiSecurityException - if the profile cannot be savedUserDatabase.save(org.apache.wiki.auth.user.UserProfile)public boolean validatePassword(java.lang.String loginName, java.lang.String password)
false. 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.validatePassword in interface UserDatabaseloginName - the user's login namepassword - the user's password (obtained from user input, e.g., a web form)true if the supplied user password matches the stored passwordUserDatabase.validatePassword(java.lang.String, java.lang.String)protected static java.lang.String generateUid(UserDatabase db)
db - The database for which the UID should be generated.protected java.lang.String getHash(java.lang.String text)
String. Note that as of JSPWiki 2.8, this method
calculates a salted hash rather than a plain hash.text - the text to hashprotected long parseLong(java.lang.String value)
value - the string to parseCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.