private void download(String url) {
    try {
      mFile =
          FileUtil.getDestinationInExternalPublicDir(
              getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));

      PersistentCookieStore cookieStore =
          new PersistentCookieStore(AttachmentsDownloadDetailActivity.this);
      String cookieString = "";
      for (Cookie cookie : cookieStore.getCookies()) {
        cookieString += cookie.getName() + "=" + cookie.getValue() + ";";
      }

      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
      request.addRequestHeader("Cookie", cookieString);
      request.setDestinationInExternalPublicDir(
          getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));
      request.setTitle(mFileObject.getName());
      // request.setDescription(mFileObject.name);
      // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
      request.setVisibleInDownloadsUi(false);
      // request.allowScanningByMediaScanner();
      // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
      // request.setShowRunningNotification(false);

      downloadId = downloadManager.enqueue(request);
      downloadListEditor.putLong(mFileObject.file_id, downloadId);
      downloadListEditor.commit();
    } catch (Exception e) {
      Toast.makeText(this, R.string.no_system_download_service, Toast.LENGTH_LONG).show();
    }
  }
 /**
  * Non-standard helper method, to delete cookie
  *
  * @param cookie cookie to be removed
  */
 public void deleteCookie(Cookie cookie) {
   String name = cookie.getName() + cookie.getDomain();
   cookies.remove(name);
   SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
   prefsWriter.remove(COOKIE_NAME_PREFIX + name);
   prefsWriter.commit();
 }
Пример #3
0
  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
  }
 @Override
 public void process(HttpResponse response, HttpContext context)
     throws HttpException, IOException {
   CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
   for (Header header : response.getAllHeaders()) {
     if (!header.getName().equalsIgnoreCase("Set-Cookie")) {
       continue;
     }
     Matcher matcher = pattern.matcher(header.getValue());
     if (!matcher.find()) {
       continue;
     }
     for (Cookie cookie : cookieStore.getCookies()) {
       if (cookie.getName().equalsIgnoreCase(matcher.group(1))) {
         if (cookie instanceof BasicClientCookie) {
           ((BasicClientCookie) cookie).setValue('"' + cookie.getValue() + '"');
         } else if (cookie instanceof BasicClientCookie2) {
           ((BasicClientCookie2) cookie).setValue('"' + cookie.getValue() + '"');
         } else {
           Log.w(TAG, "unhandled cookie implementation " + cookie.getClass().getName());
         }
         break;
       }
     }
   }
 }
 protected Map<String, String> getCookies() {
   Map<String, String> cookieMap = new CaseInsensitiveTreeMap();
   for (Cookie cookie : this.httpClient.getCookieStore().getCookies()) {
     cookieMap.put(cookie.getName(), cookie.getValue());
   }
   return cookieMap;
 }
  @Implementation
  public String getCookie(String url) {
    CookieOrigin origin = getOrigin(url);
    List<Cookie> matchedCookies = filter(origin);
    if (matchedCookies.isEmpty()) {
      return null;
    }

    StringBuffer cookieHeaderValue = new StringBuffer();
    for (int i = 0, n = matchedCookies.size(); i < n; i++) {
      Cookie cookie = matchedCookies.get(i);

      if (i > 0) {
        cookieHeaderValue.append("; ");
      }
      cookieHeaderValue.append(cookie.getName());
      String value = cookie.getValue();
      if (value != null) {
        cookieHeaderValue.append("=");
        cookieHeaderValue.append(value);
      }
    }

    return cookieHeaderValue.toString();
  }
Пример #7
0
 private void cookieToPrefs(Cookie cookie, SyncedStore.Editor e) {
   final String name = cookie.getName();
   e.putString(COOKIE_PREFIX + name + "value", cookie.getValue());
   e.putString(COOKIE_PREFIX + name + "path", cookie.getPath());
   e.putString(COOKIE_PREFIX + name + "domain", cookie.getDomain());
   e.putString(COOKIE_PREFIX + name + "expiry", stringFromDate(cookie.getExpiryDate()));
 }
Пример #8
0
  @SuppressWarnings("deprecation")
  private void setCookie(Context context) {
    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    cookieManager.setAcceptCookie(true);
    for (int i = 0; i < cookies.size(); i++) {
      Cookie cookie = cookies.get(i);
      String cookieName = cookie.getName();
      String cookieValue = cookie.getValue();
      String domainString = cookie.getDomain();
      //			Log.i("FRAGHOME",cookieName);
      //			Log.i("FRAGHOME",cookieValue);
      //			Log.i("FRAGHOME",domainString);
      if (!cookieName.isEmpty() && !cookieValue.isEmpty() && !domainString.isEmpty()) {
        cookieManager.setCookie(domainString, cookieName + "=" + cookieValue);
      }
    }

    //		cookieManager.setCookie(baseURL, "uid=123");
    CookieSyncManager.getInstance().sync();
    if (cookieManager.getCookie(devbaseURL) != null) {
      System.out.println(cookieManager.getCookie(devbaseURL));
    }
    //		webview.loadUrl(baseURL+"?app-get_top_cate");
    //		System.out.println(cookieManager.getCookie(baseURL));
  }
Пример #9
0
 public String connectByPost(String url) {
   HttpPost httpPost = new HttpPost(url);
   System.out.println(url);
   try {
     // httpPost.addHeader("Referer",
     // "https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=5&mibao_css=m_webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131202001");
     List<Cookie> cookies = cookieStore.getCookies();
     for (Cookie cookie : cookies) {
       if (cookie.getName().equals("ptwebqq")) {
         this.ptWebqq = cookie.getValue();
       }
     }
     System.out.println(ptWebqq);
     httpPost.addHeader("clientid", "48847830");
     httpPost.addHeader("psessionid", "null");
     httpPost.addHeader(
         "r",
         "{\"status\":\"online\",\"ptwebqq\":\""
             + this.ptWebqq
             + "\",\"passwd_sig\":\"\",\"clientid\":\"48847830\",\"psessionid\":null}");
     CloseableHttpResponse response = this.httpClient.execute(httpPost);
     HttpEntity entity = response.getEntity();
     this.getContent = EntityUtils.toString(entity);
     response.close();
     httpPost.abort();
   } catch (Exception e) {
     // TODO 自动生成的 catch 块
     e.printStackTrace();
   } finally {
     return getContent;
   }
 }
  @Override
  public void writeExternal(ObjectOutput output) throws IOException {
    String data;
    Date date;
    List<Cookie> cookie_list = getCookies();
    output.writeInt(cookie_list.size());
    for (Cookie cookie : cookie_list) {
      output.writeUTF(cookie.getName());
      output.writeUTF(cookie.getValue());

      data = cookie.getComment();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      date = cookie.getExpiryDate();
      output.writeBoolean(date != null);
      if (date != null) output.writeLong(date.getTime());

      data = cookie.getDomain();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      data = cookie.getPath();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      output.writeBoolean(cookie.isSecure());
      output.writeInt(cookie.getVersion());
    }
  }
Пример #11
0
  public static void login(Map<String, String> connConf, String userName, String pwd) {
    String checkImgPage =
        "https://webim.feixin.10086.cn/WebIM/GetPicCode.aspx?Type=ccpsession&0.6949566061972312";
    String check = getChkImage(checkImgPage);
    connConf.put("check", check);

    String loginUrl = "https://webim.feixin.10086.cn/WebIM/Login.aspx";

    Map<String, String> postData = new HashMap<String, String>();
    postData.put("Ccp", check);
    postData.put("OnlineStatus", "400");
    postData.put("Pwd", pwd);
    postData.put("UserName", userName);

    postText(loginUrl, postData);

    String ssid = null;
    CookieStore cookieStroe = getCookieStroe();
    List<Cookie> cookies = cookieStroe.getCookies();
    for (Cookie cookie : cookies) {
      if (cookie.getName().equals("webim_sessionid")) {
        ssid = cookie.getValue();
        connConf.put("ssid", ssid);
        log.debug("webim_sessionid:" + ssid);
      }
    }

    String preQueryUidUrl =
        "https://webim.feixin.10086.cn/content/WebIM/GetPicCode.aspx?Type=addbuddy_ccpsession&0.7922769554654019";
    getText(preQueryUidUrl);
    String ccpId = null;
    String ccpsession = null;
    cookies = cookieStroe.getCookies();
    for (Cookie cookie : cookies) {
      if (cookie.getName().equals("addbuddy_ccpsession")) {
        ccpId = cookie.getValue();
        connConf.put("ccpId", ccpId);
        // cookies.remove(cookie);
        log.debug("addbuddy_ccpsession:" + ccpId);
      }
      if (cookie.getName().equals("ccpsession")) {
        ccpsession = cookie.getValue();
        // cookies.remove(cookie);
        log.debug("ccpsession:" + ccpsession);
      }
    }
  }
Пример #12
0
 // Obté cookie a partir d'un nom del client http especificat
 private Cookie getCookie(DefaultHttpClient cl, String name) {
   List<Cookie> cookies = cl.getCookieStore().getCookies();
   for (int i = 0; i < cookies.size(); i++) {
     Cookie c = cookies.get(i);
     if (c.getName().equals(name)) return c;
   }
   return null;
 }
  private Cookie getSessionCookie(Collection<Cookie> cookies) {
    for (Cookie cookie : cookies) {
      if ("JSESSIONID".equals(cookie.getName())) {
        return cookie;
      }
    }

    return null;
  }
Пример #14
0
 private void cookieToBundle(Cookie cookie, Bundle b) {
   final String name = cookie.getName();
   b.putString(COOKIE_PREFIX + name + "value", cookie.getValue());
   b.putString(COOKIE_PREFIX + name + "path", cookie.getPath());
   b.putString(COOKIE_PREFIX + name + "domain", cookie.getDomain());
   final Date expiryDate = cookie.getExpiryDate();
   if (null != expiryDate) {
     b.putString(COOKIE_PREFIX + name + "expiry", stringFromDate(expiryDate));
   }
 }
Пример #15
0
 /**
  * Creates a new HtmlUnit cookie from the HttpClient cookie provided.
  *
  * @param c the HttpClient cookie
  */
 public Cookie(final org.apache.http.cookie.Cookie c) {
   this(
       c.getDomain(),
       c.getName(),
       c.getValue(),
       c.getPath(),
       c.getExpiryDate(),
       c.isSecure(),
       ((ClientCookie) c).getAttribute("httponly") != null);
 }
Пример #16
0
 /**
  * Extract the sessionid cookie value
  *
  * @return sessionid string
  */
 public String getSessionID() {
   String sid = null;
   String jsid = null;
   List<Cookie> cookies = this.sessioncontext.getCookieStore().getCookies();
   for (Cookie cookie : cookies) {
     if (cookie.getName().equalsIgnoreCase("sessionid")) sid = cookie.getValue();
     if (cookie.getName().equalsIgnoreCase("jsessionid")) jsid = cookie.getValue();
   }
   return (sid == null ? jsid : sid);
 }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeObject(cookie.getName());
   out.writeObject(cookie.getValue());
   out.writeObject(cookie.getComment());
   out.writeObject(cookie.getDomain());
   out.writeObject(cookie.getExpiryDate());
   out.writeObject(cookie.getPath());
   out.writeInt(cookie.getVersion());
   out.writeBoolean(cookie.isSecure());
 }
Пример #18
0
  private boolean isPurlRunning()
      throws URISyntaxException, HttpException, ClientProtocolException, IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    URI url =
        new URI(
            "http://localhost:" + testInfo.getPurlzPort() + IdentifiersTestInfo.PURLZ_REST_LOGIN);
    HttpPost method = new HttpPost(url);

    List<NameValuePair> loginParams = new ArrayList<NameValuePair>();
    loginParams.add(new BasicNameValuePair("id", IdentifiersTestInfo.PURLZ_USER));
    loginParams.add(new BasicNameValuePair("passwd", IdentifiersTestInfo.PURLZ_PASSWORD));
    loginParams.add(new BasicNameValuePair("referrer", "/docs/index.html"));

    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(loginParams, "UTF-8");
    method.setEntity(entity);

    try {
      System.out.println("isPurlRunning connecting to " + url);
      HttpResponse response = client.execute(method);

      int statusCode = response.getStatusLine().getStatusCode();

      System.out.println("PURL Login: HTTP Status code: " + statusCode);

      if (statusCode != HttpStatus.SC_OK) {
        throw new HttpException(
            " [" + statusCode + ":" + response.getStatusLine().toString() + "]");
      }

      String responseStr = IdentifiersTestInfo.getResponseString(response);
      if (!responseStr.contains(IdentifiersTestInfo.PURLZ_WELCOME_MSG)) {
        System.out.println("BAD RESPONSE FROM SERVER [" + responseStr + "]");
        return false;
      }

      System.out.println("Login to PURL successful...");

      CookieStore store = client.getCookieStore();

      for (Cookie cookie : store.getCookies()) {
        if (cookie.getName().equalsIgnoreCase(IdentifiersTestInfo.PURLZ_LOGIN_COOKIE)) {
          testInfo.setPurlzLoginCookie(cookie);
          return true;
        }
      }
    } finally {
      // Release the connection.
      method.abort();
      client.getConnectionManager().shutdown();
    }

    return false;
  }
Пример #19
0
 // 检查过期时间
 private boolean checkExperid(List<Cookie> cookies) {
   for (Cookie cookie : cookies) {
     if ("ue".equals(cookie.getName())) {
       Date now = new Date();
       if (now.compareTo(cookie.getExpiryDate()) > 0) {
         return false;
       }
     }
   }
   return true;
 }
 public void addCookie(Cookie cookie) {
   String name = cookie.getName();
   if (cookie.isExpired(new Date())) {
     this.cookies.remove(name);
   } else {
     this.cookies.put(name, cookie);
   }
   Editor edit = this.cookiePrefs.edit();
   edit.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
   edit.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
   edit.commit();
 }
Пример #21
0
 public Cookie getCookie(String name) {
   if (cookies == null || cookies.length == 0) {
     return null;
   }
   for (int i = 0; i < cookies.length; i++) {
     Cookie cookie = cookies[i];
     if (cookie.getName().equalsIgnoreCase(name)) {
       return cookie;
     }
   }
   return null;
 }
Пример #22
0
 public void addCookie(Cookie paramCookie) {
   String str = paramCookie.getName();
   if (!paramCookie.isExpired(new Date())) {
     this.cookies.put(str, paramCookie);
   }
   for (; ; ) {
     SharedPreferences.Editor localEditor = this.cookiePrefs.edit();
     localEditor.putString("names", TextUtils.join(",", this.cookies.keySet()));
     localEditor.putString("cookie_" + str, encodeCookie(new SerializableCookie(paramCookie)));
     localEditor.commit();
     return;
     this.cookies.remove(str);
   }
 }
 @Override
 public void saveCookie(Cookie cookie) {
   if (cookie != null) {
     httpClient.getCookieStore().addCookie(cookie);
     if (canCloudflare()) {
       if (cookie.getName().equals(CLOUDFLARE_COOKIE_NAME)) {
         preferences
             .edit()
             .putString(getSharedKey(PREF_KEY_CLOUDFLARE_COOKIE), cookie.getValue())
             .commit();
       }
     }
   }
 }
  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 saveCookiesToPreferences(Context context, DefaultHttpClient client) {
    final SharedPreferences sharedPreferences =
        context.getSharedPreferences(SHARED_PREFERENCES_NAME_SUMC_COOKIES, Context.MODE_PRIVATE);
    final Editor edit = sharedPreferences.edit();
    edit.clear();

    int i = 0;
    for (Cookie cookie : client.getCookieStore().getCookies()) {
      edit.putString(PREFERENCES_COOKIE_NAME + i, cookie.getName());
      edit.putString(PREFERENCES_COOKIE_VALUE + i, cookie.getValue());
      edit.putString(PREFERENCES_COOKIE_DOMAIN + i, cookie.getDomain());
      edit.putString(PREFERENCES_COOKIE_PATH + i, cookie.getPath());
      i++;
    }
    edit.commit();
  }
  public void addCookie(Cookie cookie) {
    String name = cookie.getName();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
      cookies.put(name, cookie);
    } else {
      cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
  }
Пример #27
0
  @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);
    }
  }
Пример #28
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;
 }
Пример #29
0
  @Override
  public synchronized void addCookie(Cookie cookie) {

    super.addCookie(cookie);
    String name = cookie.getName();

    Cookie existing = null;
    SyncedStore.Reader r = mSharedPreferences.read();
    try {
      existing = cookieFromPrefs(r, name);
    } finally {
      r.complete();
    }

    if (existing == null
        || !existing.getValue().equals(cookie.getValue())
        || !existing.getPath().equals(cookie.getPath())
        || !existing.getDomain().equals(cookie.getDomain())
        || !existing.getExpiryDate().equals(cookie.getExpiryDate())) {

      SyncedStore.Editor e = mSharedPreferences.edit();
      try {
        // clear the existing cookie from prefs.
        String prefix = COOKIE_PREFIX + name;
        for (String k : e.keySet()) {
          if (k.startsWith(prefix)) {
            e.remove(k);
          }
        }

        // and then, if new cookie is persistent, then add it!
        if (cookie.getExpiryDate() != null) {
          cookieToPrefs(cookie, e);
        }
      } finally {
        e.commit();
      }
    }
  }
Пример #30
0
  /**
   * 获取标准 Cookie ,并存储
   *
   * @param httpClient
   */
  private void getCookie(DefaultHttpClient httpClient) {
    List<Cookie> cookies = httpClient.getCookieStore().getCookies();
    // StringBuffer sb = new StringBuffer();
    for (int i = 0; i < cookies.size(); i++) {
      Cookie cookie = cookies.get(i);
      String cookieName = cookie.getName();
      String cookieValue = cookie.getValue();
      if (!TextUtils.isEmpty(cookieName) && !TextUtils.isEmpty(cookieValue)) {
        if ("JSESSIONID".equalsIgnoreCase(cookieName)) {
          JSESSIONIDStr = cookieValue;
        }
      }
    }
    // Log. e( "cookie", sb.toString());

    if (JSESSIONIDStr != null && !"".equals(JSESSIONIDStr)) {
      appContext
          .getSharedPreferences(BaseActivity.SETTING_INFOS, 0)
          .edit()
          .putString(BaseActivity.COOKIES_STR, JSESSIONIDStr)
          .commit();
    }
  }