* @see javax.security.auth.spi.LoginModule#login()
*/
public boolean login() throws LoginException {
logger.debug("logging in");
if (callbackHandler == null)
throw new LoginException(
"Error: no CallbackHandler available "
+ "to garner authentication information from the user");
// Setup default callback handlers.
Callback[] callbacks =
new Callback[] {
new NameCallback("Username: "),
new PasswordCallback("Password: ", false)};
try {
callbackHandler.handle(callbacks);
} catch (IOException e) {
throw new LoginException("exception calling back: " + e.toString());
} catch (UnsupportedCallbackException e) {
throw new LoginException("exception calling back: " + e.toString());
}
String username = ((NameCallback) callbacks[0]).getName();
String password =
new String(((PasswordCallback) callbacks[1]).getPassword());
if (username.equals("")) {
//succesfull login of anoynmous user
success = true;
tempPrincipals.add(anonymousUserPrincipal);
return true;
}
//get userInfo and check pwd
try {
Resource userResource = getUserResource(username);
if (userResource == null) {
if (logger.isInfoEnabled()) {
logger.info("No user-resource with shortname "+username+" found");
}
throw new LoginException("Authentication failed: Password does not match");
}
success =
userResource
.getProperty(ACCOUNTMANAGER.passwordSha1)
.getLiteral()
.getString()
.equals(
Util.sha1(password));
if (!success)
throw new LoginException("Authentication failed: Password does not match");
GVSPrincipal newPrincipal = new GVSPrincipal(username, userResource);
tempPrincipals.add(newPrincipal);
} catch (RuntimeException ex) {
logger.error("error handling user info", ex);
throw ex;