public abstract class AbstractUserDatabase extends Object implements UserDatabase
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log |
protected static String |
SHA_PREFIX |
protected static String |
SSHA_PREFIX |
Constructor and Description |
---|
AbstractUserDatabase() |
Modifier and Type | Method and Description |
---|---|
void |
commit()
Deprecated.
there is no need to call this method because the save, rename and
delete methods contain their own commit logic
|
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. |
abstract 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. |
abstract UserProfile |
findByFullName(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(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(String index)
Looks up and returns the first
UserProfile in the user database
that matches a profile having a given wiki name. |
protected static String |
generateUid(UserDatabase db)
Generates a new random user identifier (uid) that is guaranteed to be unique.
|
protected String |
getHash(String text)
Private method that calculates the salted SHA-1 hash of a given
String . |
protected String |
getOldHash(String text)
Deprecated.
this method is retained for backwards compatibility purposes; use
getHash(String) instead |
Principal[] |
getPrincipals(String identifier)
Looks up the Principals representing a user from the user database.
|
abstract 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 DefaultUserProfile with a new, distinct
unique identifier.
|
protected long |
parseLong(String value)
Parses a long integer from a supplied string, or returns 0 if not parsable.
|
abstract void |
save(UserProfile profile)
Saves a
UserProfile to the user database, overwriting the
existing profile if it exists. |
boolean |
validatePassword(String loginName,
String password)
Validates the password for a given user.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
deleteByLoginName, findByUid, getWikiNames, rename
protected static final org.apache.log4j.Logger log
protected static final String SHA_PREFIX
protected static final String SSHA_PREFIX
public AbstractUserDatabase()
public void commit() throws WikiSecurityException
UserDatabase.rename(String, String)
,
save(UserProfile)
and UserDatabase.deleteByLoginName(String)
methods
are atomic themselves.commit
in interface UserDatabase
WikiSecurityException
public UserProfile find(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 UserDatabase
index
- the login name, full name, or wiki nameNoSuchPrincipalException
UserDatabase.find(java.lang.String)
public abstract UserProfile findByEmail(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 UserDatabase
index
- the e-mail address of the desired user profileNoSuchPrincipalException
UserDatabase.findByEmail(java.lang.String)
public abstract UserProfile findByFullName(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 UserDatabase
index
- the fill name of the desired user profileNoSuchPrincipalException
UserDatabase.findByFullName(java.lang.String)
public abstract UserProfile findByLoginName(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 UserDatabase
index
- the login name of the desired user profileNoSuchPrincipalException
UserDatabase.findByLoginName(java.lang.String)
public abstract UserProfile findByWikiName(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 UserDatabase
index
- the wiki name of the desired user profileNoSuchPrincipalException
UserDatabase.findByWikiName(java.lang.String)
public Principal[] getPrincipals(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 UserDatabase
identifier
- the name of the principal to retrieve; this corresponds to
value returned by the user profile's
UserProfile.getLoginName()
method.NoSuchPrincipalException
UserDatabase.getPrincipals(java.lang.String)
public abstract void initialize(WikiEngine engine, Properties props) throws NoRequiredPropertyException, WikiSecurityException
initialize
in interface UserDatabase
NoRequiredPropertyException
WikiSecurityException
UserDatabase.initialize(org.apache.wiki.WikiEngine, java.util.Properties)
public UserProfile newProfile()
newProfile
in interface UserDatabase
public abstract void save(UserProfile profile) throws WikiSecurityException
Saves a UserProfile
to 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 UserDatabase
profile
- the user profile to saveWikiSecurityException
- if the profile cannot be savedUserDatabase.save(org.apache.wiki.auth.user.UserProfile)
public boolean validatePassword(String loginName, 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 UserDatabase
loginName
- 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 String generateUid(UserDatabase db)
db
- The database for which the UID should be generated.protected String getHash(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 String getOldHash(String text)
getHash(String)
insteadString
text
- the text to hashCopyright © 2001-2018 The Apache Software Foundation. All rights reserved.