Esempio 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);
  }
Esempio n. 2
0
  /**
   * Logout the user. Inform all message servers that we're saying goodbye. & release license lock
   */
  public void logout() {
    Iterator it = _msgServers.iterator();
    while (it.hasNext()) {
      MessageServer msgServer = (MessageServer) it.next();
      DataSource ds = msgServer.createImpl();

      ActionDobj actLogout = new ActionDobj(ActionDobj.AT_LOGOUT, "logout", ds.getName());
      try {
        actLogout.doActionQuery(ds, _sessionId, _user.getId());

      } catch (DataSourceException e) {
      }
    }
    LicenseManager.releaseLicenseLock(lockKey);
  }
Esempio n. 3
0
  /**
   * @return the currently selected menu. If there is no valid current selection then the main menu
   *     is returned.
   */
  public MenuAction getCurrentMenu() {
    assert _user != null;

    if (_currentMenu == null) {
      if (_rootMenu == null) {
        // no mainmenu yet, construct the main menu object and then load
        // base menu items for group (s)
        _rootMenu = new Submenu("Main Menu", "Main Menu", null, null);

        try {
          // find the groups the user is a member of
          boolean isFirst = true;
          Vector gmems = _user.getGroupMemberships();
          for (int i = 0; gmems != null && i < gmems.size(); i++) {
            GroupMembership gm = (GroupMembership) gmems.elementAt(i);
            if (gm != null) {
              // add a spaced between multiple group menus
              if (isFirst) isFirst = false;
              else ; // _rootMenu.addChildAtEnd (new TextAction ());

              // get the group menu
              Vector v = getCache().getGroupMenus(new Integer(gm.getGroupId()));

              // add the group menu items to main menu
              for (int j = 0; v != null && j < v.size(); j++)
                _rootMenu.addChildAtEnd((MenuAction) v.get(j));
            }
          }
        } catch (DataSourceException e) {
          Log.error("UserState.getMenu: " + e.toString());
        }

        // add the logout entry
        _rootMenu.addChildAtEnd(new LogoutAction());
      }

      _currentMenu = _rootMenu;
    }

    return _currentMenu;
  }