List of usage examples for org.apache.http.cookie Cookie isSecure
boolean isSecure();
From source file:org.apache.ambari.view.hive.client.Utils.java
static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) { if (cookieName == null || cookieStore == null) { return true; }//from w w w.java 2 s .co m List<Cookie> cookies = cookieStore.getCookies(); for (Cookie c : cookies) { // If this is a secured cookie and the current connection is non-secured, // then, skip this cookie. We need to skip this cookie because, the cookie // replay will not be transmitted to the server. if (c.isSecure() && !isSSL) { continue; } if (c.getName().equals(cookieName)) { return false; } } return true; }
From source file:cn.ttyhuo.common.MyApplication.java
public static void getJavaCookieStore(java.net.CookieStore jCookieStore) { if (cookieStore == null) return;//from w w w. j a v a 2 s .c o m for (Cookie h : cookieStore.getCookies()) { HttpCookie newCookie = new HttpCookie(h.getName(), h.getValue()); newCookie.setVersion(h.getVersion()); newCookie.setDomain(h.getDomain()); newCookie.setPath(h.getPath()); newCookie.setSecure(h.isSecure()); newCookie.setComment(h.getComment()); jCookieStore.add(URI.create("http://" + h.getDomain()), newCookie); } }
From source file:Main.java
@Deprecated // Deprecated because this uses org.apache.http, which is itself deprecated public static HttpCookie servletCookieFromApacheCookie(org.apache.http.cookie.Cookie apacheCookie) { if (apacheCookie == null) { return null; }/* w w w. j a va 2 s .c o m*/ String name = apacheCookie.getName(); String value = apacheCookie.getValue(); HttpCookie cookie = new HttpCookie(name, value); value = apacheCookie.getDomain(); if (value != null) { cookie.setDomain(value); } value = apacheCookie.getPath(); if (value != null) { cookie.setPath(value); } cookie.setSecure(apacheCookie.isSecure()); value = apacheCookie.getComment(); if (value != null) { cookie.setComment(value); } // version cookie.setVersion(apacheCookie.getVersion()); // From the Apache source code, maxAge is converted to expiry date using the following formula // if (maxAge >= 0) { // setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L)); // } // Reverse this to get the actual max age Date expiryDate = apacheCookie.getExpiryDate(); if (expiryDate != null) { long maxAge = (expiryDate.getTime() - System.currentTimeMillis()) / 1000; // we have to lower down, no other option cookie.setMaxAge((int) maxAge); } // return the servlet cookie return cookie; }
From source file:org.apache.hive.jdbc.Utils.java
/** * The function iterates through the list of cookies in the cookiestore and tries to * match them with the cookieName. If there is a match, the cookieStore already * has a valid cookie and the client need not send Credentials for validation purpose. * @param cookieStore The cookie Store/*ww w . j ava 2s . co m*/ * @param cookieName Name of the cookie which needs to be validated * @param isSSL Whether this is a http/https connection * @return true or false based on whether the client needs to send the credentials or * not to the server. */ static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) { if (cookieName == null || cookieStore == null) { return true; } List<Cookie> cookies = cookieStore.getCookies(); for (Cookie c : cookies) { // If this is a secured cookie and the current connection is non-secured, // then, skip this cookie. We need to skip this cookie because, the cookie // replay will not be transmitted to the server. if (c.isSecure() && !isSSL) { continue; } if (c.getName().equals(cookieName)) { return false; } } return true; }
From source file:fedroot.dacs.http.DacsClientContextTest.java
public void testGetAllCookies() throws Exception { URI uri = URIUtils.createURI("http", "www.google.com", -1, "/search", "q=httpclient&btnG=Google+Search&aq=f&oq=", null); DacsGetRequest dacsGetRequest = new DacsGetRequest(uri); DacsResponse dacsResponse = dacsClientContext.executeGetRequest(dacsGetRequest); List<Cookie> cookies = dacsClientContext.getAllCookies(); assertEquals(2, cookies.size());/*www . j av a 2 s . co m*/ for (Cookie cookie : cookies) { System.out.println(cookie.getName()); assertFalse(cookie.isSecure()); assertFalse(cookie.isExpired(new Date())); assertFalse(DacsCookie.isDacsCookie(cookie)); } }
From source file:com.gooddata.http.client.CookieUtilsTest.java
private void checkCookie(final String sst) { List<Cookie> cookies = cookieStore.getCookies(); assertEquals(1, cookies.size());/*from w w w . ja v a2s . c o m*/ Cookie cookie = cookies.get(0); assertThat(DOMAIN, is(cookie.getDomain())); assertThat(sst, is(cookie.getValue())); assertThat(true, is(cookie.isSecure())); assertThat("/gdc/account", is(cookie.getPath())); assertThat("GDCAuthSST", is(cookie.getName())); }
From source file:com.machinepublishers.jbrowserdriver.CookieStore.java
public void addCsrfHeaders(Settings settings, HttpRequestBase req) { final String reqHost = canonicalHost(req.getURI().getHost()); final String reqPath = canonicalPath(req.getURI().getPath()); final boolean reqSecure = isSecure(req.getURI().getScheme()); List<Cookie> list;// ww w. j ava2s . c o m synchronized (store) { list = store.getCookies(); } String csrfToken = null; for (Cookie cookie : list) { if ((!cookie.isSecure() || reqSecure) && reqHost.endsWith(canonicalHost(cookie.getDomain())) && reqPath.startsWith(canonicalPath(cookie.getPath()))) { if (SettingsManager.settings().getCsrfResponseToken() != null && cookie.getName().equalsIgnoreCase(SettingsManager.settings().getCsrfResponseToken())) { csrfToken = cookie.getValue(); break; } } } if (csrfToken != null) { req.addHeader(SettingsManager.settings().getCsrfRequestToken(), csrfToken); } }
From source file:com.machinepublishers.jbrowserdriver.CookieStore.java
/** * {@inheritDoc}/* w w w . j a v a 2s .co m*/ */ @Override public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException { final String reqHost = canonicalHost(uri.getHost()); final String reqPath = canonicalPath(uri.getPath()); final boolean reqSecure = isSecure(uri.getScheme()); final boolean reqJavascript = isJavascript(uri.getScheme()); StringBuilder builder = new StringBuilder(); if (reqJavascript) { List<Cookie> list; synchronized (store) { store.clearExpired(new Date()); list = store.getCookies(); } for (Cookie cookie : list) { if ((!cookie.isSecure() || reqSecure) && reqHost.endsWith(canonicalHost(cookie.getDomain())) && reqPath.startsWith(canonicalPath(cookie.getPath()))) { if (builder.length() > 0) { builder.append(';'); } builder.append(cookie.getName()); builder.append('='); builder.append(cookie.getValue()); } } } String cookies = builder.length() == 0 ? null : builder.toString(); Map<String, List<String>> map; if (cookies != null) { map = new HashMap<String, List<String>>(); map.put("Cookie", Arrays.asList(cookies)); } else { map = Collections.emptyMap(); } return map; }
From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java
public synchronized byte[] toByteArray() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); try {//from ww w. j av a2 s .c o m dos.writeInt(cookies.size()); for (final Cookie cookie : cookies) { dos.writeUTF(cookie.getName()); dos.writeUTF(cookie.getValue()); dos.writeUTF(cookie.getDomain()); dos.writeUTF(cookie.getPath()); dos.writeBoolean(cookie.isSecure()); } dos.flush(); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); }
From source file:botvn.libraries.StorageCookies.java
public boolean Save() { if (mCookieStore != null) { FileWriter file = null;//from w w w. j a v a2s . c om try { List<Cookie> ckss = mCookieStore.getCookies(); HashMap<String, Object> d; JSONArray allCks = new JSONArray(); for (Cookie cks : ckss) { d = new HashMap<>(ckss.size()); String name = cks.getName(); long expires = cks.getExpiryDate() != null ? cks.getExpiryDate().getTime() : 0; String path = cks.getPath(); String domain = cks.getDomain(); boolean secure = cks.isSecure(); d.put("name", name); d.put("expires", expires); d.put("path", path); d.put("domain", domain); d.put("secure", secure); allCks.add(d); } String jsonStr = allCks.toJSONString(); String currentDir = System.getProperty(USER_DIR); file = new FileWriter(currentDir + "/" + COOKIE_FILE); file.write(jsonStr); file.flush(); file.close(); return true; } catch (IOException ex) { Logger.getLogger(StorageCookies.class.getName()).log(Level.SEVERE, null, ex); } } return false; }