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.basicservice.controller.AdminController.java

private void prepareContext(Map map, HttpServletResponse response) {
    Map constants = service.getConstants();
    String csrf_token = "<secret changing key>"; // use SecureRandom to generate a random token
    Locale locale = LocaleContextHolder.getLocale();
    map.put("locale", locale.getLanguage());
    map.put("constants", constants);
    if (response != null) {
        map.put("csrf_token", csrf_token);
        Cookie cookie = new Cookie(Constants.CSRF_COOKIE_NAME, csrf_token);
        cookie.setPath("/");
        cookie.setMaxAge(-1);/*from  ww w .j  a  v  a2s  . co m*/
        response.addCookie(cookie);
    }
}

From source file:net.sourceforge.vulcan.web.struts.actions.ManagePreferencesAction.java

public ActionForward save(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    final PreferencesForm form = (PreferencesForm) actionForm;

    request.removeAttribute(Keys.PREFERENCES);
    request.getSession().setAttribute(Keys.PREFERENCES, form.getConfig());

    final Cookie cookie = new Cookie(Keys.PREFERENCES, preferencesStore.convertToString(form.getConfig()));
    cookie.setPath(request.getContextPath());
    cookie.setMaxAge(60 * 60 * 24 * 365);

    response.addCookie(cookie);//ww  w. j  a  v  a2 s .  co  m
    return mapping.findForward("dashboard");
}

From source file:org.nuxeo.wss.handlers.fprpc.OWSSvrHandler.java

protected void handleFileDialog(FPRPCRequest request, FPRPCResponse response, FPRPCCall call,
        WSSBackend backend, boolean save) throws WSSException {
    if ("HEAD".equals(request.getHttpRequest().getMethod())) {
        response.setContentType("text/html");
        return;//from  w w  w.j av a  2s.  c o  m
    }

    String location = call.getParameters().get("location");
    location = WSSUrlMapper.getUrlWithSitePath(request, location);

    WSSListItem parent = backend.getItem(location);
    List<WSSListItem> items = backend.listItems(location);
    response.addRenderingParameter("parent", parent);
    response.addRenderingParameter("items", items);
    response.setContentType("text/html");

    Cookie MSOWebPartCookie = new Cookie("MSOWebPartPage_AnonymousAccessCookie", "80");
    MSOWebPartCookie.setPath("/");
    MSOWebPartCookie.setMaxAge(3600);

    response.getHttpResponse().setCharacterEncoding("UTF-8");

    response.getHttpResponse().addCookie(MSOWebPartCookie);
    if (save) {
        //response.setRenderingTemplateName("FileSave.ftl");
        response.setRenderingTemplateName("FileOpen.ftl");
    } else {
        response.setRenderingTemplateName("FileOpen.ftl");
    }
}

From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java

public void removeUser(HttpServletRequest request, HttpServletResponse response) {
    //remove from request
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (COOKIE_NAME.equals(c.getName())) {
                c.setValue("deleted");
                break;
            }/*from  w w  w  .j  ava2  s . c  o m*/
        }
    }

    //remove from browser
    Cookie cookie = new Cookie(COOKIE_NAME, "1");
    cookie.setPath(PATH);
    cookie.setMaxAge(0); //0 = remove cookie
    response.setContentType("text/html"); //else delete cookie not works
    response.addCookie(cookie);
}

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

/**
 * {@inheritDoc}/*from ww w  .  j  av  a  2  s  .  co  m*/
 */
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    // Spring put the CSRF token in session attribute "_csrf"
    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");

    // Send the cookie only if the token has changed
    String actualToken = request.getHeader("X-XSRF-TOKEN");
    if (actualToken == null || !actualToken.equals(csrfToken.getToken())) {
        // Session cookie that will be used by AngularJS
        String pCookieName = "XSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, csrfToken.getToken());
        cookie.setMaxAge(-1);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
    filterChain.doFilter(request, response);
}

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

From source file:cn.vlabs.duckling.vwb.CPSFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    int advSiteId = Integer.parseInt(StringUtils.defaultIfEmpty(request.getParameter("as"), "-1"));

    if (advSiteId <= 0) {
        chain.doFilter(request, response);
        return;/*from w  ww .  j a  v  a2s .  c o m*/
    }

    HttpServletResponse rep = (HttpServletResponse) response;
    HttpServletRequest req = (HttpServletRequest) request;
    request.setAttribute("cps", advSiteId);

    Cookie[] cookies = req.getCookies();

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(CPS_ADV, cookie.getName())) {
                cookie.setPath(req.getContextPath());
                cookie.setMaxAge(0);
            }
        }
    }

    Cookie myCookie = new Cookie(CPS_ADV, advSiteId + "");
    myCookie.setMaxAge(60 * 60 * 24);//
    myCookie.setPath(req.getContextPath());
    rep.addCookie(myCookie);
    chain.doFilter(request, response);
}

From source file:io.syndesis.rest.v1.handler.connection.ConnectionHandler.java

@Override
public Connection create(@Context SecurityContext sec,
        @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) {
    final Date rightNow = new Date();
    final Connection updatedConnection = new Connection.Builder().createFrom(connection).createdDate(rightNow)
            .lastUpdated(rightNow).userId(sec.getUserPrincipal().getName()).build();

    final Set<CredentialFlowState> flowStates = CredentialFlowState.Builder.restoreFrom(state::restoreFrom,
            request);/*from w w w . j  a  v  a  2 s .c  o m*/

    final Connection connectionToCreate = flowStates.stream().map(s -> {
        final Cookie removal = new Cookie(s.persistenceKey(), "");
        removal.setPath("/");
        removal.setMaxAge(0);

        response.addCookie(removal);

        return credentials.apply(updatedConnection, s);
    }).findFirst().orElse(updatedConnection);

    return Creator.super.create(sec, connectionToCreate);
}

From source file:com.edgenius.wiki.integration.client.Authentication.java

private void setCookie(String[] tokens, int maxAge, String targetWebContext, HttpServletRequest request,
        HttpServletResponse response) {/*from   w w  w .j  ava  2  s  . c  o m*/
    String cookieValue = encodeCookie(tokens);
    Cookie cookie = new Cookie(WsContants.REMEMBER_ME_COOKIE_NAME, cookieValue);
    cookie.setMaxAge(maxAge);
    cookie.setPath(targetWebContext);
    response.addCookie(cookie);
}

From source file:org.apache.oodt.security.sso.OpenSSOImpl.java

private void addCookie(String name, String val) {
    Cookie userCookie = new Cookie(name, val);
    userCookie.setPath("/");
    userCookie.setMaxAge((int) (System.currentTimeMillis() + (60 * 15)));
    this.res.addCookie(userCookie);
}