use of org.apache.wiki.auth.user.UserDatabase in project jspwiki by apache.
the class UserDatabaseLoginModule method login.
/**
* @see javax.security.auth.spi.LoginModule#login()
*
* {@inheritDoc}
*/
public boolean login() throws LoginException {
UserDatabaseCallback ucb = new UserDatabaseCallback();
NameCallback ncb = new NameCallback("User name");
PasswordCallback pcb = new PasswordCallback("Password", false);
Callback[] callbacks = new Callback[] { ucb, ncb, pcb };
try {
m_handler.handle(callbacks);
UserDatabase db = ucb.getUserDatabase();
String username = ncb.getName();
String password = new String(pcb.getPassword());
// Look up the user and compare the password hash
if (db == null) {
throw new FailedLoginException("No user database: check the callback handler code!");
}
UserProfile profile = db.findByLoginName(username);
String storedPassword = profile.getPassword();
if (storedPassword != null && db.validatePassword(username, password)) {
if (log.isDebugEnabled()) {
log.debug("Logged in user database user " + username);
}
// If login succeeds, commit these principals/roles
m_principals.add(new WikiPrincipal(username, WikiPrincipal.LOGIN_NAME));
return true;
}
throw new FailedLoginException("The username or password is incorrect.");
} catch (IOException e) {
String message = "IO exception; disallowing login.";
log.error(message, e);
throw new LoginException(message);
} catch (UnsupportedCallbackException e) {
String message = "Unable to handle callback; disallowing login.";
log.error(message, e);
throw new LoginException(message);
} catch (NoSuchPrincipalException e) {
throw new FailedLoginException("The username or password is incorrect.");
}
}
use of org.apache.wiki.auth.user.UserDatabase in project jspwiki by apache.
the class Installer method adminExists.
/**
* Returns <code>true</code> if the administrative user had
* been created previously.
* @return the result
*/
public boolean adminExists() {
// See if the admin user exists already
UserManager userMgr = m_engine.getUserManager();
UserDatabase userDb = userMgr.getUserDatabase();
try {
userDb.findByLoginName(ADMIN_ID);
return true;
} catch (NoSuchPrincipalException e) {
return false;
}
}
Aggregations