private ActionConfig buildActionConfig(String path) {
    ActionMapping mapping = new ActionMapping();

    mapping.setName("name,{1}");
    mapping.setPath(path);
    mapping.setScope("request");
    mapping.setUnknown(false);
    mapping.setValidate(true);

    mapping.setPrefix("foo,{1}");
    mapping.setSuffix("bar,{1}");

    mapping.setType("foo.bar.{1}Action");
    mapping.setRoles("public,{1}");
    mapping.setParameter("param,{1}");
    mapping.setAttribute("attrib,{1}");
    mapping.setForward("fwd,{1}");
    mapping.setInclude("include,{1}");
    mapping.setInput("input,{1}");

    ForwardConfig cfg = new ActionForward();

    cfg.setName("name");
    cfg.setPath("path,{1}");
    cfg.setModule("mod{1}");
    cfg.setProperty("foo", "bar,{1}");
    mapping.addForwardConfig(cfg);

    cfg = new ActionForward();
    cfg.setName("name2");
    cfg.setPath("path2");
    cfg.setModule("mod{1}");
    mapping.addForwardConfig(cfg);

    ExceptionConfig excfg = new ExceptionConfig();

    excfg.setKey("foo");
    excfg.setType("foo.Bar");
    excfg.setPath("path");
    mapping.addExceptionConfig(excfg);

    excfg = new ExceptionConfig();
    excfg.setKey("foo2");
    excfg.setType("foo.Bar2");
    excfg.setPath("path2");
    mapping.addExceptionConfig(excfg);

    mapping.setProperty("testprop", "testval");
    mapping.setProperty("testprop2", "test{1}");

    mapping.freeze();

    return mapping;
  }
Пример #2
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);
  }
Пример #3
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());
  }
Пример #4
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;
  }
Пример #5
0
  /**
   * Method that will create and add an ActionForward to a ActionMapping, this call is mandatory for
   * the creation of ActionForwards because extra logic will be required for jsp forwards to work.
   *
   * @param actionMapping
   * @param name
   * @param path
   * @param redirect
   * @return
   * @throws Exception
   */
  protected ForwardConfig registerActionForward(
      BundleContext context,
      ActionMapping actionMapping,
      String name,
      String path,
      Boolean redirect)
      throws Exception {

    if (!path.startsWith(PATH_SEPARATOR)) {
      path = PATH_SEPARATOR + path;
    }

    String forwardMapping = activatorUtil.getBundleFolder(context) + path;

    // Creating an ForwardConfig Instance
    ForwardConfig forwardConfig = new ActionForward(name, forwardMapping, redirect);
    // Adding the ForwardConfig to the ActionConfig
    actionMapping.addForwardConfig(forwardConfig);

    // Copy all the resources inside the folder of the given resource to the corresponding dotCMS
    // folders
    activatorUtil.moveResources(context, path);

    return forwardConfig;
  }
  @Before
  public void setUp() throws Exception {

    mapping.addForwardConfig(new ActionForward("success", "/jsp/AjaxResponse.jsp", false));
    mapping.addForwardConfig(new ActionForward("failure", "/jsp/ErrorMsgPage.jsp", false));

    request =
        (MockHttpServletRequest)
            Log2TxNode.getInstance()
                .log2TxNode2HttpServletRequest(request, actionName, ajaxChildValue);
  }
  @Before
  public void setUp() throws Exception {

    mapping.addForwardConfig(new ActionForward("success", "/jsp/choosePOI.jsp", false));
    request = (MockHttpServletRequest) log2Protobuf.getInstance().getProtobuf("mock");

    request.addParameter("poi", "");
    request.addParameter("json", "");
    request.addParameter("width", "480");
    request.addParameter("height", "800");
    request.addParameter("clientInfo", "{}");
  }
 private static void registerForward(
     final ActionMapping actionMapping,
     final Forward forward,
     Forwards forwards,
     Mapping mapping,
     String defaultResourcesName) {
   if (forward.useTile() && isSimplePageFile(forward.path())) {
     PartialTileDefinition tileDefinition =
         new PartialTileDefinition(forward, forwards, mapping, defaultResourcesName);
     FenixDefinitionsFactory.registerDefinition(tileDefinition);
     actionMapping.addForwardConfig(
         new ActionForward(
             forward.name(),
             tileDefinition.getName(),
             forward.redirect(),
             forward.contextRelative()));
   } else {
     // The forward is using an existing tile definition
     actionMapping.addForwardConfig(
         new ActionForward(
             forward.name(), forward.path(), forward.redirect(), forward.contextRelative()));
   }
 }