Example usage for javax.servlet.http Cookie getSecure

List of usage examples for javax.servlet.http Cookie getSecure

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getSecure.

Prototype

public boolean getSecure() 

Source Link

Document

Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.

Usage

From source file:com.google.gsa.valve.modules.utils.CookieManagement.java

/**
 * Transforms Servlet cookies into Apache Cookies
 * /*from   w w w.j a  va2s  . c  o m*/
 * @param servletCookie servlet cookie
 * 
 * @return apache cookie
 */
public static org.apache.commons.httpclient.Cookie transformServletCookie(
        javax.servlet.http.Cookie servletCookie) {

    org.apache.commons.httpclient.Cookie newCookie = null;

    if (servletCookie != null) {
        newCookie = new org.apache.commons.httpclient.Cookie(servletCookie.getDomain(), servletCookie.getName(),
                servletCookie.getValue(), servletCookie.getPath() != null ? servletCookie.getPath() : "/",
                servletCookie.getMaxAge(), servletCookie.getSecure());
    }
    return newCookie;
}

From source file:net.bluehornreader.web.WebUtils.java

public static String cookieAsString(Cookie cookie) {
    StringBuilder bld = new StringBuilder();
    bld.append("Name=").append(cookie.getName()).append(" ");
    bld.append("Value=").append(cookie.getValue()).append(" ");
    bld.append("Domain=").append(cookie.getDomain()).append(" ");
    bld.append("MaxAge=").append(cookie.getMaxAge()).append(" ");
    bld.append("Path=").append(cookie.getPath()).append(" ");
    bld.append("Secure=").append(cookie.getSecure()).append(" ");
    bld.append("Comment=").append(cookie.getComment()).append(" ");
    bld.append("Version=").append(cookie.getVersion()).append(" ");
    return bld.toString().trim();
}

From source file:org.springframework.test.web.servlet.htmlunit.MockWebResponseBuilder.java

static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) {
    Date expires = null;//from   ww  w . ja  v  a 2 s  .  co  m
    if (cookie.getMaxAge() > -1) {
        expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000);
    }
    BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue());
    result.setDomain(cookie.getDomain());
    result.setComment(cookie.getComment());
    result.setExpiryDate(expires);
    result.setPath(cookie.getPath());
    result.setSecure(cookie.getSecure());
    if (cookie.isHttpOnly()) {
        result.setAttribute("httponly", "true");
    }
    return new com.gargoylesoftware.htmlunit.util.Cookie(result);
}

From source file:de.betterform.agent.web.WebUtil.java

private static Vector<BasicClientCookie> saveAsBasicClientCookie(Iterator iterator,
        Vector<BasicClientCookie> commonsCookies) {
    while (iterator.hasNext()) {
        javax.servlet.http.Cookie c = (Cookie) iterator.next();
        BasicClientCookie commonsCookie = new BasicClientCookie(c.getName(), c.getValue());
        commonsCookie.setDomain(c.getDomain());
        commonsCookie.setPath(c.getPath());
        commonsCookie.setAttribute(ClientCookie.MAX_AGE_ATTR, Integer.toString(c.getMaxAge()));
        commonsCookie.setSecure(c.getSecure());

        commonsCookies.add(commonsCookie);

        if (WebUtil.LOGGER.isDebugEnabled()) {
            WebUtil.LOGGER.debug("adding cookie >>>>>");
            WebUtil.LOGGER.debug("name: " + c.getName());
            WebUtil.LOGGER.debug("value: " + c.getValue());
            WebUtil.LOGGER.debug("path: " + c.getPath());
            WebUtil.LOGGER.debug("maxAge: " + c.getMaxAge());
            WebUtil.LOGGER.debug("secure: " + c.getSecure());
            WebUtil.LOGGER.debug("adding cookie done <<<<<");
        }//w ww. ja va  2s  . c  om
    }

    return commonsCookies;
}

From source file:RequestUtil.java

/**
 * Encode a cookie as per RFC 2109. The resulting string can be used as the
 * value for a <code>Set-Cookie</code> header.
 * //  ww  w .  j  a  v  a2s. c  o m
 * @param cookie
 *            The cookie to encode.
 * @return A string following RFC 2109.
 */
public static String encodeCookie(Cookie cookie) {

    StringBuffer buf = new StringBuffer(cookie.getName());
    buf.append("=");
    buf.append(cookie.getValue());

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

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

    if (cookie.getMaxAge() >= 0) {
        buf.append("; Max-Age=\"");
        buf.append(cookie.getMaxAge());
        buf.append("\"");
    }

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

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

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

    return (buf.toString());
}

From source file:org.codemucker.testserver.capturing.CapturedCookie.java

public CapturedCookie(Cookie c) {
    domain = c.getDomain();//from w  ww . ja v  a 2  s .com
    path = c.getPath();
    name = c.getName();
    value = c.getValue();
    secure = c.getSecure();
    maxAge = c.getMaxAge();
    version = c.getVersion();
}

From source file:gr.abiss.calipso.web.filters.RestRequestNormalizerFilter.java

protected String getCookieToken(HttpServletRequest httpRequest) {
    String authToken = null;//from www. ja va 2s . c  om
    Cookie[] cookies = httpRequest.getCookies();
    String ssoCookieName = userDetailsConfig.getCookiesBasicAuthTokenName();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found cookie '" + cookie.getName() + "', secure:  " + cookie.getSecure()
                        + ", comment: " + cookie.getComment() + ", domain: " + cookie.getDomain() + ", value: "
                        + cookie.getValue());
            }
            if (cookie.getName().equalsIgnoreCase(ssoCookieName)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Matched calipso SSO cookie'" + cookie.getName() + "', secure:  "
                            + cookie.getSecure() + ", comment: " + cookie.getComment() + ", domain: "
                            + cookie.getDomain() + ", value: " + cookie.getValue());
                }
                authToken = cookie.getValue();
                break;
            }
        }
        if (LOGGER.isDebugEnabled() && authToken == null) {
            LOGGER.debug("Found no calipso SSO cookie with name: " + ssoCookieName);

        }
    }
    return authToken;
}

From source file:com.google.acre.script.AcreCookie.java

public AcreCookie(Cookie servlet_cookie) {
    name = servlet_cookie.getName();//from w  w w  . jav  a  2 s. co m
    value = servlet_cookie.getValue();
    domain = servlet_cookie.getDomain();
    path = servlet_cookie.getPath();
    secure = servlet_cookie.getSecure();
    max_age = servlet_cookie.getMaxAge();
}

From source file:com.acc.storefront.security.cookie.EnhancedCookieGenerator.java

@Override
public void addCookie(final HttpServletResponse response, final String cookieValue) {
    super.addCookie(new HttpServletResponseWrapper(response) {
        @Override/* w  ww  .ja  v a2 s .c o m*/
        public void addCookie(final Cookie cookie) {
            setEnhancedCookiePath(cookie);

            if (isHttpOnly()) {
                // Custom code to write the cookie including the httpOnly flag
                final StringBuffer headerBuffer = new StringBuffer(100);
                ServerCookie.appendCookieValue(headerBuffer, cookie.getVersion(), cookie.getName(),
                        cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(),
                        cookie.getMaxAge(), cookie.getSecure(), true);
                response.addHeader(HEADER_COOKIE, headerBuffer.toString());
            } else {
                // Write the cookie as normal
                super.addCookie(cookie);
            }
        }
    }, cookieValue);
}

From source file:AIR.Common.Web.Session.MultiValueCookie.java

public MultiValueCookie(Cookie cookie) {
    this._name = cookie.getName();
    //Shiva: we can limit the code to the else part rather than have 
    //the "if" part as well. The if part is there just for safety.
    if (StringUtils.isEmpty(cookie.getPath()))
        this._path = Server.getContextPath();
    else//w w  w.j  av a  2  s.c  o m
        this._path = cookie.getPath();
    this._comment = cookie.getComment();
    this._domain = cookie.getDomain();
    this._isSecure = cookie.getSecure();
    this._encodedValue = cookie.getValue();
    this._cookie = cookie;
    deserializeCookieValue();
}