Example usage for javax.servlet.http Cookie setDomain

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

Introduction

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

Prototype

public void setDomain(String domain) 

Source Link

Document

Specifies the domain within which this cookie should be presented.

Usage

From source file:de.appsolve.padelcampus.utils.LoginUtil.java

private void deleteCookie(HttpServletRequest request, HttpServletResponse response, String path) {
    Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, null);
    cookie.setDomain(request.getServerName());
    cookie.setMaxAge(0);// w  w  w  .  ja v a  2 s. c  o  m
    if (!StringUtils.isEmpty(path)) {
        cookie.setPath(path);
    }
    response.addCookie(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 a2s . 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:de.appsolve.padelcampus.utils.LoginUtil.java

public void updateLoginCookie(HttpServletRequest request, HttpServletResponse response) {
    Player player = sessionUtil.getUser(request);
    if (player != null) {
        UUID cookieUUID = UUID.randomUUID();
        UUID cookieValue = UUID.randomUUID();
        String cookieValueHash = BCrypt.hashpw(cookieValue.toString(), BCrypt.gensalt());
        LoginCookie loginCookie = new LoginCookie();
        loginCookie.setUUID(cookieUUID.toString());
        loginCookie.setPlayerUUID(player.getUUID());
        loginCookie.setLoginCookieHash(cookieValueHash);
        loginCookie.setValidUntil(new LocalDate().plusYears(1));
        loginCookieDAO.saveOrUpdate(loginCookie);
        Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, cookieUUID.toString() + ":" + cookieValue.toString());
        cookie.setDomain(request.getServerName());
        cookie.setMaxAge(ONE_YEAR_SECONDS);
        cookie.setPath("/");
        response.addCookie(cookie);/*from  w  ww  .  j a  va2  s. c o m*/
    }
}

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

public Cookie toServletCookie() {
    Cookie c = new Cookie(name, value);
    c.setPath(path);//from w  ww  .  j a  v  a 2 s .  c  om
    c.setMaxAge(max_age);
    if (domain != null)
        c.setDomain(domain);
    c.setSecure(secure);
    return c;
}

From source file:com.companyname.services.OnLoginSuccessHandler.java

private Cookie createCookie(HttpServletRequest request, String name, String value) {
    logger.info("create a new token with name: " + name);
    Cookie cookie = new Cookie(name, value);
    cookie.setDomain(getCookieDomain());
    cookie.setPath(getCookiePath(request));
    cookie.setMaxAge(getCookieExpireTimeLength());
    return cookie;
}

From source file:io.cfp.auth.service.CookieService.java

public Cookie getTokenCookie(String tokenValue) {
    Cookie tokenCookie = new Cookie("token", tokenValue);
    tokenCookie.setPath("/");
    tokenCookie.setHttpOnly(true); // secure Token to be invisible from
    // javascript in the browser
    tokenCookie.setDomain(cookieDomain);
    tokenCookie.setMaxAge((int) Duration.ofHours(TokenService.TOKEN_EXPIRATION).getSeconds());
    return tokenCookie;
}

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);//  www  .  j  a  v  a 2s.c o m
    seriesCookie.setPath("/");
    seriesCookie.setDomain(".computoser.com");
    response.addCookie(seriesCookie);
}

From source file:com.aurel.track.master.ModuleBL.java

public static Cookie sendPOSTRequest(String urlString) {
    Cookie responseCookie = null;
    try {/* w w  w .j  a v a  2s. c  o m*/
        HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault();
        HttpPost httppost = new HttpPost(urlString);
        // Request parameters and other properties.
        //Execute and get the response.
        HttpContext localContext = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpResponse response = httpclient.execute(httppost, localContext);

        if (cookieStore.getCookies().size() > 0) {
            List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
            for (org.apache.http.cookie.Cookie cookie : cookies) {
                if (cookie.getName().equals("JSESSIONID")) {
                    responseCookie = new Cookie(cookie.getName(), cookie.getValue());
                    responseCookie.setPath(cookie.getPath());
                    responseCookie.setDomain(cookie.getDomain());
                }
            }
        }
        if (response.getEntity() != null) {
            response.getEntity().consumeContent();
        }

    } catch (Exception ex) {
        LOGGER.debug(ExceptionUtils.getStackTrace(ex));
    }
    return responseCookie;
}

From source file:org.xchain.namespaces.servlet.SetCookie.java

public boolean execute(JXPathContext context) throws Exception {
    Cookie cookie = new Cookie(getName(context), getValue(context));
    if (hasPath()) {
        cookie.setPath(getPath(context));
    }/*from  w w  w  . j  ava 2s.  co m*/
    if (hasDomain()) {
        cookie.setDomain(getDomain(context));
    }
    if (hasMaxAge()) {
        cookie.setMaxAge(getMaxAge(context));
    }
    getResponse(context).addCookie(cookie);
    return false;
}

From source file:cn.vlabs.umt.ui.servlet.LogoutServlet.java

private void removeCookie(HttpServletResponse response, String domain, String path, String name) {
    Cookie cookie = new Cookie(name, "");
    if (!CommonUtils.isNull(domain)) {
        cookie.setDomain(domain);
    }// w ww.  j  a v a 2s .  com
    if (!CommonUtils.isNull(path)) {
        cookie.setPath(path);
    }
    cookie.setMaxAge(0);
    response.addCookie(cookie);
}