Example usage for java.net HttpCookie getSecure

List of usage examples for java.net HttpCookie getSecure

Introduction

In this page you can find the example usage for java.net HttpCookie getSecure.

Prototype

public boolean getSecure() 

Source Link

Document

Returns true if sending this cookie should be restricted to a secure protocol, or false if the it can be sent using any protocol.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println(cookie.getSecure());
        System.out.println();//from   w  w  w  . ja  va  2 s.co  m
    }
}

From source file:keywhiz.cli.JsonCookie.java

public static JsonCookie fromHttpCookie(HttpCookie cookie) {
    return JsonCookie.create(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
            cookie.getSecure(), cookie.isHttpOnly());
}

From source file:io.druid.security.kerberos.DruidKerberosUtil.java

public static HttpCookie getAuthCookie(CookieStore cookieStore, URI uri) {
    if (cookieStore == null) {
        return null;
    }/*from   w  ww  .ja  v  a2 s  .  c  o m*/
    boolean isSSL = uri.getScheme().equals("https");
    List<HttpCookie> cookies = cookieStore.getCookies();

    for (HttpCookie 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.getSecure() && !isSSL) {
            continue;
        }
        if (c.getName().equals(AuthenticatedURL.AUTH_COOKIE)) {
            return c;
        }
    }
    return null;
}

From source file:cn.ttyhuo.common.MyApplication.java

public static void setUpPersistentCookieStore() {
    if (context == null)
        return;//  w ww. ja va2 s . c o m
    cookieStore = new PersistentCookieStore(context);

    CookieStore httpCookieStore = HttpRequestUtil.cookieManager.getCookieStore();
    for (HttpCookie h : httpCookieStore.getCookies()) {
        BasicClientCookie newCookie = new BasicClientCookie(h.getName(), h.getValue());
        newCookie.setVersion(h.getVersion());
        newCookie.setDomain(h.getDomain());
        newCookie.setPath(h.getPath());
        newCookie.setSecure(h.getSecure());
        newCookie.setComment(h.getComment());
        cookieStore.addCookie(newCookie);
    }
}

From source file:com.github.parisoft.resty.utils.CookieUtils.java

public static String toString(HttpCookie... cookies) {
    if (isEmpty(cookies)) {
        return null;
    }/*from w w w  .j a v  a 2s  .c  o  m*/

    final StringBuilder cookieBuilder = new StringBuilder();

    for (HttpCookie cookie : cookies) {
        cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue());

        if (cookie.getComment() != null) {
            cookieBuilder.append(";").append("Comment=").append(cookie.getComment());
        }

        if (cookie.getDomain() != null) {
            cookieBuilder.append(";").append("Domain=").append(cookie.getDomain());
        }

        if (cookie.getPath() != null) {
            cookieBuilder.append(";").append("Path=").append(cookie.getPath());
        }

        if (cookie.getSecure()) {
            cookieBuilder.append(";").append("Secure");
        }

        if (cookie.isHttpOnly()) {
            cookieBuilder.append(";").append("HttpOnly");
        }

        if (cookie.getVersion() > 0) {
            cookieBuilder.append(";").append("Version=").append(cookie.getVersion());
        }

        if (cookie.hasExpired()) {
            cookieBuilder.append(";").append("Max-Age=0");
        } else {
            cookieBuilder.append(";").append("Max-Age=").append(cookie.getMaxAge());
        }

        cookieBuilder.append(", ");
    }

    return cookieBuilder.deleteCharAt(cookieBuilder.length() - 1).toString();
}

From source file:java.net.HttpCookie.java

/**
 * Returns true if {@code cookie} should be sent to {@code uri} with respect to the cookie's
 * secure attribute. Secure cookies should not be sent in insecure (ie. non-HTTPS) requests.
 *///from  www  .  jav a2s .co m
static boolean secureMatches(HttpCookie cookie, URI uri) {
    return !cookie.getSecure() || "https".equalsIgnoreCase(uri.getScheme());
}

From source file:at.becast.youploader.youtube.data.Cookie.java

public Cookie(final HttpCookie cookie) {
    name = cookie.getName();/*  w  w w.  j  a  v a  2s  .  c  o  m*/
    value = cookie.getValue();
    comment = cookie.getComment();
    commentUrl = cookie.getCommentURL();
    domain = cookie.getDomain();
    discard = cookie.getDiscard();
    maxAge = cookie.getMaxAge();
    path = cookie.getPath();
    portList = cookie.getPortlist();
    secure = cookie.getSecure();
    version = cookie.getVersion();
}

From source file:com.nominanuda.web.http.ServletHelper.java

public Cookie servletCookie(HttpCookie c) {
    Cookie _c = new Cookie(c.getName(), c.getValue());
    if (c.getComment() != null) {
        _c.setComment(c.getComment());//from   w w w .jav  a2s .c  o  m
    }
    if (c.getDomain() != null) {
        _c.setDomain(c.getDomain());
    }
    if (c.getPath() != null) {
        _c.setPath(c.getPath());
    }
    _c.setSecure(c.getSecure());
    _c.setVersion(c.getVersion());
    _c.setHttpOnly(c.getDiscard());
    _c.setMaxAge((int) c.getMaxAge());
    return _c;
}

From source file:io.mapzone.controller.vm.http.HttpResponseForwarder.java

/**
 * Copy cookie from the proxy to the servlet client. Replaces cookie path to
 * local path and renames cookie to avoid collisions.
 *//*ww w.  ja  v a 2s . co  m*/
protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        Header header) {
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = servletRequest.getContextPath(); // path starts with / or is empty string
    path += servletRequest.getServletPath(); // servlet path starts with / or is empty string

    for (HttpCookie cookie : cookies) {
        // set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = requestForwarder.cookieNamePrefix.get() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); // set to the path of the proxy servlet
        // don't set cookie domain
        servletCookie.setSecure(cookie.getSecure());
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}

From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java

private Cookie toCookie(URI uri, HttpCookie httpCookie) {
    SetCookie cookie = new BasicClientCookie(httpCookie.getName(), httpCookie.getValue());
    cookie.setComment(httpCookie.getComment());
    if (httpCookie.getDomain() != null) {
        cookie.setDomain(httpCookie.getDomain());
    } else {//w  w  w .  j av a 2  s .  c  o  m
        cookie.setDomain(uri.getHost());
    }
    if (httpCookie.getMaxAge() != -1) {
        cookie.setExpiryDate(new Date(httpCookie.getMaxAge() * 1000));
    }
    if (httpCookie.getPath() != null) {
        cookie.setPath(httpCookie.getPath());
    } else {
        cookie.setPath(uri.getPath());
    }
    cookie.setSecure(httpCookie.getSecure());
    cookie.setVersion(httpCookie.getVersion());
    return cookie;
}