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:com.music.web.SocialSignInAdapter.java

public void addPermanentCookies(User user, HttpServletResponse response) {
    Cookie authTokenCookie = new Cookie(AUTH_TOKEN_COOKIE_NAME, user.getLoginToken());
    authTokenCookie.setMaxAge(COOKIE_AGE);
    authTokenCookie.setPath("/");
    authTokenCookie.setDomain(".computoser.com");
    response.addCookie(authTokenCookie);

    Cookie seriesCookie = new Cookie(AUTH_TOKEN_SERIES_COOKIE_NAME, user.getLoginSeries());
    seriesCookie.setMaxAge(COOKIE_AGE);//from   w w  w.  j a  va  2  s  .  co m
    seriesCookie.setPath("/");
    seriesCookie.setDomain(".computoser.com");
    response.addCookie(seriesCookie);
}

From source file:org.tonguetied.web.CookieUtilsTest.java

/**
 * Test method for {@link org.tonguetied.web.CookieUtils#getCookie(HttpServletRequest, String)}.
 *///from w w w.j a  v  a 2  s. c  o  m
@Test
public final void testGetCookieWithNullName() {
    Cookie[] cookies = new Cookie[] { new Cookie("name", "value") };
    request.setCookies(cookies);
    Cookie cookie = CookieUtils.getCookie(request, null);
    assertNull(cookie);
}

From source file:org.araneaframework.tests.servlet.util.AtomicResponsetHelperTests.java

public void testRollBackHeaders() throws Exception {
    res.setHeader("key", "value");
    assertEquals("value", res.getHeader("key"));

    Cookie cookie = new Cookie("key", "value");
    res.addCookie(cookie);/*from  w w w  .jav a2s  .co m*/
    assertEquals(cookie, res.getCookie("key"));

    atomic.rollback();
    assertEquals(null, res.getHeader("key"));
    assertEquals(null, res.getCookie("key"));
}

From source file:com.epam.cme.storefront.security.cookie.EnhancedCookieGeneratorTest.java

@Test
public void testClientSideCookieDynamicPath() {
    cookieGenerator.setCookieName(JSESSIONID);
    cookieGenerator.setHttpOnly(false);// client side
    cookieGenerator.setCookieSecure(true);
    cookieGenerator.setUseDefaultPath(false);

    BDDMockito.given(request.getContextPath()).willReturn("/some_path");

    cookieGenerator.addCookie(request, response, "cookie_monster");

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/some_path");
    expectedCookie.setSecure(true);//from   ww w . j  ava2  s  .  c  o  m
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

    Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie)));
    assertNoHeaderAdjustments();

}

From source file:org.kievguide.controller.UserController.java

@RequestMapping(value = "/signinaction", method = RequestMethod.POST)
public ModelAndView signInAction(@RequestParam("email") String email, @RequestParam("password") String password,
        HttpServletResponse response) {/*w  w  w . j  a  v  a2 s.  c  o m*/
    ModelAndView modelAndView = new ModelAndView();

    User user = null;
    user = userService.searchUser(email);

    if (user.getPassword().equals(password)) {

        Cookie userCookie = new Cookie("userstatus", email);
        response.addCookie(userCookie);
        String userStatus = Util.userPanel(email);
        modelAndView.addObject("userstatus", userStatus);
        modelAndView.addObject("user", user);
        modelAndView.setViewName("redirect:" + "firstrequest");
        return modelAndView;
    } else {
        modelAndView.setViewName("error");
        return modelAndView;
    }

}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.security.cookie.EnhancedCookieGeneratorTest.java

@Test
public void testClientSideCookieDynamicPath() {
    cookieGenerator.setCookieName(JSESSIONID);
    cookieGenerator.setHttpOnly(false);//client side
    cookieGenerator.setCookieSecure(true);
    cookieGenerator.setUseDefaultPath(false);

    BDDMockito.given(request.getContextPath()).willReturn("/some_path");

    cookieGenerator.addCookie(request, response, "cookie_monster");

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/some_path");
    expectedCookie.setSecure(true);/*w  w w  .  j av  a2 s . c  o  m*/
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

    Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie)));
    assertNoHeaderAdjustments();

}

From source file:org.jasig.cas.web.flow.GenerateServiceTicketActionTests.java

@Test
public void testServiceTicketFromCookie() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", TestUtils.getService());
    context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket);
    MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(/*from   w w w  .  j a  v  a  2 s .c o  m*/
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    request.setCookies(new Cookie[] { new Cookie("TGT", this.ticketGrantingTicket) });

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}

From source file:com.yahoo.yos.AccessToken.java

public Cookie getCookie() throws UnsupportedEncodingException, JSONException {
    return new Cookie("yosdk_at",
            new String(Base64.encodeBase64(toJSONObject().toString().getBytes("UTF-8")), "UTF-8"));
}

From source file:net.mindengine.oculus.frontend.web.Auth.java

private static Cookie createCookie(String name, String value, int maxAge, String path) {
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);/*from  w w w  .  j  a  va 2 s.c  o  m*/
    cookie.setPath(path);
    return cookie;
}

From source file:net.webpasswordsafe.server.ServerSessionUtil.java

public static void initCsrfSession() {
    HttpSession session = getRequest().getSession(false);
    if (session.isNew() || (session.getAttribute(Constants.CSRF_TOKEN_KEY) == null)) {
        // either new session or old session without csrf token set, so set it
        session.setAttribute(Constants.CSRF_TOKEN_KEY, session.getId());
        Cookie cookie = new Cookie(Constants.CSRF_TOKEN_KEY, session.getId());
        cookie.setPath("".equals(getRequest().getContextPath()) ? "/" : getRequest().getContextPath());
        getResponse().addCookie(cookie);
    }/*w ww.j  a v  a2 s.c  o  m*/
}