Example usage for javax.servlet.http Cookie Cookie

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

Introduction

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

Prototype

public Cookie(String name, String value) 

Source Link

Document

Constructs a cookie with the specified name and value.

Usage

From source file:cn.vlabs.umt.ui.servlet.login.LoginMethod.java

public static void generateAutoFill(HttpServletResponse response, HttpServletRequest request,
        LoginInfo loginInfo) {//from  w  w w.j  a  va  2s  .co m
    Cookie autoFill = new Cookie(Attributes.AUTO_FILL, loginInfo.getLoginNameInfo().getLoginName());
    autoFill.setPath("/");
    autoFill.setMaxAge(Integer.MAX_VALUE);
    response.addCookie(autoFill);
}

From source file:com.lushapp.common.web.utils.WebUtils.java

/**
 * cookie./*  ww w . j  a  v  a2  s  .  c  o m*/
 * @param response
 * @param name
 * @param value
 * @param path
 */
public static void setCookie(HttpServletResponse response, String name, String value, String path) {
    if (logger.isDebugEnabled()) {
        logger.debug("Cookie '" + name + "',?: '" + path + "'");
    }

    Cookie cookie = new Cookie(name, value);
    cookie.setSecure(false);
    cookie.setPath(path);
    cookie.setMaxAge(2592000);

    response.addCookie(cookie);
}

From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java

private String addCookie(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final String cookieName, final String cookieValue) {
    if (httpRequest == null || httpResponse == null || cookieName == null || cookieValue == null) {
        throw new PreconditionException("Required parameter is null");
    }/*w  w w .  j a v a 2 s .  c o  m*/
    final Cookie cookie = new Cookie(cookieName, "");
    cookie.setValue(cookieValue);
    cookie.setMaxAge(-1);
    cookie.setSecure(true);
    cookie.setDomain(httpRequest.getServerName());
    cookie.setPath("/");
    cookie.setHttpOnly(true);
    httpResponse.addCookie(cookie);
    return cookie.getValue();
}

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

@RequestMapping(value = "/logout")
public String logout(Model model, HttpServletRequest request, HttpServletResponse response) {
    request.getSession().invalidate();/*from  ww w  .j a  v  a 2s  .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:azkaban.webapp.servlet.LoginAbstractAzkabanServlet.java

protected void handleAjaxLoginAction(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> ret)
        throws ServletException {
    if (hasParam(req, "username") && hasParam(req, "password")) {
        Session session = null;//from ww  w. ja  v a 2s .  c o  m
        try {
            session = createSession(req);
        } catch (UserManagerException e) {
            ret.put("error", "Incorrect Login. " + e.getMessage());
            return;
        }

        Cookie cookie = new Cookie(SESSION_ID_NAME, session.getSessionId());
        cookie.setPath("/");
        resp.addCookie(cookie);
        getApplication().getSessionCache().addSession(session);
        ret.put("status", "success");
        ret.put("session.id", session.getSessionId());
    } else {
        ret.put("error", "Incorrect Login.");
    }
}

From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java

/**
 * set a paris connect cokkie in the HttpServletResponse
 *
 * @param strPCUID/*from   w ww  . jav a  2s .  co m*/
 *            the user PCUID
 * @param response
 *            The HTTP response
 */
public void setConnectionCookie(String strPCUID, HttpServletResponse response) {
    // set a connexion cookie to let the user access other PC Services
    // without sign in
    Cookie openamCookie = new Cookie(COOKIE_OPENAM_NAME, strPCUID);
    openamCookie.setDomain(COOKIE_OPENAM_DOMAIN);
    openamCookie.setSecure(COOKIE_OPENAM_SECURE);
    openamCookie.setMaxAge(COOKIE_OPENAM_MAX_AGE);
    openamCookie.setPath(COOKIE_OPENAM_PATH);

    response.addCookie(openamCookie);
}

From source file:com.vmware.identity.samlservice.Shared.java

/**
 * Adding a browser session cookie to browser.
 * @param cookieName//from w w w . j a  v  a 2s  .c om
 * @param cookieValue
 * @param response
 */
public static void addSessionCookie(String cookieName, String cookieValue, HttpServletResponse response) {
    Validate.notNull(response);
    if (cookieName == null || cookieName.isEmpty() || cookieValue == null || cookieValue.isEmpty()) {
        log.warn("Cookie name/value is null or empty. Ignoring.");
        return;
    }
    log.debug("Setting cookie " + cookieName + " value " + cookieValue);
    Cookie sessionCookie = new Cookie(cookieName, cookieValue);
    sessionCookie.setPath("/");
    sessionCookie.setSecure(true);
    sessionCookie.setHttpOnly(true);
    response.addCookie(sessionCookie);
}

From source file:com.netspective.sparx.security.HttpLoginManager.java

public void logout(HttpServletValueContext vc) {
    vc.getProject().getScrollStates().removeActiveState(vc);

    if (isAllowRememberUserId()) {
        Cookie cookie = new Cookie(getRememberUserIdCookieName(), "");
        cookie.setPath(getRememberPasswordCookiePath(vc));
        cookie.setMaxAge(-1);//w  ww . j  a  v  a 2s.c  om
        vc.getHttpResponse().addCookie(cookie);
        cookie = new Cookie(getRememberPasswordCookieName(), "");
        cookie.setPath(getRememberPasswordCookiePath(vc));
        cookie.setMaxAge(-1);
        vc.getHttpResponse().addCookie(cookie);
    }

    final HttpServletRequest req = vc.getHttpRequest();
    final MutableAuthenticatedUser user = (MutableAuthenticatedUser) getAuthenticatedUser(req);
    final HttpSession session = req.getSession();
    if (user != null) {
        registerLogout(vc, user);
        session.removeAttribute(getAuthenticatedUserSessionAttrName());
    }
    session.invalidate();
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static void setBuildInfoCookie(HttpServletResponse response, String buildName) {
    response.addCookie(new Cookie(BUILD_INFO_COOKIE, buildName));
}

From source file:com.ctc.storefront.controllers.misc.AddToCartController.java

private void setCookie(final HttpServletResponse response, final CartData cartData) {
    final Cookie cookie = new Cookie("cartQuantity", String.valueOf(cartData.getTotalUnitCount()));
    cookie.setMaxAge(60 * 60);//from  ww  w . jav  a 2  s .c om
    cookie.setPath("/");
    cookie.setDomain(siteConfigService.getString(CART_COUNT_COOKIE_DOMAIN_NAME, ".ctc.com"));
    response.addCookie(cookie);
}