/**
   * @see javax.security.auth.spi.LoginModule#login()
   * @return true if is authenticated, false otherwise
   * @throws LoginException
   */
  public boolean login() throws LoginException {
    try {
      if (callbackHandler == null) throw new LoginException("No callback handler");

      Callback[] callbacks = configureCallbacks();
      callbackHandler.handle(callbacks);

      String webUserName = ((NameCallback) callbacks[0]).getName();
      Object webCredential = null;

      webCredential =
          ((ObjectCallback) callbacks[1])
              .getObject(); // first check if ObjectCallback has the credential
      if (webCredential == null)
        webCredential =
            ((PasswordCallback) callbacks[2]).getPassword(); // use standard PasswordCallback

      if ((webUserName == null) || (webCredential == null)) {
        setAuthenticated(false);
        return isAuthenticated();
      }

      UserInfo userInfo = getUserInfo(webUserName);

      if (userInfo == null) {
        setAuthenticated(false);
        return isAuthenticated();
      }

      currentUser = new JAASUserInfo(userInfo);
      setAuthenticated(currentUser.checkCredential(webCredential));
      return isAuthenticated();
    } catch (IOException e) {
      throw new LoginException(e.toString());
    } catch (UnsupportedCallbackException e) {
      throw new LoginException(e.toString());
    } catch (Exception e) {
      e.printStackTrace();
      throw new LoginException(e.toString());
    }
  }