示例#1
0
  /**
   * Gets details for a given user. These details include first names, last name, email, prefix,
   * last login date, and created on date.
   *
   * @param loggedInUser The current user
   * @param login The login for the user you want the details for
   * @return Returns a Map containing the details for the given user.
   * @throws FaultException A FaultException is thrown if the user doesn't have access to lookup the
   *     user corresponding to login or if the user does not exist.
   * @xmlrpc.doc Returns the details about a given user.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.returntype #struct("user details") #prop_desc("string", "first_names", "deprecated, use
   *     first_name") #prop("string", "first_name") #prop("string", "last_name") #prop("string",
   *     "email") #prop("int", "org_id") #prop("string", "org_name") #prop("string", "prefix")
   *     #prop("string", "last_login_date") #prop("string", "created_date") #prop_desc("boolean",
   *     "enabled", "true if user is enabled, false if the user is disabled") #prop_desc("boolean",
   *     "use_pam", "true if user is configured to use PAM authentication") #struct_end()
   */
  public Map getDetails(User loggedInUser, String login) throws FaultException {
    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
    LocalizationService ls = LocalizationService.getInstance();

    Map ret = new HashMap();
    ret.put("first_names", StringUtils.defaultString(target.getFirstNames()));
    ret.put("first_name", StringUtils.defaultString(target.getFirstNames()));
    ret.put("last_name", StringUtils.defaultString(target.getLastName()));
    ret.put("email", StringUtils.defaultString(target.getEmail()));
    ret.put("prefix", StringUtils.defaultString(target.getPrefix()));

    // Last login date
    String lastLoggedIn =
        target.getLastLoggedIn() == null ? "" : ls.formatDate(target.getLastLoggedIn());
    ret.put("last_login_date", lastLoggedIn);

    // Created date
    String created = target.getCreated() == null ? "" : ls.formatDate(target.getCreated());
    ret.put("created_date", created);
    ret.put("org_id", loggedInUser.getOrg().getId());
    ret.put("org_name", loggedInUser.getOrg().getName());

    if (target.isDisabled()) {
      ret.put("enabled", Boolean.FALSE);
    } else {
      ret.put("enabled", Boolean.TRUE);
    }
    ret.put("use_pam", target.getUsePamAuthentication());

    return ret;
  }
  private void setupExpectations(RhnMockDynaActionForm form, User user) {

    form.addExpectedProperty("uid", user.getId());
    form.addExpectedProperty("firstNames", user.getFirstNames());
    form.addExpectedProperty("lastName", user.getLastName());
    form.addExpectedProperty("title", user.getTitle());
    form.addExpectedProperty("prefix", user.getPrefix());
  }