Example #1
0
  public void testDisabledUser() {
    LoginAction action = new LoginAction();
    User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName());
    UserManager.disableUser(u, u);

    ActionMapping mapping = new ActionMapping();
    mapping.addForwardConfig(new ActionForward("failure", "path", false));
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    request.setSession(new MockHttpSession());
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    form.set("username", u.getLogin());
    /**
     * Since we know testUser's password is "password", just set that here. using u.getPassword()
     * will fail when we're using encrypted passwords.
     */
    form.set("password", "password");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertEquals("failure", rc.getName());
  }
Example #2
0
  /**
   * Wrap a call to loginUserIntoSessionTest since we want that method to return a value and JUnit
   * only calls methods with void return types
   *
   * @throws Exception
   */
  public void testPerformValidUsername() throws Exception {
    HttpServletRequest request = loginUserIntoSessionTest();
    RequestContext requestContext = new RequestContext(request);

    assertNotNull(
        IntegrationService.get().getAuthToken(requestContext.getCurrentUser().getLogin()));
  }
  /**
   * Applies the selected errata
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward applyErrata(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    Map<String, Object> params = new HashMap<String, Object>();

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();
    // if they chose errata, send them to the confirmation page
    Long sid = requestContext.getParamAsLong("sid");

    User user = requestContext.getCurrentUser();
    RhnSet set = getSetDecl(sid).get(user);

    // if they chose no errata, return to the same page with a message
    if (set.isEmpty()) {
      ActionMessages msg = new ActionMessages();
      msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errata.applynone"));
      params = makeParamMap(formIn, request);
      strutsDelegate.saveMessages(request, msg);
      return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
    }

    if (sid != null) {
      params.put("sid", sid);
    }

    return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
  }
  /**
   * The second step in the wizard
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runSecond(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {
    log.debug("runSecond");

    if (!StringUtils.isBlank(form.getString(HIDDEN_BOND_SLAVE_INTERFACES))) {
      form.set(BOND_SLAVE_INTERFACES, form.getString(HIDDEN_BOND_SLAVE_INTERFACES).split(","));
    }

    Long sid = (Long) form.get(RequestContext.SID);
    User user = ctx.getCurrentUser();

    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    KickstartScheduleCommand cmd = getScheduleCommand(form, ctx, null, null);

    checkForKickstart(form, cmd, ctx);
    addRequestAttributes(ctx, cmd, form);
    if (!cmd.isCobblerOnly()) {
      List packageProfiles = cmd.getProfiles();
      form.set(SYNCH_PACKAGES, packageProfiles);
      List systemProfiles = cmd.getCompatibleSystems();
      form.set(SYNCH_SYSTEMS, systemProfiles);

      // Disable the package/system sync radio buttons if no profiles are
      // available:
      String syncPackageDisabled = "false";
      if (packageProfiles.size() == 0) {
        syncPackageDisabled = "true";
      }
      String syncSystemDisabled = "false";
      if (systemProfiles.size() == 0) {
        syncSystemDisabled = "true";
      }
      ctx.getRequest().setAttribute(SYNC_PACKAGE_DISABED, syncPackageDisabled);
      ctx.getRequest().setAttribute(SYNC_SYSTEM_DISABLED, syncSystemDisabled);

      if (StringUtils.isEmpty(form.getString(TARGET_PROFILE_TYPE))) {
        form.set(TARGET_PROFILE_TYPE, KickstartScheduleCommand.TARGET_PROFILE_TYPE_NONE);
      }
    } else {
      ctx.getRequest().setAttribute(COBBLER_ONLY_PROFILE, Boolean.TRUE);
    }

    if (StringUtils.isEmpty(form.getString(KERNEL_PARAMS_TYPE))) {
      form.set(KERNEL_PARAMS_TYPE, KERNEL_PARAMS_DISTRO);
    }

    if (StringUtils.isEmpty(form.getString(POST_KERNEL_PARAMS_TYPE))) {
      form.set(POST_KERNEL_PARAMS_TYPE, KERNEL_PARAMS_DISTRO);
    }

    SdcHelper.ssmCheck(ctx.getRequest(), sid, user);
    return mapping.findForward("second");
  }
 /** {@inheritDoc} */
 protected DataResult getDataResult(RequestContext requestContext, ListControl lc) {
   User user = requestContext.getCurrentUser();
   DataResult dr =
       ChannelManager.popularChannelTree(
           user, (Long) requestContext.getRequest().getAttribute("count"), lc);
   return dr;
 }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext rc = new RequestContext(request);
    User user = rc.getLoggedInUser();

    Channel chan = ChannelManager.lookupByIdAndUser(rc.getRequiredParam(RequestContext.CID), user);

    try {
      ChannelManager.verifyChannelAdmin(user, chan.getId());
    } catch (InvalidChannelRoleException e) {
      addMessage(request, e.getMessage());
      return mapping.findForward("default");
    }

    ListRhnSetHelper helper =
        new ListRhnSetHelper(this, request, RhnSetDecl.ERRATA_TO_SYNC.createCustom(chan.getId()));

    helper.execute();
    if (helper.isDispatched()) {
      Map params = new HashMap();
      params.put(RequestContext.CID, chan.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
    }

    request.setAttribute("channel_name", chan.getName());
    request.setAttribute(RequestContext.CID, chan.getId());
    return mapping.findForward("default");
  }
Example #7
0
  private void setPageSize() {
    int tmp = -1;
    RequestContext rctx = new RequestContext((HttpServletRequest) pageContext.getRequest());
    User user = rctx.getLoggedInUser();
    if (user != null) {
      tmp = user.getPageSize();
      if (tmp > 0) {
        pageSize = tmp;
      }
    }
    if (pageSize < 1) {
      pageSize = 10;
    }

    HttpServletRequest httpRequest = (HttpServletRequest) pageContext.getRequest();

    if (PageSizeDecorator.pageWidgetSelected(httpRequest, getUniqueName())) {
      int size = PageSizeDecorator.getSelectedPageSize(httpRequest, getUniqueName());
      List<Integer> pageSizes = PageSizeDecorator.getPageSizes();
      if (size < 1 || size > pageSizes.get(pageSizes.size() - 1)) {
        return;
      } else {
        pageSize = size;
      }
    }
  }
  /** {@inheritDoc} */
  public List getResult(RequestContext context) {
    User user = context.getLoggedInUser();
    Channel chan =
        ChannelManager.lookupByIdAndUser(context.getRequiredParam(RequestContext.CID), user);

    return ChannelManager.listErrataNeedingResync(chan, user);
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward handleDispatch(
      ListSessionSetHelper helper,
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext context = new RequestContext(request);
    ActivationKey key = context.lookupAndBindActivationKey();
    ConfigChannelListProcessor proc = new ConfigChannelListProcessor();
    Set<String> set = helper.getSet();

    for (String id : set) {
      Long ccid = Long.valueOf(id);
      ConfigChannel cc = ConfigurationFactory.lookupConfigChannelById(ccid);
      proc.remove(key.getConfigChannelsFor(context.getCurrentUser()), cc);
    }
    getStrutsDelegate()
        .saveMessage(
            "config_channels_to_unsubscribe.unsubscribe.success",
            new String[] {String.valueOf(set.size())},
            request);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(RequestContext.TOKEN_ID, key.getToken().getId().toString());
    StrutsDelegate strutsDelegate = getStrutsDelegate();
    return strutsDelegate.forwardParams(mapping.findForward("success"), params);
  }
Example #10
0
  /**
   * In this test we actually return an HttpServletRequest so this code can be reused by other tests
   * to Login a user and get the Request (with session) that appears logged in. In order for this
   * test to be executed by JUnit we have to wrap its call in the above method with a void return
   * type.
   *
   * @throws Exception
   */
  public HttpServletRequest loginUserIntoSessionTest() throws Exception {
    LoginAction action = new LoginAction();
    User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName());
    ActionMapping mapping = new ActionMapping();
    mapping.addForwardConfig(new ActionForward("loggedin", "path", false));
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    MockHttpSession mockSession = new MockHttpSession();
    mockSession.setupGetAttribute("url_bounce", null);
    mockSession.setupGetAttribute("request_method", "GET");
    request.setSession(mockSession);
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    form.set("username", u.getLogin());
    /**
     * Since we know testUser's password is "password", just set that here. using u.getPassword()
     * will fail when we're using encrypted passwords.
     */
    form.set("password", "password");
    form.set("request_method", "POST");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertNull(rc);
    return request;
  }
Example #11
0
  public void testPerformNoPasswordName() {

    LoginAction action = new LoginAction();

    ActionMapping mapping = new ActionMapping();
    ActionForward failure = new ActionForward("failure", "path", false);
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    request.setSession(new MockHttpSession());
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    mapping.addForwardConfig(failure);
    form.set("username", "someusername");
    form.set("password", "");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertEquals(rc, failure);
  }
 /** {@inheritDoc} */
 protected void processParamMap(ActionForm formIn, HttpServletRequest request, Map params) {
   RequestContext requestContext = new RequestContext(request);
   Long sid = requestContext.getRequiredParam("sid");
   params.put("sid", sid);
   getStrutsDelegate()
       .rememberDatePicker(
           params, (DynaActionForm) formIn, "date", DatePicker.YEAR_RANGE_POSITIVE);
 }
Example #13
0
  private Channel makePrivate(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User user = ctx.getCurrentUser();
    Long cid = ctx.getParamAsLong("cid");
    Channel channel = ChannelFactory.lookupById(cid);
    unsubscribeOrgsFromChannel(user, channel, Channel.PRIVATE);
    return edit(form, errors, ctx);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    User user = requestContext.getCurrentUser();

    Errata errata = requestContext.lookupErratum();
    DataResult dr = ErrataManager.systemsAffected(user, errata.getId(), null);

    RhnSet set = RhnSetDecl.SYSTEMS_AFFECTED.get(user);
    RhnListSetHelper helper = new RhnListSetHelper(request);

    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!requestContext.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    if (request.getParameter(DISPATCH) != null) {
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        // Send to AffectedSystemsAction to handle submit
        return strutsDelegate.forwardParams(
            mapping.findForward("confirm"), request.getParameterMap());
      }
      RhnHelper.handleEmptySelection(request);
    }

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dr);
    }

    // if I have a previous set selections populate data using it
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    TagHelper.bindElaboratorTo("systemAffectedList", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo(LIST_NAME, RhnSetDecl.SYSTEMS_AFFECTED, request);

    request.setAttribute(RequestContext.PAGE_LIST, dr);
    request.setAttribute("set", set);
    request.setAttribute("errata", errata);
    request.setAttribute(
        ListTagHelper.PARENT_URL,
        request.getRequestURI() + "?" + RequestContext.ERRATA_ID + "=" + errata.getId());

    return strutsDelegate.forwardParams(
        mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);

    if (request.getParameter("dispatch") != null) {
      if (requestContext.wasDispatched("installconfirm.jsp.confirm")) {
        return executePackageAction(mapping, formIn, request, response);
      }
    }

    List<PackageListItem> items = getDataResult(request);

    Server server = requestContext.lookupAndBindServer();

    /*
     * If we are removing a package that is not in a channel the server is
     *  subscribed to, then the rollback will not work, lets give the user
     *  a message telling them that.
     */
    if (this instanceof RemoveConfirmSetupAction
        && server.hasEntitlement(EntitlementManager.PROVISIONING)) {
      for (PackageListItem item : items) {
        Map<String, Long> map = item.getKeyMap();
        if (!SystemManager.hasPackageAvailable(
            server, map.get("name_id"), map.get("arch_id"), map.get("evr_id"))) {
          ActionMessages msgs = new ActionMessages();
          msgs.add(
              ActionMessages.GLOBAL_MESSAGE, new ActionMessage("package.remove.cant.rollback"));
          getStrutsDelegate().saveMessages(request, msgs);
          break;
        }
      }
    }

    DynaActionForm dynaForm = (DynaActionForm) formIn;
    DatePicker picker =
        getStrutsDelegate()
            .prepopulateDatePicker(request, dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);
    request.setAttribute("date", picker);

    ActionChainHelper.prepopulateActionChains(request);

    request.setAttribute("system", server);
    requestContext.copyParamToAttributes(RequestContext.SID);
    request.setAttribute(
        ListTagHelper.PARENT_URL, request.getRequestURI() + "?sid=" + server.getId());
    request.setAttribute(WIDGET_SUMMARY, getWidgetSummary());
    request.setAttribute(HEADER_KEY, getHeaderKey());
    request.setAttribute(DATA_SET, items);

    return getStrutsDelegate()
        .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
  }
Example #16
0
  private Channel edit(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User loggedInUser = ctx.getCurrentUser();
    Channel updated = null;

    // handle submission
    // why can't I just pass in a dictionary? sigh, there are
    // times where python would make this SOOOO much easier.
    UpdateChannelCommand ucc = new UpdateChannelCommand();
    ucc.setArchLabel((String) form.get("arch"));
    ucc.setChecksumLabel((String) form.get("checksum"));
    ucc.setLabel((String) form.get("label"));
    ucc.setName((String) form.get("name"));
    ucc.setSummary((String) form.get("summary"));
    ucc.setDescription((String) form.get("description"));
    ucc.setUser(loggedInUser);
    ucc.setGpgKeyId((String) form.get("gpg_key_id"));
    ucc.setGpgKeyUrl((String) form.get("gpg_key_url"));
    ucc.setGpgKeyFp((String) form.get("gpg_key_fingerprint"));
    ucc.setMaintainerName((String) form.get("maintainer_name"));
    ucc.setMaintainerEmail((String) form.get("maintainer_email"));
    ucc.setMaintainerPhone((String) form.get("maintainer_phone"));
    ucc.setSupportPolicy((String) form.get("support_policy"));
    ucc.setAccess((String) form.get("org_sharing"));

    String parent = (String) form.get("parent");
    if (parent == null || parent.equals("")) {
      ucc.setParentId(null);
    } else {
      ucc.setParentId(Long.valueOf(parent));
    }

    try {
      updated = ucc.update(ctx.getParamAsLong("cid"));
      String sharing = (String) form.get("per_user_subscriptions");
      updated.setGloballySubscribable(
          (sharing != null) && ("all".equals(sharing)), loggedInUser.getOrg());
      updated = (Channel) ChannelFactory.reload(updated);
    } catch (InvalidGPGFingerprintException borg) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgfp"));
    } catch (InvalidGPGKeyException dukat) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgkey"));
    } catch (InvalidGPGUrlException khan) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgurl"));
    } catch (InvalidChannelNameException ferengi) {
      handleChannelNameException(errors, ferengi);

    } catch (InvalidChannelLabelException q) {
      handleChannelLabelException(errors, q);

    } catch (IllegalArgumentException iae) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(iae.getMessage()));
    }

    return updated;
  }
  /**
   * Parses the kernel options or Post kernel options from the given form. Called after the advanced
   * options page is typically set.. This is a handy method used in both SSM and SDC KS scheduling.
   *
   * @param form the kickstartScheduleWizardForm that holds the form fields.
   * @param request the servlet request
   * @param profileCobblerId the cobbler profile id
   * @param isPost true if caller is interested in getting the post kernel options and not the pre.
   * @return the kernel options selected by the user.
   */
  public static String parseKernelOptions(
      DynaActionForm form, HttpServletRequest request, String profileCobblerId, boolean isPost) {
    RequestContext context = new RequestContext(request);
    String typeKey = !isPost ? KERNEL_PARAMS_TYPE : POST_KERNEL_PARAMS_TYPE;
    String customKey = !isPost ? KERNEL_PARAMS : POST_KERNEL_PARAMS;
    String type = form.getString(typeKey);

    return parseKernelOptions(
        form.getString(customKey), type, profileCobblerId, isPost, context.getCurrentUser());
  }
Example #18
0
  /**
   * Makes a parameter map containing request params that need to be forwarded on to the success
   * mapping.
   *
   * @param request HttpServletRequest containing request vars
   * @return Returns Map of parameters TODO: was private
   */
  protected Map makeParamMap(ActionForm form, HttpServletRequest request) {

    RequestContext rctx = new RequestContext(request);
    Map params = rctx.makeParamMapWithPagination();
    Long sid = new RequestContext(request).getParamAsLong("sid");
    if (sid != null) {
      params.put("sid", sid);
    }
    return params;
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();

    long cid = context.getRequiredParam("cid");
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    request.setAttribute("channel_name", chan.getName());
    request.setAttribute("cid", chan.getId());

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(RequestContext.CID, chan.getId().toString());

    ListSessionSetHelper helper = new ListSessionSetHelper(this, request, params);

    if (!context.isSubmitted()) {
      List<ContentSource> result = getResult(context);
      Set<String> preSelect = new HashSet<String>();
      for (int i = 0; i < result.size(); i++) {
        ContentSource src = result.get(i);
        if (src.getChannels().contains(chan)) {
          preSelect.add(src.getId().toString());
        }
      }
      helper.preSelect(preSelect);
    }

    helper.ignoreEmptySelection();
    helper.execute();

    if (helper.isDispatched()) {
      Set<ContentSource> foo = chan.getSources();
      foo.clear();
      Set<String> set = helper.getSet();
      for (String id : set) {
        Long sgid = Long.valueOf(id);
        ContentSource tmp = ChannelFactory.lookupContentSource(sgid, user.getOrg());
        foo.add(tmp);
      }

      ChannelFactory.save(chan);

      StrutsDelegate strutsDelegate = getStrutsDelegate();
      strutsDelegate.saveMessage(
          "channel.edit.repo.updated", new String[] {chan.getName()}, request);

      return strutsDelegate.forwardParams(mapping.findForward("success"), params);
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
 /**
  * @param mapping ActionMapping
  * @param formIn ActionForm
  * @param request ServletRequest
  * @param response ServletResponse
  * @return The ActionForward to go to next.
  */
 public ActionForward processUnsubscribe(
     ActionMapping mapping,
     ActionForm formIn,
     HttpServletRequest request,
     HttpServletResponse response) {
   Map params = makeParamMap(formIn, request);
   operateOnSelectedSet(mapping, formIn, request, response, "unsubscribeSystems");
   RequestContext requestContext = new RequestContext(request);
   ConfigActionHelper.clearRhnSets(requestContext.getCurrentUser());
   return getStrutsDelegate().forwardParams(mapping.findForward("success"), params);
 }
 /**
  * {@inheritDoc}
  *
  * @throws Exception sometimes things just don't work out
  */
 public String renderAsync() throws Exception {
   WebContext ctx = WebContextFactory.get();
   HttpServletRequest req = ctx.getHttpServletRequest();
   RequestContext rhnCtx = new RequestContext(req);
   User user = rhnCtx.getCurrentUser();
   PageControl pc = new PageControl();
   pc.setStart(1);
   pc.setPageSize(PAGE_SIZE);
   render(user, pc, req);
   HttpServletResponse resp = ctx.getHttpServletResponse();
   return RendererHelper.renderRequest(getPageUrl(), req, resp);
 }
  private List<PackageListItem> getDataResult(HttpServletRequest request) {
    RequestContext requestContext = new RequestContext(request);

    Long sid = requestContext.getRequiredParam("sid");

    Set<String> data = SessionSetHelper.lookupAndBind(request, getDecl(sid));
    List<PackageListItem> items = new LinkedList<PackageListItem>();
    for (String key : data) {
      items.add(PackageListItem.parse(key));
    }
    return items;
  }
 protected void addHardwareMessage(PackageAction pa, RequestContext rctx) {
   // If we scheduled a hardware refresh too
   if (pa != null && pa.getPrerequisite() != null) {
     // NOTE: Hardware refresh has been scheduled for
     // cascade.sfbay.redhat.com to be run before the
     // package profile sync.  This is required to verify that the
     // system has the ability to compare packages.
     List hwargs = new ArrayList();
     hwargs.add(rctx.lookupAndBindServer().getId().toString());
     hwargs.add(pa.getPrerequisite().toString());
     hwargs.add(rctx.lookupAndBindServer().getName());
     createMessage(rctx.getRequest(), "message.hardwarerefresh", hwargs);
   }
 }
  public void setUp() {
    request = new RhnMockHttpServletRequest();
    session = new RhnMockHttpSession();

    RequestContext requestContext = new RequestContext(request);

    request.setupServerName("mymachine.rhndev.redhat.com");
    request.setSession(session);
    request.setupGetRequestURI("http://localhost:8080");
    WebSession s = requestContext.getWebSession();
    request.addCookie(requestContext.createWebSessionCookie(s.getId(), 10));
    response = new RhnMockHttpServletResponse();
    chain = new MockFilterChain();
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    Server server = requestContext.lookupAndBindServer();
    Long aid = requestContext.getRequiredParam("aid");

    request.setAttribute("aid", aid);
    request.setAttribute("referrerLink", "History.do");
    request.setAttribute("linkLabel", "system.event.return");
    request.setAttribute("headerLabel", "system.event.header");

    Action action;
    ServerAction serverAction;
    try {
      action = ActionManager.lookupAction(requestContext.getCurrentUser(), aid);
      serverAction = ActionFactory.getServerActionForServerAndAction(server, action);
    } catch (LookupException e) {
      ServerHistoryEvent event = ActionFactory.lookupHistoryEventById(aid);
      request.setAttribute("actiontype", event.getSummary());
      request.setAttribute("earliestaction", event.getCreated());
      request.setAttribute("actionnotes", event.getDetails());
      request.setAttribute("failed", false);
      return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
    }
    ActionFormatter af = action.getFormatter();
    request.setAttribute("actionname", af.getName());
    request.setAttribute("actiontype", af.getActionType());
    request.setAttribute("scheduler", af.getScheduler());
    request.setAttribute("earliestaction", af.getEarliestDate());
    request.setAttribute("actionnotes", af.getDetails(server, requestContext.getCurrentUser()));
    request.setAttribute("failed", serverAction.getStatus().equals(ActionFactory.STATUS_FAILED));
    if (!serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)
        && !serverAction.getStatus().equals(ActionFactory.STATUS_FAILED)) {
      request.setAttribute("referrerLink", "Pending.do");
      request.setAttribute("linkLabel", "system.event.pendingReturn");
      request.setAttribute("headerLabel", "system.event.pendingHeader");
    }
    if (isSubmitted((DynaActionForm) formIn)) {
      createSuccessMessage(request, "system.event.rescheduled", action.getName());
      ActionFactory.rescheduleSingleServerAction(action, 5L, server.getId());
      return mapping.findForward("continue");
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /**
   * Callback for the Subscribe to channels button, it attempts to subscribe to the channels
   * containing the Packages.
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request HttpServletRequest
   * @param response HttpServletResponse
   * @return ActionForward
   */
  public ActionForward subscribeToChannels(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request, getDecl(requestContext, sid));
    Map params = new HashMap();
    params.put("sid", sid);

    syncToVictim(requestContext, sid, pkgIdCombos, ProfileManager.OPTION_SUBSCRIBE);
    return getStrutsDelegate().forwardParams(mapping.findForward("showprofile"), params);
  }
 protected ActionForward handleSubmit(ActionMapping mapping, RequestContext ctx, Server server) {
   User user = ctx.getCurrentUser();
   RhnSet set = RhnSetDecl.setForSystemCrashes(server).get(user);
   // until we delete crash files from taskomatic, we have to delete them one by one
   for (Iterator<Long> iter =
           RhnSetDecl.setForSystemCrashes(server).get(user).getElementValues().iterator();
       iter.hasNext(); ) {
     CrashManager.deleteCrash(user, iter.next());
   }
   createSuccessMessage(ctx.getRequest(), "message.crashesdeleted", Integer.toString(set.size()));
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("sid", server.getId());
   return getStrutsDelegate().forwardParams(mapping.findForward("delete"), params);
 }
    /** {@inheritDoc} */
    public List getResult(RequestContext ctx) {
      Long sid = ctx.getParamAsLong(RequestContext.SID);
      User user = ctx.getCurrentUser();

      KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);
      DataResult profiles = cmd.getKickstartProfiles();
      if (profiles.size() == 0) {
        addMessage(ctx.getRequest(), "kickstart.schedule.noprofiles");
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.FALSE.toString());
      } else {
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.TRUE.toString());
      }
      return profiles;
    }
Example #29
0
  /** {@inheritDoc} */
  public DataResult<ManagedServerGroup> getResult(RequestContext context) {

    Server server = context.lookupAndBindServer();
    ServerGroupManager manager = ServerGroupManager.getInstance();
    List<ManagedServerGroup> serverGroups = server.getManagedGroups();
    List<ManagedServerGroup> all = context.getCurrentUser().getOrg().getManagedServerGroups();
    List<ManagedServerGroup> ret = new LinkedList<ManagedServerGroup>();
    for (ManagedServerGroup group : all) {
      if (!serverGroups.contains(group) && manager.canAccess(context.getCurrentUser(), group)) {
        ret.add(group);
      }
    }
    return new DataResult<ManagedServerGroup>(ret);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getLoggedInUser();
    DataList result = OrgManager.activeOrgs(user);

    request.setAttribute(ListTagHelper.PAGE_LIST, result);
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());

    return mapping.findForward("default");
  }