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.acc.storefront.security.cookie.EnhancedCookieGeneratorTest.java

@Test
public void testClientSideCookieDefaultPath() {
    cookieGenerator.setCookieName(JSESSIONID);
    cookieGenerator.setHttpOnly(false);//client side

    cookieGenerator.addCookie(response, "cookie_monster");

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/");
    expectedCookie.setSecure(false);/*  w w w  .java  2  s .c om*/
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

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

}

From source file:io.gravitee.management.security.JWTCookieGenerator.java

public Cookie generate(final String value) {
    final Cookie cookie = new Cookie(HttpHeaders.AUTHORIZATION, value);
    cookie.setHttpOnly(true);//from  w w w  . j  a v  a2  s. c  o m
    cookie.setSecure(environment.getProperty("jwt.cookie-secure", Boolean.class, DEFAULT_JWT_COOKIE_SECURE));
    cookie.setPath(environment.getProperty("jwt.cookie-path", DEFAULT_JWT_COOKIE_PATH));
    cookie.setDomain(environment.getProperty("jwt.cookie-domain", DEFAULT_JWT_COOKIE_DOMAIN));
    return cookie;
}

From source file:m.c.m.proxyma.rewrite.CookieRewriteEngineTest.java

public void testMasquerade_Unmasquerade_Cookie() throws NullArgumentException, IllegalArgumentException, UnsupportedEncodingException {
    System.out.println("masquerade/unmasqueradeCookie");
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.getContextByName("default");
    ProxyFolderBean folder1 = proxyma.createNewProxyFolder("host1", "http://www.google.com/it", context);
    ProxyFolderBean folder2 = proxyma.createNewProxyFolder("host2", "https://www.apple.com/en", context);
    ProxymaResource aResource = proxyma.createNewResource(request, response, context);
    aResource.setProxymaRootURI("http://localhost:8080/proxyma");
    aResource.setProxyFolder(folder1);//from  w w w . j  a v a2  s.c  o  m
    CookieRewriteEngine instance = new CookieRewriteEngine(context);

    Cookie theCookie = new Cookie("cookie1", "Value1");
    theCookie.setDomain("google.com");
    theCookie.setPath("/it/pippo");
    instance.masqueradeCookie(theCookie, aResource);

    String expected = "localhost";
    assertEquals(expected, theCookie.getDomain());

    expected = "/proxyma/host1/pippo";
    assertEquals(expected, theCookie.getPath());

    expected = CookieRewriteEngine.PROXYMA_REWRITTEN_HEADER  + "Value1";
    assertEquals(expected, theCookie.getValue());

    instance.unmasqueradeCookie(theCookie);

    expected = "Value1";
    assertEquals(expected, theCookie.getValue());

    theCookie = new Cookie("cookie2", "Value2");
    instance.masqueradeCookie(theCookie, aResource);

    expected = "localhost";
    assertEquals(expected, theCookie.getDomain());

    expected = "/proxyma/host1";
    assertEquals(expected, theCookie.getPath());

    expected = CookieRewriteEngine.PROXYMA_REWRITTEN_HEADER  + "Value2";
    assertEquals(expected, theCookie.getValue());

    instance.unmasqueradeCookie(theCookie);

    expected = "Value2";
    assertEquals(expected, theCookie.getValue());

    proxyma.removeProxyFolder(folder2, context);
    proxyma.removeProxyFolder(folder1, context);
}

From source file:com.acc.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(response, "cookie_monster");

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/some_path");
    expectedCookie.setSecure(true);/*from   w w  w.ja v 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:com.acc.storefront.security.cookie.EnhancedCookieGeneratorTest.java

@Test
public void testServerSideCookieDynamicPath() {
    cookieGenerator.setCookieName(JSESSIONID);
    cookieGenerator.setHttpOnly(true);//server side
    cookieGenerator.setUseDefaultPath(false);

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

    cookieGenerator.addCookie(response, "cookie_monster");

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/some_path");
    expectedCookie.setSecure(false);/*from   w w w  .j a  v  a 2s.  co m*/
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

    Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie)));
    Mockito.verify(response).addHeader(EnhancedCookieGenerator.HEADER_COOKIE,
            "JSESSIONID=cookie_monster; Domain=\"what a domain\"; Path=/; HttpOnly");

}

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

@Test
public void testServerSideCookieDefaultPath() {
    cookieGenerator.setCookieName("guid");
    cookieGenerator.setHttpOnly(true);// server side

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

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

    final Cookie expectedCookie = new Cookie("guid", "cookie_monster");
    expectedCookie.setPath("/");
    expectedCookie.setSecure(false);//from   w ww.j  a v  a  2  s . c  o m
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

    Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie)));
    Mockito.verify(response).addHeader(EnhancedCookieGenerator.HEADER_COOKIE,
            "guid=cookie_monster; Domain=\"what a domain\"; Path=/; HttpOnly");

}

From source file:net.prasenjit.auth.config.CustomAjaxAwareHandler.java

/** {@inheritDoc} */
@Override//from w  w w. j a v  a  2s. com
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    request.setAttribute("javax.servlet.error.status_code", HttpServletResponse.SC_FORBIDDEN);
    request.setAttribute("org.springframework.boot.autoconfigure.web.DefaultErrorAttributes.ERROR",
            accessDeniedException);
    if (accessDeniedException instanceof CsrfException && !response.isCommitted()) {
        // Remove the session cookie so that client knows it's time to obtain a new CSRF token
        String pCookieName = "CSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, "");
        cookie.setMaxAge(0);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }

    delegatedAccessDeniedHandler.handle(request, response, accessDeniedException);
}

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

@Test
public void testClientSideCookieDefaultPath() {
    cookieGenerator.setCookieName(JSESSIONID);
    cookieGenerator.setHttpOnly(false);// client side

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

    final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster");
    expectedCookie.setPath("/");
    expectedCookie.setSecure(false);/*from w  w w  . j  a  v  a 2  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:com.third.rent.user.controller.LoginController.java

@RequestMapping(value = "/user/login.do", method = RequestMethod.POST)
public String login_post(@RequestParam String userId, @RequestParam String userPwd,
        @RequestParam(required = false) String chkSaveId, HttpServletRequest request,
        HttpServletResponse response, Model model) {
    // 1// www. j  a  va2s. c o  m
    logger.info("? , ? userId={} userPwd={}", userId, userPwd);
    logger.info("? chkSaveId={}", chkSaveId);

    // 2
    int result = userService.loginCheck(userId, userPwd);
    logger.info("?  , ? result={}", result);

    String msg = "", url = "/user/login.do";
    if (result == userService.LOGIN_OK) {
        UserVO vo = userService.selectByUserid(userId);

        msg = vo.getUserName() + " ? ?.";
        url = "/user/index.do";

        // ? 
        HttpSession session = request.getSession();
        session.setAttribute("userId", userId);
        session.setAttribute("userName", vo.getUserName());
        session.setAttribute("userLicense", vo.getUserLicense());

        // ? 
        Cookie ck = new Cookie("ck_userId", userId);
        ck.setPath("/");
        // ?  ? 
        if (chkSaveId != null) {
            ck.setMaxAge(1000 * 24 * 60 * 60); // 1000?
            response.addCookie(ck);
        } else {
            ck.setMaxAge(0); //  
            response.addCookie(ck);
        }

    } else if (result == userService.ID_NONE) {
        msg = " ?  .";
    } else if (result == userService.PWD_DISAGREE) {
        msg = " ? ";
    } else {
        msg = "? ? ";
    }
    // 3
    model.addAttribute("msg", msg);
    model.addAttribute("url", url);

    return "common/message";
}

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

@Test
public void testServerSideCookieDefaultPath() {
    cookieGenerator.setCookieName("guid");
    cookieGenerator.setHttpOnly(true);//server side

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

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

    final Cookie expectedCookie = new Cookie("guid", "cookie_monster");
    expectedCookie.setPath("/");
    expectedCookie.setSecure(false);//from   w ww.j  av a  2s  .  c o  m
    expectedCookie.setMaxAge(NEVER_EXPIRES);
    expectedCookie.setDomain("what a domain");

    Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie)));
    Mockito.verify(response).addHeader(EnhancedCookieGenerator.HEADER_COOKIE,
            "guid=cookie_monster; Domain=\"what a domain\"; Path=/; HttpOnly");

}