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:es.logongas.ix3.web.security.impl.WebSessionSidStorageImplAbstractJws.java

@Override
public void setSid(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Serializable sid) {/*from w ww . j  a v  a 2  s. co  m*/
    String payload = serialize(sid);

    String jwsCompact = jws.getJwsCompactSerialization(payload, getSecretKey(sid));
    Cookie cookie = new Cookie(jwsCookieName, jwsCompact);
    cookie.setHttpOnly(false);
    cookie.setPath(httpServletRequest.getContextPath() + "/");
    httpServletResponse.addCookie(cookie);
}

From source file:org.j2free.util.ServletUtils.java

/**
 * /*from  w w  w .j a  v  a  2 s  . co m*/
 * @param response
 * @param name
 * @param value
 * @param expiry
 * @param useRootPath
 * @return
 */
public static Cookie createCookie(HttpServletResponse response, String name, String value, int expiry,
        boolean useRootPath) {

    Cookie c = new Cookie(name, value);
    c.setMaxAge(expiry);
    if (useRootPath) {
        c.setPath("/");
    }

    response.addCookie(c);
    return c;
}

From source file:br.com.edo.atmlist.config.CsrfHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);/*from  w  w  w  . java  2  s.  c o m*/
        }
    }
    filterChain.doFilter(request, response);
}

From source file:com.aplikasi.penjualan.config.CsrfAttributeToCookieFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//from w  w  w.  j a v a 2  s  .co  m
        }
    }
    filterChain.doFilter(request, response);
}

From source file:iddb.web.security.service.CommonUserService.java

protected void invalidateUserSession(HttpServletRequest request, HttpServletResponse response) {
    context.removeSubject();/*from w  w  w.java 2  s. co  m*/
    String sessionKey = null;
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.removeAttribute(UserService.SUBJECT);
        sessionKey = (String) session.getAttribute(UserService.SESSION_KEY);
        session.removeAttribute(UserService.SESSION_KEY);
    }
    // remove cookie
    Cookie cookie = new Cookie("iddb-u", "");
    cookie.setPath(request.getContextPath() + "/");
    cookie.setMaxAge(0);
    response.addCookie(cookie);

    cookie = new Cookie("iddb-k", "");
    cookie.setPath(request.getContextPath() + "/");
    cookie.setMaxAge(0);
    response.addCookie(cookie);

    if (sessionKey != null) {
        removeSession(sessionKey);
    }
}

From source file:co.edu.utb.softeng.springtodos.config.security.CsrfHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//from w ww.  j  a v  a2 s  . c  om
        }

    }
    filterChain.doFilter(request, response);

}

From source file:eu.semlibproject.annotationserver.managers.CookiesManager.java

/**
 * Generate a new cookie for the annotation server
 * /*from w w  w  . jav  a 2  s  .  c  o  m*/
 * @param accessToken   the accessToken
 * @return              the new generated cookie
 */
public Cookie generateNewASCookie(String accessToken) {

    if (accessToken != null) {
        Cookie cookie = new Cookie(SemlibConstants.COOCKIE_NAME, accessToken);
        cookie.setComment(SemlibConstants.COOCKIE_DESCRIPTION);
        cookie.setPath(SemlibConstants.COOKIE_PATH);
        cookie.setMaxAge(SemlibConstants.COOKIE_TIME);
        cookie.setVersion(1);
        cookie.setSecure(false);

        return cookie;
    }

    return null;
}

From source file:com.openthinks.webscheduler.service.WebSecurityService.java

public Cookie createRememberMeCookie() {
    Cookie cookie = new Cookie(StaticDict.COOKIE_REMEMBER_ME, DigestUtils.sha1Hex(StaticUtils.UUID()));
    cookie.setMaxAge(StaticDict.COOKIE_REMEMBER_ME_EXPIRE_TIME);
    cookie.setPath(StaticUtils.getRootContext());
    return cookie;
}

From source file:org.jboss.web.loadbalancer.scheduler.SchedulerBase.java

protected void setStickyCookie(URL host, HttpServletRequest request, HttpServletResponse response) {
    Cookie cookie = new Cookie(stickyCookieName, Integer.toString(host.hashCode()));
    cookie.setPath("/");
    cookie.setMaxAge(-1);//  w  w w  .j  a v a 2  s  .c o m
    response.addCookie(cookie);
}

From source file:com.ar.dev.tierra.api.config.CsrfHeaderFilter.java

/**
 * Metodo para agregar cookie contra CRSF
 * @param request/*from   w  w w .j  a va2  s. c om*/
 * @param response
 * @param filterChain
 * @throws ServletException
 * @throws IOException 
 */
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);
        }
    }
    filterChain.doFilter(request, response);
}