* Verifies that the user datbase was initialized properly, and that
* user add and delete operations work as they should.
*/
protected void verifyUserDatabase()
{
UserDatabase db = m_engine.getUserManager().getUserDatabase();
// Check for obvious error conditions
if ( db == null )
{
m_session.addMessage( ERROR_DB, "UserDatabase is null; JSPWiki could not " +
"initialize it. Check the error logs." );
return;
}
if ( db instanceof UserManager.DummyUserDatabase )
{
m_session.addMessage( ERROR_DB, "UserDatabase is DummyUserDatabase; JSPWiki " +
"may not have been able to initialize the database you supplied in " +
"jspwiki.properties, or you left the 'jspwiki.userdatabase' property " +
"blank. Check the error logs." );
}
// Tell user what class of database this is.
m_session.addMessage( INFO_DB, "UserDatabase is of type '" + db.getClass().getName() +
"'. It appears to be initialized properly." );
// Now, see how many users we have.
int oldUserCount = 0;
try
{
Principal[] users = db.getWikiNames();
oldUserCount = users.length;
m_session.addMessage( INFO_DB, "The user database contains " + oldUserCount + " users." );
}
catch ( WikiSecurityException e )
{
m_session.addMessage( ERROR_DB, "Could not obtain a list of current users: " + e.getMessage() );
return;
}
// Try adding a bogus user with random name
String loginName = "TestUser" + System.currentTimeMillis();
try
{
UserProfile profile = db.newProfile();
profile.setEmail( "jspwiki.tests@mailinator.com" );
profile.setLoginName( loginName );
profile.setFullname( "FullName"+loginName );
profile.setPassword( "password" );
db.save(profile);
// Make sure the profile saved successfully
if ( db.getWikiNames().length == oldUserCount )
{
m_session.addMessage( ERROR_DB, "Could not add a test user to the database." );
return;
}
m_session.addMessage( INFO_DB, "The user database allows new users to be created, as it should." );
}
catch ( WikiSecurityException e )
{
m_session.addMessage( ERROR_DB, "Could not add a test user to the database: " + e.getMessage() );
return;
}
// Now delete the profile; should be back to old count
try
{
db.deleteByLoginName( loginName );
if ( db.getWikiNames().length != oldUserCount )
{
m_session.addMessage( ERROR_DB, "Could not delete a test user from the database." );
return;
}
m_session.addMessage( INFO_DB, "The user database allows users to be deleted, as it should." );