Exemplo n.º 1
0
  /**
   * Login the user.
   *
   * @param username, the username.
   * @param password, the password, may not be required (depends on the LoginSettings flags).
   * @return true if the user is successfully logged in.
   */
  public boolean login(String username, String password) {
    Log.debug("UserState.login");

    // perform the login
    try {
      _user = getCache().getUser(username);
      if (_user == null) {
        Log.log(
            User.ERR_USER_NOT_FOUND1.getText()
                + " ["
                + username
                + "] "
                + User.ERR_USER_NOT_FOUND2.getText());
        return false;
      }

      // validate password
      if (getLoginSettings().getFlags(LoginSettings.FLAG_REQUIRE_PASSWORD)) {
        // test the user against the security id
        SecurityId sid = new SecurityId(username, password);
        if (!_user.identityCheck(sid)) {
          _user = null;
          Log.log(User.ERR_INCORRECT_PASSWORD.getText() + " [" + sid.getName() + "]");
        }
      }
    } catch (Exception e) {
      _user = null;
    }
    return (_user != null);
  }