Example usage for javax.servlet.http Cookie setPath

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

Introduction

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

Prototype

public void setPath(String uri) 

Source Link

Document

Specifies a path for the cookie to which the client should return the cookie.

Usage

From source file:com.nkapps.billing.services.SearchServiceImpl.java

@Override
public String execSearchWithinDate(HttpServletRequest request, HttpServletResponse response) {
    Cookie sbtCookie = null;

    String searchWithinDate = request.getParameter("searchWithinDate");
    if (searchWithinDate == null) {
        Cookie[] requestCookies = request.getCookies();
        for (Cookie c : requestCookies) {
            if (c.getName().equals("searchWithinDate")) {
                sbtCookie = c;/* w  w  w  .j  a v a  2  s .c  o m*/
            }
        }
        if (sbtCookie != null) {
            searchWithinDate = sbtCookie.getValue();
        } else {
            searchWithinDate = "true";
        }
    } else {
        sbtCookie = new Cookie("searchWithinDate", searchWithinDate);
        sbtCookie.setPath("/");
        response.addCookie(sbtCookie);
    }
    return searchWithinDate;
}

From source file:com.expressui.core.MainApplication.java

/**
 * Adds a cookie to the HTTP response./*  ww w .  j a va2s.  c o  m*/
 *
 * @param name  name of the cookie
 * @param value value
 */
public void addCookie(String name, String value) {
    Cookie cookie = new Cookie(name, value);
    cookie.setPath("/");
    getResponse().addCookie(cookie);
}

From source file:org.josso.gateway.signon.SignonBaseAction.java

protected void removeJossoSessionId(HttpServletRequest request, HttpServletResponse response) {
    SSOContext ctx = SSOContext.getCurrent();

    try {/*ww  w .j a v a2 s .c o m*/
        SSOWebConfiguration cfg = Lookup.getInstance().lookupSSOWebConfiguration();

        if (cfg.isSessionTokenOnClient()) {
            Cookie ssoCookie = newJossoCookie(request.getContextPath(),
                    JOSSO_SINGLE_SIGN_ON_COOKIE + "_" + ctx.getSecurityDomain().getName(), "-");
            ssoCookie.setMaxAge(0);
            response.addCookie(ssoCookie);
        } else {
            HttpSession session = request.getSession();
            session.removeAttribute(JOSSO_SINGLE_SIGN_ON_COOKIE + "_" + ctx.getSecurityDomain().getName());
        }

        if (cfg.isRememberMeEnabled()) {

            // Clear the remember me cookie
            Cookie rememberMeCookie = new Cookie(Constants.JOSSO_REMEMBERME_TOKEN + "_"
                    + SSOContext.getCurrent().getSecurityDomain().getName(), "-");
            rememberMeCookie.setMaxAge(0);
            rememberMeCookie.setSecure(cfg.isSessionTokenSecure());
            rememberMeCookie.setPath("/");

            response.addCookie(rememberMeCookie);
        }
    } catch (Exception ex) {
        if (logger.isDebugEnabled())
            logger.debug("  [removeJossoSessionId()] cant find SSOWebConfiguration");
    }
}

From source file:com.spshop.web.ShoppingController.java

@RequestMapping(value = "/logout")
public String logout(Model model, HttpServletRequest request, HttpServletResponse response) {
    request.getSession().invalidate();//w w w  .  j  a  va 2  s . co  m
    model.addAttribute(LOGOUT_ACTION, Boolean.TRUE.toString());
    Cookie[] cookies = request.getCookies();
    if (null != cookies) {
        for (Cookie cookie : cookies) {
            if (COOKIE_ACCOUNT.equals(cookie.getName())) {
                cookie = new Cookie(COOKIE_ACCOUNT, EMPTY_STR);
                cookie.setPath("/");
                cookie.setMaxAge(30 * 24 * 60 * 60);
                response.addCookie(cookie);
            }
        }
    }
    return "redirect:" + getSiteView().getHost();
}

From source file:com.xpn.xwiki.user.impl.xwiki.MyPersistentLoginManager.java

/**
 * Remove a cookie./*w  w  w .j a va  2  s .co m*/
 * 
 * @param request The servlet request.
 * @param response The servlet response.
 * @param cookieName The name of the cookie that must be removed.
 */
private void removeCookie(HttpServletRequest request, HttpServletResponse response, String cookieName) {
    Cookie cookie = getCookie(request.getCookies(), cookieName);
    if (cookie != null) {
        cookie.setMaxAge(0);
        cookie.setPath(this.cookiePath);
        addCookie(response, cookie);
        String cookieDomain = getCookieDomain(request);
        if (cookieDomain != null) {
            cookie.setDomain(cookieDomain);
            addCookie(response, cookie);
        }
    }
}

From source file:com.qlkh.client.server.proxy.ProxyServlet.java

/**
 * Retrieves all of the cookies from the servlet request and sets them on
 * the proxy request//from   w  ww. j  ava  2s  .c  o  m
 *
 * @param httpServletRequest     The request object representing the client's
 *                               request to the servlet engine
 * @param httpMethodProxyRequest The request that we are about to send to
 *                               the proxy host
 */
@SuppressWarnings("unchecked")
private void setProxyRequestCookies(HttpServletRequest httpServletRequest, HttpMethod httpMethodProxyRequest) {
    // Get an array of all of all the cookies sent by the client
    Cookie[] cookies = httpServletRequest.getCookies();
    if (cookies == null) {
        return;
    }

    for (Cookie cookie : cookies) {
        cookie.setDomain(stringProxyHost);
        cookie.setPath(httpServletRequest.getServletPath());
        httpMethodProxyRequest.setRequestHeader("Cookie",
                cookie.getName() + "=" + cookie.getValue() + "; Path=" + cookie.getPath());
    }
}

From source file:org.eclipse.userstorage.tests.util.USSServer.java

protected void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Map<String, Object> requestObject = JSONUtil.parse(request.getInputStream(), null);

    String username = (String) requestObject.get("username");
    String password = (String) requestObject.get("password");

    User user = users.get(username);//from   w  w  w.  j  ava  2s . com
    if (user == null || password == null || !password.equals(user.getPassword())) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");

    Session session = addSession(user);
    Cookie cookie = new Cookie("SESSION", session.getID());
    cookie.setPath("/");
    response.addCookie(cookie);

    Map<String, Object> responseObject = new LinkedHashMap<String, Object>();
    responseObject.put("sessid", session.getID());
    responseObject.put("token", session.getCSRFToken());
    InputStream body = JSONUtil.build(responseObject);

    try {
        ServletOutputStream out = response.getOutputStream();
        IOUtil.copy(body, out);
        out.flush();
    } finally {
        IOUtil.closeSilent(body);
    }
}

From source file:com.nkapps.billing.services.SearchServiceImpl.java

@Override
public String execSearchByDate(HttpServletRequest request, HttpServletResponse response) {
    Cookie sbdCookie = null;

    String searchByDate = request.getParameter("searchByDate");
    if (searchByDate == null) {
        Cookie[] requestCookies = request.getCookies();
        for (Cookie c : requestCookies) {
            if (c.getName().equals("searchByDate")) {
                sbdCookie = c;/*from   ww w  .j av a2  s  . c om*/
            }
        }
        if (sbdCookie != null) {
            searchByDate = sbdCookie.getValue();
        } else {
            searchByDate = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime());
        }
    } else {
        sbdCookie = new Cookie("searchByDate", searchByDate);
        sbdCookie.setPath("/");
        response.addCookie(sbdCookie);
    }
    return searchByDate;
}

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

@RequestMapping(value = { "/{userParam}/loggedout", "{userParam}/j_spring_security_logout" })
public String loggedout(@PathVariable String userParam, ModelMap map, HttpSession session,
        HttpServletResponse response, HttpServletRequest request) {
    logger.debug("###Entering in loggedout(response) method");
    String showSuffixControl = "false";
    String suffixControlType = "textbox";
    List<String> suffixList = null;
    if (config.getValue(Names.com_citrix_cpbm_username_duplicate_allowed).equals("true")) {
        showSuffixControl = "true";
        if (config.getValue(Names.com_citrix_cpbm_login_screen_tenant_suffix_dropdown_enabled).equals("true")) {
            suffixControlType = "dropdown";
            suffixList = tenantService.getSuffixList();
        }//from  w w  w.  j  a  va  2  s  . c  om
    }
    map.addAttribute("showSuffixControl", showSuffixControl);
    map.addAttribute("suffixControlType", suffixControlType);
    map.addAttribute("suffixList", suffixList);
    if (config.getBooleanValue(Configuration.Names.com_citrix_cpbm_portal_directory_service_enabled)
            && config.getValue(Names.com_citrix_cpbm_directory_mode).equals("pull")) {
        map.addAttribute("directoryServiceAuthenticationEnabled", "true");
    }
    if (config.getValue(Names.com_citrix_cpbm_public_catalog_display).equals("true")
            && channelService.getDefaultServiceProviderChannel() != null) {
        map.addAttribute("showAnonymousCatalogBrowsing", "true");
    }
    map.addAttribute("showLanguageSelection", "true");
    map.addAttribute("supportedLocaleList", this.getLocaleDisplayName(listSupportedLocales()));
    map.addAttribute("logout", true);
    String redirect = null;
    Enumeration<String> en = session.getAttributeNames();
    while (en.hasMoreElements()) {
        String attr = en.nextElement();
        session.removeAttribute(attr);
    }
    Cookie cookie = new Cookie("JforumSSO", "");
    cookie.setMaxAge(0);
    cookie.setPath("/");
    response.addCookie(cookie);
    if (request.getRequestedSessionId() != null && request.isRequestedSessionIdValid()) {
        // create logout notification begins
        User user = userService.get(userParam);
        String message = "logged.out";
        String messageArgs = user.getUsername();
        eventService.createEvent(new Date(), user, message, messageArgs, Source.PORTAL, Scope.USER,
                Category.ACCOUNT, Severity.INFORMATION, true);
    }
    session.invalidate();
    if (config.getAuthenticationService().compareToIgnoreCase(CAS) == 0) {
        try {
            redirect = StringUtils.isEmpty(config.getCasLogoutUrl()) ? null
                    : config.getCasLogoutUrl() + "?service="
                            + URLEncoder.encode(config.getCasServiceUrl(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("Exception encoding: " + redirect, e);
        }
        if (redirect == null) {
            throw new InternalError("CAS authentication required, but login url not set");
        }
    }

    SecurityContextHolder.getContext().setAuthentication(null);
    // ends
    logger.debug("###Exiting loggedout(response) method");
    return redirect == null ? "redirect:/j_spring_security_logout" : "redirect:" + redirect;
}