Esempio n. 1
0
  @Override
  protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception {
    HtmlForm form = authorizationPage.getFormByName("loginform");
    final HtmlTextInput login = form.getInputByName("log");
    login.setValueAttribute("testscribeup");
    final HtmlPasswordInput passwd = form.getInputByName("pwd");
    passwd.setValueAttribute("testpwdscribeup");

    HtmlElement button = (HtmlElement) authorizationPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // HtmlButton button = form.getButtonByName("wp-submit");

    final HtmlPage confirmPage = button.click();
    form = confirmPage.getFormByName("loginform");

    button = (HtmlElement) confirmPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // button = form.getButtonByName("wp-submit");

    final HtmlPage callbackPage = button.click();
    final String callbackUrl = callbackPage.getUrl().toString();
    logger.debug("callbackUrl : {}", callbackUrl);
    return callbackUrl;
  }
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlPasswordInput password = form.getInputByName("password");
   password.setValueAttribute("testpwdpac4j");
   final HtmlSubmitInput submit = form.getInputByValue("Sign In");
   final HtmlPage callbackPage = submit.click();
   /*form = confirmPage.getForms().get(0);
   HtmlButton continueButton = (HtmlButton) form.getElementById("continue-button");
   HtmlPage callbackPage = continueButton.click();*/
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
Esempio n. 3
0
  public Page submitAuthentication(String username, String password) throws IOException {
    if (usernameField != null && passwordField != null && submitField != null) {
      usernameField.setValueAttribute(username);
      passwordField.setValueAttribute(password);
      return submitField.click();
    }

    return null;
  }
Esempio n. 4
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginValid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("*****@*****.**");
    textPassword.setValueAttribute("malczyk123");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.getTitleText().equals("Taskflow-Main"));

    webClient.closeAllWindows();
  }
Esempio n. 5
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginInvalid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("invalidLogin");
    textPassword.setValueAttribute("invalidPasswd");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.asText().contains("Błędny login bądź hasło"));

    webClient.closeAllWindows();
  }
Esempio n. 6
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   webClient.waitForBackgroundJavaScript(5000);
   HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlTextInput login = form.getInputByName("login_email");
   login.setValueAttribute("*****@*****.**");
   final HtmlPasswordInput passwd = form.getInputByName("login_password");
   passwd.setValueAttribute("testpwdscribeup");
   HtmlButton submit = form.getButtonByName("");
   HtmlPage confirmPage = submit.click();
   confirmPage = (HtmlPage) confirmPage.refresh();
   webClient.waitForBackgroundJavaScript(5000);
   form = confirmPage.getForms().get(0);
   HtmlButton submit2 = form.getButtonByName("allow_access");
   final HtmlPage callbackPage = submit2.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
Esempio n. 7
0
  public static HtmlPage login(HtmlPage page, String username, String password) {
    int attempts = 0;
    boolean loggedIn = false;
    while (!loggedIn) {
      try {
        if (attempts > 3) System.exit(1);
        attempts++;
        System.out.println("Logging in... (Attempt " + attempts + ")");

        page = wc.getPage("http://torn.com/login");

        final HtmlForm form = page.getFormByName("login");

        HtmlSubmitInput button = form.getInputByName("btnLogin");

        HtmlTextInput textField = form.getInputByName("player");

        // Change the value of the text field
        textField.setValueAttribute(username);

        final HtmlPasswordInput passwordField = form.getInputByName("password");

        // Change the value of the text field
        passwordField.setValueAttribute(password);

        // Now submit the form by clicking the button and get back the second page.
        page = button.click();

        page = wc.getPage("http://torn.com/index.php");
        loggedIn = true;

      } catch (Exception e) {
        System.out.println(e.toString());
        loggedIn = false;
      }
    }
    return page;
  }
  @Test
  public void testConfigureApitoken() throws Exception {
    prepareSecurity();

    FreeStyleProject p = j.createFreeStyleProject();
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("test2", false)));

    WebClient wc = j.createWebClient();
    wc.login("test1");

    String apitokenForTest2 = User.get("test2").getProperty(ApiTokenProperty.class).getApiToken();
    assertNotNull(apitokenForTest2);
    assertNotEquals("", apitokenForTest2);

    // authentication fails without apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication succeeds with the good apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      j.submit(page.getFormByName("config"));

      assertEquals(
          "test2",
          ((SpecificUsersAuthorizationStrategy)
                  p.getProperty(AuthorizeProjectProperty.class).getStrategy())
              .getUserid());
    }

    // authentication fails with a bad apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2 + "xxx");
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication fails if the apitoken is used for password
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(false);
      HtmlPasswordInput password =
          page.<HtmlPasswordInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'password') and @type='password']");
      password.setValueAttribute(apitokenForTest2);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }
  }
Esempio n. 9
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    int no = 0;
    try {
      no = Integer.parseInt(request.getParameter("no"));

    } catch (NumberFormatException exception) {
      no = 0;
    }

    try {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet NewServlet</title>");
      out.println("</head>");
      out.println("<body>");

      final WebClient webClient = new WebClient();
      webClient.getCookieManager().clearCookies();
      webClient.getOptions().setUseInsecureSSL(true);
      webClient.setJavaScriptEnabled(false);
      final HtmlPage page = webClient.getPage("https://filestream.me/");
      // out.println(page.getTitleText());
      System.out.println("no of forms : " + page.getForms().size());
      HtmlForm form = page.getForms().get(1);
      final HtmlTextInput textField = form.getInputByName("login");
      textField.setAttribute("value", "*****@*****.**");

      final HtmlPasswordInput passField = form.getInputByName("password");
      passField.setAttribute("value", "ramkrishnan18");
      HtmlSubmitInput htmlSubmitInput = form.getInputByValue("login");
      HtmlPage page1 = htmlSubmitInput.click();

      HtmlTable htmlTable = page1.getHtmlElementById("fileCatTable");
      List<HtmlTableRow> listOfHtmlTableRow = htmlTable.getBodies().get(0).getRows();
      List<String> allLinks = new ArrayList<String>();
      for (HtmlTableRow htmlTableRow : listOfHtmlTableRow) {
        HtmlTableCell cell = htmlTableRow.getCells().get(htmlTableRow.getCells().size() - 1);
        for (DomElement domElement : cell.getChildElements()) {
          // out.println(domElement.getTagName());
          if (domElement.getTagName().equals("div")) {
            boolean flag = true;

            for (DomElement celldomElement : domElement.getChildElements()) {
              if (flag) {
                // out.println(celldomElement.getTagName());

                String title = celldomElement.getAttribute("title");
                if ("Download".equals(title) || "Downloads".equals(title)) {

                  String link = celldomElement.getAttribute("onclick");
                  String http =
                      link.substring(
                          link.indexOf('\'') + 1, link.indexOf('\'', link.indexOf('\'') + 1));

                  //  out.println(celldomElement.getAttribute("onclick") + "<br/>");
                  // out.println(http + "<br/>");
                  allLinks.add(http);
                  flag = false;
                }
              }
            }
          }
        }
      }

      //  InputStream is =anchorAttachment.click().getWebResponse().getContentAsStream();

      out.println("************ Start *************");

      //  HtmlAnchor anchorElement=HTMLAnchorElement.;
      //  anchorElement.set
      // anchorElement.setHref(allLinks.get(0));

      //  anchorElement.cl
      final String u = allLinks.get(no);
      Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    URL url = new URL(u);
                    System.out.println("Link : " + u);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();

                    // System.out.println("Response Code : " + con.getInputStream().available());
                    con.setRequestProperty("Accept-Encoding", "gzip,deflate");
                    con.setRequestProperty(
                        "User-Agent",
                        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36");

                    Map<String, List<String>> map = con.getHeaderFields();

                    for (String object : map.keySet()) {
                      System.out.println(object + " --> " + map.get(object));
                    }

                    System.out.println("Response Code : " + con.getResponseCode());
                    System.out.println("length :" + con.getContentLength());
                    System.out.println("Message " + con.getResponseMessage());

                    InputStream inputStream = con.getInputStream();
                    String path = System.getenv("OPENSHIFT_JBOSSAS_DIR");
                    FileOutputStream fileOutputStream = new FileOutputStream(path + "test.zip");
                    byte[] buffer = new byte[1024];
                    System.out.println(inputStream.available());
                    int bytesRead = 10;
                    while (true) {
                      //   System.out.print("--");
                      bytesRead = inputStream.read(buffer);
                      //   System.out.println(bytesRead);
                      if (bytesRead == -1) {
                        break;
                      }
                      fileOutputStream.write(buffer, 0, bytesRead);
                      // System.out.print(">");
                    }
                    fileOutputStream.close();

                    System.out.println("File Completed");
                  } catch (IOException ex) {
                    Logger.getLogger(MakeData.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              });
      t.start();

      //            System.out.println(allLinks.get(0));
      //            System.out.println(webClient.getCookieManager().getCookies(new
      // URL(allLinks.get(0))).size());
      //            // System.out.println(httpPage.asText());
      //             HtmlPage httpPage = webClient.getPage(allLinks.get(0));
      //
      //           // final String pageAsXml = page1.asXml();
      //            // InputStream inputStream=httpPage.getWebResponse().getContentAsStream();
      //           //  inputStream.available();
      //              System.out.println("Code : "+httpPage.getWebResponse().getStatusMessage());
      //               System.out.println("Code : "+httpPage.getWebResponse().getContentType());
      //                System.out.println("netCode :
      // "+httpPage.getWebResponse().getContentCharset());
      //
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getStatusCode());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentType());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentCharset());

      // final String pageAsText = page1.asText();

      // out.println(pageAsXml);
      webClient.closeAllWindows();
      out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
      out.println("</body>");
      out.println("</html>");
    } finally {
      out.close();
    }
  }