Example usage for javax.servlet.http HttpServletResponse addCookie

List of usage examples for javax.servlet.http HttpServletResponse addCookie

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse addCookie.

Prototype

public void addCookie(Cookie cookie);

Source Link

Document

Adds the specified cookie to the response.

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);//from   ww  w  .j a v  a  2  s .  c  o  m
    if (!StringUtils.isEmpty(path)) {
        cookie.setPath(path);
    }
    response.addCookie(cookie);
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.CookieCleaner.java

public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    for (String s : cookieNames) {
        Cookie cookie = new Cookie(s, null);
        cookie.setPath("/");
        cookie.setMaxAge(0);/*w  ww. j  a  v  a2  s.co m*/
        response.addCookie(cookie);

        cookie = new Cookie(s, null);
        cookie.setPath(request.getContextPath() + "/eauth/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }

    if (request.getCookies() != null) {
        for (int i = 0; i < request.getCookies().length; i++) {
            Cookie cookie = request.getCookies()[i];
            for (String s : cookieNames) {
                if (cookie.getName().startsWith(s)) {
                    cookie = new Cookie(cookie.getName(), null);
                    cookie.setPath("/");
                    cookie.setMaxAge(0);
                    response.addCookie(cookie);

                    cookie = new Cookie(cookie.getName(), null);
                    cookie.setPath(request.getContextPath() + "/eauth/");
                    cookie.setMaxAge(0);
                    response.addCookie(cookie);
                }
            }
        }
    }
    request.getSession().invalidate();
    if (authentication != null)
        authentication.setAuthenticated(false);
    response.sendRedirect(request.getContextPath() + redirect);
}

From source file:com.baron.bm.controller.MemberController.java

@RequestMapping("/logout") // 
public String logout(HttpServletRequest request, MemberModel model, HttpServletResponse response) {

    for (Cookie cookie : request.getCookies()) {
        if (cookie.getName().equals("bm_id")) {
            cookie.setMaxAge(0);/*from  w w w. j a v a 2 s . c o  m*/
            model.setId("0");
            response.addCookie(new Cookie("bm_id", model.getId()));
        } else if (cookie.getName().equals("bm_permission")) {
            cookie.setMaxAge(0);
            model.setPermission("0");
            response.addCookie(new Cookie("bm_permission", model.getPermission()));
        }
    }
    return "logout";
}

From source file:org.uaa.security.core.LogoutHandler.java

public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String uri = request.getRequestURI();

    // clear Cookies
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        log.debug(cookie.getName());//from  w  w w . j  a va 2s  .  c om

        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }

    // set response message
    ResponseWithStatus res = new ResponseWithStatus(uri, "0", ConfigUtil.getValue("00000"));
    response.setContentType("application/json;charset=UTF-8");
    response.getOutputStream().write(res.toJson().getBytes());
    return;
}

From source file:net.longfalcon.web.LogoutController.java

@RequestMapping("/logout")
public String logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        HttpSession httpSession, Model model) {
    try {//from   w  w w  .j  a v a 2s.c om
        httpSession.invalidate();
        Cookie uidCookie = new Cookie("uid", "");
        uidCookie.setMaxAge(-1);
        Cookie idhCookie = new Cookie("idh", "");
        idhCookie.setMaxAge(-1);
        httpServletResponse.addCookie(uidCookie);
        httpServletResponse.addCookie(idhCookie);
    } catch (Exception e) {
        _log.error(e, e);
    }
    model.asMap().clear();
    return "redirect:/";
}

From source file:com.vmware.identity.openidconnect.server.HttpResponse.java

public void applyTo(HttpServletResponse httpServletResponse) throws SerializeException, IOException {
    Validate.notNull(httpServletResponse, "httpServletResponse");

    if (this.cookies != null) {
        for (Cookie cookie : this.cookies) {
            if (cookie != null) {
                httpServletResponse.addCookie(cookie);
            }/*from   w w w.j  a v  a2s. c o m*/
        }
    }

    if (this.headers != null) {
        for (Header header : this.headers) {
            if (header != null) {
                httpServletResponse.addHeader(header.getName(), header.getValue());
            }
        }
    }

    if (this.response != null) {
        HTTPResponse nimbusHttpResponse = this.response.toHTTPResponse(); // throws SerializeException
        nimbusHttpResponse.applyTo(httpServletResponse); // throws IOException
    }

    if (this.serverException != null) {
        ErrorObject error = this.serverException.getErrorObject();
        httpServletResponse.sendError(error.getHTTPStatusCode(),
                error.getCode() + ": " + error.getDescription());
    }
}

From source file:es.logongas.ix3.web.security.impl.WebSessionSidStorageImplAbstractJws.java

@Override
public void deleteSid(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    Cookie cookie = new Cookie(jwsCookieName, "");
    cookie.setHttpOnly(false);//  www.ja  v a2s . com
    cookie.setPath(httpServletRequest.getContextPath() + "/");
    httpServletResponse.addCookie(cookie);
}

From source file:org.apereo.portal.url.UrlCanonicalizingFilter.java

protected void setRedirectCount(HttpServletRequest request, HttpServletResponse response, int count) {
    final Cookie cookie = new Cookie(COOKIE_NAME, Integer.toString(count));
    cookie.setPath(request.getContextPath());
    cookie.setMaxAge(30);//from w  w w.j  av  a  2 s  . c  o m
    response.addCookie(cookie);
}

From source file:com.trailmagic.image.ui.LogoutController.java

@RequestMapping("/logout")
public void handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
    SavedRequest savedRequest = requestCache.getRequest(req, res);

    HttpSession session = req.getSession(false);
    session.invalidate();/*  ww  w .ja va2  s  .c  o  m*/

    Cookie terminate = new Cookie(TokenBasedRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, null);
    terminate.setMaxAge(0);
    res.addCookie(terminate);

    if (savedRequest != null) {
        res.sendRedirect(savedRequest.getRedirectUrl());
    } else {
        res.sendRedirect("/photo/albums/");
    }
}

From source file:com.glaf.core.util.RequestUtils.java

public static void setTheme(HttpServletRequest request, HttpServletResponse response, String theme) {
    if (StringUtils.isNotEmpty(theme)) {
        Cookie cookie = new Cookie(Constants.THEME_COOKIE, theme);
        cookie.setPath("/");
        cookie.setMaxAge(-1);//from   w  ww .  j a  v a  2 s  . c  o  m
        response.addCookie(cookie);

        Cookie cookie2 = new Cookie("data-theme", "theme-" + theme);
        cookie2.setPath("/");
        cookie2.setMaxAge(-1);
        response.addCookie(cookie2);
    }
}