}
@Override
public void authenticate(String username, final String password,
final AsyncCallback<LoginResult> callback) {
LoginResult result = new LoginResult(authType);
if (username == null || "".equals(username.trim()) //
|| password == null || "".equals(password)) {
result.setError(LoginResult.Error.INVALID_LOGIN);
callback.onSuccess(result);
return;
}
username = username.trim();
final AuthRequest req = AuthRequest.forUser(username);
req.setPassword(password);
final AuthResult res;
try {
res = accountManager.authenticate(req);
} catch (AccountUserNameException e) {
// entered user name and password were correct, but user name could not be
// set for the newly created account and this is why the login fails,
// error screen with error message should be shown to the user
callback.onFailure(e);
return;
} catch (AuthenticationUnavailableException e) {
result.setError(LoginResult.Error.AUTHENTICATION_UNAVAILABLE);
callback.onSuccess(result);
return;
} catch (AccountException e) {
log.info(String.format("'%s' failed to sign in: %s", username, e.getMessage()));
result.setError(LoginResult.Error.INVALID_LOGIN);
callback.onSuccess(result);
return;
}
result.success = true;