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());
  }
Exemple #2
0
  /**
   * Deletes a user
   *
   * @param loggedInUser The current user
   * @param login The login for the user you would like to delete
   * @return Returns 1 if successful (exception otherwise)
   * @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 Delete a user.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User login name to delete.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int delete(User loggedInUser, String login) throws FaultException {
    ensureOrgAdmin(loggedInUser);
    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);

    try {
      UserManager.deleteUser(loggedInUser, target.getId());
    } catch (DeleteSatAdminException e) {
      throw new DeleteUserException("user.cannot.delete.last.sat.admin");
    }

    return 1;
  }
  public void testPostProcessValidSession() {
    User user = UserTestUtils.findNewUser("testUser", "testOrg");
    // create a web session indicating a logged in user.
    WebSession s = WebSessionFactory.createSession();
    s.setWebUserId(user.getId());
    assertNotNull(s);
    WebSessionFactory.save(s);
    assertNotNull(s.getId());

    String[] args = {s.getKey()};

    lip.before(new XmlRpcInvocation(10, "handler", "method", null, Arrays.asList(args), writer));
    Object rc =
        lip.after(
            new XmlRpcInvocation(10, "handler", "method", null, Arrays.asList(args), writer),
            "returnthis");
    assertEquals("returnthis", rc);
    assertEquals("", writer.toString());
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    if (CertificateManager.getInstance().isSatelliteCertExpired()) {
      addMessage(request, "satellite.expired");
      request.setAttribute(LoginSetupAction.HAS_EXPIRED, new Boolean(true));
      return mapping.findForward("failure");
    }

    ActionForward ret = null;
    DynaActionForm f = (DynaActionForm) form;

    // Validate the form
    ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, f);
    if (!errors.isEmpty()) {
      performGracePeriodCheck(request);
      addErrors(request, errors);
      return mapping.findForward("failure");
    }
    String username = (String) f.get("username");
    String password = (String) f.get("password");
    String urlBounce = (String) f.get("url_bounce");

    ActionErrors e = new ActionErrors();
    User user = loginUser(username, password, request, response, e);
    RequestContext ctx = new RequestContext(request);

    if (e.isEmpty()) {
      if (urlBounce == null || urlBounce.trim().equals("")) {
        if (log.isDebugEnabled()) {
          log.debug("2 - url bounce is empty using [" + DEFAULT_URL_BOUNCE + "]");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (urlBounce.trim().endsWith("Logout.do")) {
        if (log.isDebugEnabled()) {
          log.debug(" - handling special case of url_bounce=Logout.do");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (user != null) {
        try {
          publishUpdateErrataCacheEvent(user.getOrg());
        } catch (ConstraintViolationException ex) {
          log.error(ex);
          User loggedInUser = ctx.getLoggedInUser();
          if (loggedInUser != null) {
            request.setAttribute("loggedInUser", loggedInUser.getLogin());
          }
          ret = mapping.findForward("error");
          return ret;
        }
      }

      if (log.isDebugEnabled()) {
        log.debug("5 - redirecting to [" + urlBounce + "]");
      }
      if (user != null) {
        pxtDelegate.updateWebUserId(request, response, user.getId());

        try {
          response.sendRedirect(urlBounce);
          return null;
        } catch (IOException ioe) {
          throw new RuntimeException("Exception while trying to redirect: " + ioe);
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug("6 - forwarding to failure");
      }

      performGracePeriodCheck(request);

      addErrors(request, e);
      request.setAttribute("url_bounce", urlBounce);
      ret = mapping.findForward("failure");
    }
    if (log.isDebugEnabled()) {
      log.debug("7 - returning");
    }
    return ret;
  }
 public static void verifyRhnSetData(User user, RhnSetDecl decl, int size)
     throws HibernateException, SQLException {
   verifyRhnSetData(user.getId(), decl.getLabel(), size);
 }