protected synchronized void clearCookieForHost(String sessionHost) throws Exception {
    Cookie sessionCookie = null;
    for (Cookie cookie : cookieStore.getCookies()) {
      String cookieDomain = cookie.getDomain();
      if (cookieDomain != null) {
        if (sessionHost.equals(cookieDomain)
            || sessionHost.indexOf(cookieDomain) != -1
            || cookieDomain.indexOf(sessionHost) != -1) {
          sessionCookie = cookie;
          break;
        }
      }
    }

    if (sessionCookie != null) {
      BasicClientCookie httpCookie =
          new BasicClientCookie(sessionCookie.getName(), sessionCookie.getValue());
      httpCookie.setExpiryDate(new Date(0));
      httpCookie.setVersion(1);
      httpCookie.setPath(sessionCookie.getPath());
      httpCookie.setDomain(sessionCookie.getDomain());
      cookieStore.addCookie(httpCookie);
    }

    cookieStore.clearExpired(new Date()); // this should clear the cookie
  }
 @Implementation
 public void setCookie(String url, String value) {
   List<Cookie> cookies = parseCookies(url, value);
   for (Cookie cookie : cookies) {
     store.addCookie(cookie);
   }
 }
Esempio n. 3
0
  private Response doRequest(final Request<?> request, final HttpRequestBase fetcher) {
    if (fetcher == null) {
      return null;
    }

    List<Parameter> headers = request.getHeaders();
    if (checkListOfParams(headers)) {
      for (Parameter parameter : headers) {
        Header header = new BasicHeader(parameter.getName(), parameter.getValue());
        fetcher.addHeader(header);
      }
    }

    final DefaultHttpClient httpClient = getHttpClient();
    List<Parameter> cookies = request.getCookies();
    if (checkListOfParams(cookies)) {
      CookieStore cookieStore = httpClient.getCookieStore();
      for (Parameter cookie : cookies) {
        cookieStore.addCookie(new BasicClientCookie(cookie.getName(), cookie.getValue()));
      }
      httpClient.setCookieStore(cookieStore);
    }

    return doRequest(fetcher, httpClient);
  }
  @Override
  public void activateBrowserfeatures(final Upload upload) throws UnirestException {

    // Create a local instance of cookie store
    // Populate cookies if needed
    final CookieStore cookieStore = new BasicCookieStore();
    for (final PersistentCookieStore.SerializableCookie serializableCookie :
        upload.getAccount().getSerializeableCookies()) {
      final BasicClientCookie cookie =
          new BasicClientCookie(
              serializableCookie.getCookie().getName(), serializableCookie.getCookie().getValue());
      cookie.setDomain(serializableCookie.getCookie().getDomain());
      cookieStore.addCookie(cookie);
    }

    final HttpClient client =
        HttpClientBuilder.create().useSystemProperties().setDefaultCookieStore(cookieStore).build();
    Unirest.setHttpClient(client);

    final HttpResponse<String> response =
        Unirest.get(String.format(VIDEO_EDIT_URL, upload.getVideoid())).asString();

    changeMetadata(response.getBody(), upload);

    final RequestConfig clientConfig =
        RequestConfig.custom().setConnectTimeout(600000).setSocketTimeout(600000).build();
    Unirest.setHttpClient(HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());
  }
Esempio n. 5
0
 private void getCookieFromTr1(MyRespone myRespone) {
   Header[] headers = myRespone.getHttpClientContext().getResponse().getHeaders("Set-Cookie");
   for (Header header : headers) {
     BasicClientCookie cookie =
         new BasicClientCookie(
             header.getValue().split(";")[0].split("=")[0],
             header.getValue().split(";")[0].split("=")[1]);
     cookie.setDomain(host);
     cookie.setPath("/");
     cookieStore.addCookie(cookie);
     System.out.println(header.getValue().split(";")[0].split("=")[1]);
   }
   BasicClientCookie cookie = new BasicClientCookie("PLUS", "1");
   cookie.setDomain(host);
   cookie.setPath("/");
   cookieStore.addCookie(cookie);
 }
 private void clearAndAddPersistentCookies() {
   List<Cookie> cookies = new ArrayList<Cookie>(store.getCookies());
   store.clear();
   for (Cookie cookie : cookies) {
     if (cookie.isPersistent()) {
       store.addCookie(cookie);
     }
   }
 }
Esempio n. 7
0
 private void generateCookie(HttpClientBuilder httpClientBuilder, Site site) {
   CookieStore cookieStore = new BasicCookieStore();
   for (Map.Entry<String, String> cookieEntry : site.getCookies().entrySet()) {
     BasicClientCookie cookie =
         new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
     cookie.setDomain(site.getDomain());
     cookieStore.addCookie(cookie);
   }
   for (Map.Entry<String, Map<String, String>> domainEntry : site.getAllCookies().entrySet()) {
     for (Map.Entry<String, String> cookieEntry : domainEntry.getValue().entrySet()) {
       BasicClientCookie cookie =
           new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
       cookie.setDomain(domainEntry.getKey());
       cookieStore.addCookie(cookie);
     }
   }
   httpClientBuilder.setDefaultCookieStore(cookieStore);
 }
Esempio n. 8
0
  @Test
  public void example3() {
    CookieStore cookieStore = new BasicCookieStore();
    BasicClientCookie cookie = new BasicClientCookie("name", "value");
    cookieStore.addCookie(cookie);

    CloseableHttpClient httpClient =
        HttpClients.custom().setDefaultCookieStore(cookieStore).build();
  }
Esempio n. 9
0
  private static int getContacktJsonList(String ssid, CookieStore cookieStroe, int version) {
    String getContactListUrl =
        "https://webim.feixin.10086.cn/WebIM/GetContactList.aspx?Version=" + version++;
    Map<String, String> postData = new HashMap<String, String>();
    postData.put("ssid", ssid);

    BasicClientCookie cookie = new BasicClientCookie("IsCookiesEnable", "true");
    cookie.setVersion(0);
    cookie.setDomain(".webim.feixin.10086.cn");
    cookie.setPath("/");
    cookieStroe.addCookie(cookie);

    cookie = new BasicClientCookie("webim_login_status", "0");
    cookie.setVersion(0);
    cookie.setDomain(".webim.feixin.10086.cn");
    cookie.setPath("/");
    cookieStroe.addCookie(cookie);

    cookie = new BasicClientCookie("webim_loginCounter", "1342244257406");
    cookie.setVersion(0);
    cookie.setDomain(".webim.feixin.10086.cn");
    cookie.setPath("/");
    cookieStroe.addCookie(cookie);

    cookie =
        new BasicClientCookie(
            "webim_remindmsgs", "645048052-39532%21191-0-a56dcfc5f2c943adb168c91f6456fe59");
    cookie.setVersion(0);
    cookie.setDomain(".feixin.10086.cn");
    cookie.setPath("/");
    cookieStroe.addCookie(cookie);

    // {"rc":521,"rv":{"bl":"0","bss":1,"ln":"","rs":0,"uid":223534907,"uri":"tel:13636532333","v":"0"}}
    // JSONObject json = postTextToJson(getContactListUrl, postData);
    // String uid = null;
    // if(json.getString("rc").equals("521")){
    // uid = json.getJSONObject("rv").getString("uid");
    // log.debug("uid:" + uid);
    // }
    return version;
  }
Esempio n. 10
0
 private void getCookieFromHome(MyRespone myRespone) {
   Header[] headers = myRespone.getHttpClientContext().getResponse().getHeaders("Set-Cookie");
   for (Header header : headers) {
     if (!header.getValue().contains("__bsi")) {
       BasicClientCookie cookie =
           new BasicClientCookie(
               header.getValue().split(";")[0].split("=")[0],
               header.getValue().split(";")[0].split("=")[1]);
       cookie.setDomain(host);
       cookie.setPath("/");
       //				System.out.println(cookie);
       cookieStore.addCookie(cookie);
     }
   }
 }
  private static CookieStore handleCsrfCookies(CookieStore cookieStore) {
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (Cookie cookie : cookieStore.getCookies()) {
      if (!cookie.getName().contains("CSRF")) {
        cookies.add(cookie);
      }
    }

    cookieStore.clear();

    for (Cookie cookie : cookies) {
      cookieStore.addCookie(cookie);
    }
    return cookieStore;
  }
  private void loadCookiesFromPreferences(Context context, DefaultHttpClient client) {
    final CookieStore cookieStore = client.getCookieStore();
    final SharedPreferences sharedPreferences =
        context.getSharedPreferences(SHARED_PREFERENCES_NAME_SUMC_COOKIES, Context.MODE_PRIVATE);

    int i = 0;
    while (sharedPreferences.contains(PREFERENCES_COOKIE_NAME + i)) {
      final String name = sharedPreferences.getString(PREFERENCES_COOKIE_NAME + i, null);
      final String value = sharedPreferences.getString(PREFERENCES_COOKIE_VALUE + i, null);
      final BasicClientCookie result = new BasicClientCookie(name, value);

      result.setDomain(sharedPreferences.getString(PREFERENCES_COOKIE_DOMAIN + i, null));
      result.setPath(sharedPreferences.getString(PREFERENCES_COOKIE_PATH + i, null));
      cookieStore.addCookie(result);
      i++;
    }
  }
  @Override
  public void retrieve() throws RetrieverException {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient
        .getParams()
        .setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
    HttpContext context = new BasicHttpContext();

    accounts = new HashMap<String, Account>();
    try {
      CookieStore cookieStore = httpClient.getCookieStore();
      BasicClientCookie newCookie = new BasicClientCookie("XPRDMBP1E", registrationCookie);
      newCookie.setVersion(0);
      newCookie.setDomain("bankservices.rabobank.nl");
      newCookie.setPath("/");
      cookieStore.addCookie(newCookie);

      if (!checkAppStatus(httpClient, context)) {
        throw new RetrieverException("Application status is not OK");
      }

      if (!loginWithAccessCode(httpClient, context, accountNumber, accessCode)) {
        throw new RetrieverException("Login with access code failed", true);
      }

      List<Account> accountList = retrieveAccounts(httpClient, context);

      logoff(httpClient, context);

      accounts = new HashMap<String, Account>();
      for (Account account : accountList) {
        accounts.put(account.getAccountName(), account);
      }

      for (Cookie cookie : httpClient.getCookieStore().getCookies()) {
        if ("XPRDMBP1E".equals(cookie.getName())) {
          registrationCookie = cookie.getValue();
        }
      }
    } catch (IOException e) {
      throw new RetrieverException(e);
    }
  }
Esempio n. 14
0
  public static void main(String[] args) {
    BasicClientCookie cookie = new BasicClientCookie("test", "test");
    cookie.setDomain("115.159.3.51");
    cookie.setPath("/");
    CookieStore cs = new BasicCookieStore();
    cs.addCookie(cookie);
    System.out.println(cs.getCookies());
    try {
      CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cs).build();
      HttpGet httpGet = new HttpGet("http://115.159.3.51/cookieShow.php");
      CloseableHttpResponse response = httpClient.execute(httpGet);
      try {
        HttpEntity responseEntity = response.getEntity();
        System.out.println(EntityUtils.toString(responseEntity));

      } finally {
        response.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 15
0
 /**
  * Проверяет авторизирован ли пользователь,удаляет все куки записи которые неявляются
  * обязательными
  *
  * @return true если авторизирован
  */
 public boolean isAutorizted() {
   List<Cookie> listCookie = new ArrayList<Cookie>();
   // System.out.println(cookie.getCookies().size());
   for (Cookie cookieElement : cookie.getCookies()) {
     boolean result = false;
     for (String mandatoryEl : mandatoryElements)
       if (cookieElement.getName().compareTo(mandatoryEl) == 0) {
         result = true;
         break;
       }
     if (result) {
       listCookie.add(cookieElement);
     }
   }
   cookie.clear();
   // System.out.println(cookie.getCookies().size());
   for (Cookie cookieElement : listCookie) {
     cookie.addCookie(cookieElement);
   }
   // System.out.println(cookie.getCookies().size());
   return cookie.getCookies().size() == mandatoryElements.length;
 }
Esempio n. 16
0
 public void setCookie(Cookie cookie) {
   cookieJar.addCookie(cookie);
 }