Example usage for javax.servlet.http Cookie getDomain

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

Introduction

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

Prototype

public String getDomain() 

Source Link

Document

Gets the domain name of this Cookie.

Usage

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

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

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

public CapturedCookie(org.apache.http.cookie.Cookie c) {
    domain = c.getDomain();
    path = c.getPath();// w ww  . j a v  a 2 s .  c o  m
    name = c.getName();
    value = c.getValue();
    secure = c.isSecure();
    maxAge = c.getExpiryDate() == null ? -1 : 0;
    version = c.getVersion();
}

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

public AcreCookie(Cookie servlet_cookie) {
    name = servlet_cookie.getName();/*www.j  a v  a2 s . c o 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.google.acre.script.AcreCookie.java

public AcreCookie(org.apache.http.cookie.Cookie c) {
    name = c.getName();/*from w  w  w. java2 s  .  co  m*/
    value = c.getValue();
    secure = c.isSecure();
    domain = c.getDomain();
    path = c.getPath();
    max_age = -1;
    // XXX translate into max-age?
    // c.getExpiryDate();
}

From source file:com.anjz.util.CookieUtils.java

private static void getCookieHeaderValue(final Cookie cookie, final StringBuffer buf, final boolean httpOnly) {
    final int version = cookie.getVersion();

    // this part is the same for all cookies

    String name = cookie.getName(); // Avoid NPE on malformed cookies
    if (name == null) {
        name = "";
    }//from ww  w  .j  a  v  a 2 s  . c o  m
    String value = cookie.getValue();
    if (value == null) {
        value = "";
    }

    buf.append(name);
    buf.append("=");

    maybeQuote(version, buf, value);

    // add version 1 specific information
    if (version == 1) {
        // Version=1 ... required
        buf.append("; Version=1");

        // Comment=comment
        if (cookie.getComment() != null) {
            buf.append("; Comment=");
            maybeQuote(version, buf, cookie.getComment());
        }
    }

    // add domain information, if present

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

    // Max-Age=secs/Discard ... or use old "Expires" format
    if (cookie.getMaxAge() >= 0) {
        if (version == 0) {
            buf.append("; Expires=");
            SimpleDateFormat dateFormat = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); //GMT?
            if (cookie.getMaxAge() == 0) {
                dateFormat.format(new Date(10000), buf, new FieldPosition(0));
            } else {
                dateFormat.format(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L), buf,
                        new FieldPosition(0));
            }
        } else {
            buf.append("; Max-Age=");
            buf.append(cookie.getMaxAge());
        }
    } else if (version == 1) {
        buf.append("; Discard");
    }

    // Path=path
    if (cookie.getPath() != null) {
        buf.append("; Path=");
        maybeQuote(version, buf, cookie.getPath());
    }

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

    // HttpOnly
    if (httpOnly) {
        buf.append("; HttpOnly");
    }
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractManageResourceController.java

@RequestMapping(value = "/get_sso_cmd_string", method = RequestMethod.POST)
@ResponseBody// www.j av  a2  s .  c  o m
public Map<String, String> getSSOCmdString(@ModelAttribute("currentTenant") Tenant tenant,
        @RequestParam(value = "tenant", required = false) String tenantParam,
        @RequestParam(value = "serviceInstanceUUID", required = true) String serviceInstanceUUID, ModelMap map,
        HttpServletRequest request, HttpServletResponse response) {

    logger.debug("### In getSSOCmdString  start method (POST)...");
    SsoObject ssoObject = new SsoObject();
    Tenant userTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY);
    Map<String, String> responseMap = new HashMap<String, String>();
    if (userTenant.getState() == Tenant.State.NEW) {
        responseMap.put("status", "fail");
        if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
            responseMap.put("error_message",
                    messageSource.getMessage("message.user.no.billing", null, getSessionLocale(request)));
            responseMap.put("url", "/portal/portal/home");
        } else {
            responseMap.put("url", "/portal/portal/tenants/editcurrent");
        }
    } else {
        // if user logged in as root and try to access cloud resources under specific account then using the specific
        // account and account owner.
        SsoHandler ssoHandler = ((CloudConnector) connectorManagementService
                .getServiceInstance(serviceInstanceUUID)).getSSOHandler();
        if (ssoHandler != null) {
            if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + userTenant.getOwner());
                ssoObject = ssoHandler.handleLogin(userTenant.getOwner());
                logger.trace("###SPI Called SsoHandler.handleLogin(User) for user:" + userTenant.getOwner());
            } else {
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + getCurrentUser());
                ssoObject = ssoHandler.handleLogin(getCurrentUser());
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + getCurrentUser());
            }
            if (ssoObject != null && ssoObject.getCookies().size() > 0) {
                for (Cookie cookie : ssoObject.getCookies()) {
                    response.addCookie(cookie);
                    logger.debug("Sending cookies:" + cookie.getName() + " domain:" + cookie.getDomain());
                }
            }
            responseMap.put("callback", ssoObject.getCallBack());
            responseMap.put("status", "success");
            responseMap.put("cmdString", ssoObject.getSsoString());
        } else {
            // if a connector is not implementing a ssoHandler, return success
            responseMap.put("status", "success");
        }
    }
    logger.debug("### getSSOCmdString method ending...(POST)");
    return responseMap;
}

From source file:org.iwethey.forums.web.HeaderInterceptor.java

/**
 * Load the request attributes with the User object (if authenticated)
 * and start time for the page for audit purposes.
 * <p>/*  w  w w.j a va2  s.co  m*/
 * @param request The servlet request object.
 * @param response The servlet response object.
 * @param handler The request handler processing this request.
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    Date now = new Date();
    request.setAttribute("now", now);

    long start = now.getTime();
    request.setAttribute("start", new Long(start));

    Integer id = (Integer) WebUtils.getSessionAttribute(request, USER_ID_ATTRIBUTE);

    User user = null;

    if (id == null) {
        user = (User) WebUtils.getSessionAttribute(request, USER_ATTRIBUTE);

        if (user == null) {
            user = new User("Anonymous");
            WebUtils.setSessionAttribute(request, USER_ATTRIBUTE, user);
        }
    } else {
        user = mUserManager.getUserById(id.intValue());
        user.setLastPresent(new Date());
        mUserManager.saveUserAttributes(user);
    }

    request.setAttribute("username", user.getNickname());
    request.setAttribute(USER_ATTRIBUTE, user);

    System.out.println("Local Address  = [" + request.getLocalAddr() + "]");
    System.out.println("Local Name     = [" + request.getLocalName() + "]");
    System.out.println("Remote Address = [" + request.getRemoteAddr() + "]");
    System.out.println("Remote Host    = [" + request.getRemoteHost() + "]");
    System.out.println("Remote Port    = [" + request.getRemotePort() + "]");
    System.out.println("Remote User    = [" + request.getRemoteUser() + "]");
    System.out.println("Context Path   = [" + request.getContextPath() + "]");
    System.out.println("====================");

    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];

            System.out.println("Cookie Domain = [" + cookie.getDomain() + "]");
            System.out.println("Cookie Name   = [" + cookie.getName() + "]");
            System.out.println("Cookie Value  = [" + cookie.getValue() + "]");
            System.out.println("Cookie Expire = [" + cookie.getMaxAge() + "]");
            System.out.println("====================");

            if ("iwt_cookie".equals(cookie.getName())) {
                cookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6);
                response.addCookie(cookie);
            }
        }
    } else {
        System.out.println("No cookies were found in the request");
    }

    Cookie newCookie = new Cookie("iwt_cookie", "harrr2!");
    newCookie.setPath(request.getContextPath());
    newCookie.setDomain(request.getLocalName());
    newCookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6);
    response.addCookie(newCookie);

    request.setAttribute(HEADER_IMAGE_ATTRIBUTE, "/images/iwethey-lrpd-small.png");

    return true;
}

From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseDispatchAction.java

protected ActionForward dispatchMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String name) throws Exception {

    String user = null;// w w  w  .  ja v  a 2  s  .c o  m
    Cookie[] cookieArray = request.getCookies();
    if (cookieArray != null) {
        for (int i = 0; i < cookieArray.length; i++) {
            Cookie c = cookieArray[i];
            if (c.getName().equals("ADMIN_TOOL_USER")) {
                user = c.getValue();
                System.out.println("Reading username from cookie :" + user);
                System.out.println("Domain: " + c.getDomain());
                System.out.println("Path: " + c.getPath());
            }
        }
    }
    if (user == null) {
        return mapping.findForward("login");
    }
    return super.dispatchMethod(mapping, form, request, response, name);
}

From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String user = null;/* w w w  .j a va2  s  .c  o  m*/
    Cookie[] cookieArray = request.getCookies();
    if (cookieArray != null) {
        for (int i = 0; i < cookieArray.length; i++) {
            Cookie c = cookieArray[i];
            if (c.getName().equals("ADMIN_TOOL_USER")) {
                user = c.getValue();
                System.out.println("Reading username from cookie :" + user);
                System.out.println("Domain: " + c.getDomain());
                System.out.println("Path: " + c.getPath());
            }
        }
    }
    if (user == null) {
        return mapping.findForward("login");
    }

    return executeAction(mapping, form, request, response);
}

From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    // debug informations
    log.debug("doGet");
    log.debug("context path: " + request.getContextPath());
    log.debug("character encoding: " + request.getCharacterEncoding());
    log.debug("content length: " + request.getContentLength());
    log.debug("content type: " + request.getContentType());
    log.debug("local addr: " + request.getLocalAddr());
    log.debug("local name: " + request.getLocalName());
    log.debug("local port: " + request.getLocalPort());
    log.debug("method: " + request.getMethod());
    log.debug("path info: " + request.getPathInfo());
    log.debug("path translated: " + request.getPathTranslated());
    log.debug("protocol: " + request.getProtocol());
    log.debug("query string: " + request.getQueryString());
    log.debug("requested session id: " + request.getRequestedSessionId());
    log.debug("Host header: " + request.getServerName());
    log.debug("servlet path: " + request.getServletPath());
    log.debug("request URI: " + request.getRequestURI());
    @SuppressWarnings("unchecked")
    final Enumeration<String> header_names = request.getHeaderNames();
    while (header_names.hasMoreElements()) {
        final String header_name = header_names.nextElement();
        log.debug("header name: " + header_name);
        @SuppressWarnings("unchecked")
        final Enumeration<String> header_values = request.getHeaders(header_name);
        while (header_values.hasMoreElements())
            log.debug("  " + header_name + " => " + header_values.nextElement());
    }//from   ww w .ja v  a  2s . c  om
    if (request.getCookies() != null)
        for (Cookie cookie : request.getCookies()) {
            log.debug("cookie:");
            log.debug("cookie comment: " + cookie.getComment());
            log.debug("cookie domain: " + cookie.getDomain());
            log.debug("cookie max age: " + cookie.getMaxAge());
            log.debug("cookie name: " + cookie.getName());
            log.debug("cookie path: " + cookie.getPath());
            log.debug("cookie value: " + cookie.getValue());
            log.debug("cookie version: " + cookie.getVersion());
            log.debug("cookie secure: " + cookie.getSecure());
        }
    @SuppressWarnings("unchecked")
    final Enumeration<String> parameter_names = request.getParameterNames();
    while (parameter_names.hasMoreElements()) {
        final String parameter_name = parameter_names.nextElement();
        log.debug("parameter name: " + parameter_name);
        final String[] parameter_values = request.getParameterValues(parameter_name);
        for (final String parameter_value : parameter_values)
            log.debug("  " + parameter_name + " => " + parameter_value);
    }

    // parse request

    String target_scheme = null;
    String target_host;
    int target_port;

    // request.getPathInfo() is url decoded
    final String[] path_info_parts = request.getPathInfo().split("/");
    if (path_info_parts.length >= 2)
        target_scheme = path_info_parts[1];
    if (path_info_parts.length >= 3) {
        target_host = path_info_parts[2];
        try {
            if (path_info_parts.length >= 4)
                target_port = new Integer(path_info_parts[3]);
            else
                target_port = 80;
        } catch (final NumberFormatException ex) {
            log.warn(ex);
            target_port = 80;
        }
    } else {
        target_scheme = "http";
        target_host = "www.google.com";
        target_port = 80;
    }

    log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port);

    // create forwarding request

    final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port);
    final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection();

    // be transparent for accept-language headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_languages = request.getHeaders("accept-language");
    while (accepted_languages.hasMoreElements())
        target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement());

    // be transparent for accepted headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_content = request.getHeaders("accept");
    while (accepted_content.hasMoreElements())
        target_connection.setRequestProperty("Accept", accepted_content.nextElement());

}