Example usage for javax.servlet.http Cookie getValue

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

Introduction

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

Prototype

public String getValue() 

Source Link

Document

Gets the current value of this Cookie.

Usage

From source file:io.interface21.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())) {
            // Angular is capable to handle CSRF protection and expected a token with name XSRF-TOKEN
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//  w ww  .  ja  v  a  2s .  c om
        }
    }
    filterChain.doFilter(request, response);
}

From source file:Controladores.ControladorLogin.java

@RequestMapping("exibe-login")
public ModelAndView exibeLogin(HttpServletRequest request,
        @CookieValue(value = "loginCookie", defaultValue = "") String loginCookie, // se usar request nao precisa desse parmetro
        @CookieValue(value = "senhaCookie", defaultValue = "") String senhaCookie) { // nem desse!

    ModelAndView mv = new ModelAndView("login");

    Cookie c = obterCookie("loginCookie", request);
    if (c != null) {
        mv.addObject("loginCookie", c.getValue());
    }/*from   ww  w .  j a v  a 2s . co m*/

    c = obterCookie("senhaCookie", request);
    if (c != null) {
        mv.addObject("senhaCookie", c.getValue());
    }

    /*
     mv.addObject("loginCookie", loginCookie );
     mv.addObject("senhaCookie", senhaCookie );        
     */
    return mv;
}

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

private String getCookieParameter(HttpServletRequest request, String name) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null || cookies.length <= 0 || StringUtils.isBlank(name)) {
        return "";
    }/*from  w w  w.  ja  v  a 2  s .  c o m*/

    for (Cookie cookie : cookies) {
        if (StringUtils.equals(name, cookie.getName())) {
            return cookie.getValue();
        }
    }

    return "";
}

From source file:com.yahoo.yos.RequestToken.java

public RequestToken(Cookie cookie) throws UnsupportedEncodingException, JSONException {
    JSONObject json = new JSONObject(
            new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8"));
    setKey(json.optString("key", null));
    setSecret(json.optString("secret", null));
    setSessionHandle(json.optString("sessionHandle", null));
}

From source file:cn.designthougths.sample.axon.sfav.webui.UIApplication.java

private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override/*  www  . j  a  va  2  s  .c  om*/
        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);
        }
    };
}

From source file:com.tamnd.app.filters.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 . ja  v  a  2  s .c  o  m
        }
    }
    filterChain.doFilter(request, response);

    //      CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
    //        if (token != null) {
    //            response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName());
    //            response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName());
    //            response.setHeader(RESPONSE_TOKEN_NAME , token.getToken());
    //        }
    //        filterChain.doFilter(request, response);
}

From source file:de.berlios.jhelpdesk.web.tools.LocaleCustomResolver.java

public Locale resolveLocale(HttpServletRequest request) {
    Locale raLocale = (Locale) request.getAttribute("jhd_locale");
    if (raLocale != null) {
        return raLocale;
    }//  w w  w .  jav  a 2  s.c  o m
    HttpSession session = request.getSession();
    User currentUser = (User) session.getAttribute("user");
    if (currentUser != null && currentUser.getUserId() != null) {
        request.setAttribute("jhd_locale", currentUser.getPreferredLocale());
        return currentUser.getPreferredLocale();
    }
    Cookie localeCookie = WebUtils.getCookie(request, "jhd_locale");
    if (localeCookie != null) {
        Locale locale = StringUtils.parseLocaleString(localeCookie.getValue());
        if (locale != null) {
            request.setAttribute("jhd_locale", locale);
            return locale;
        }
    }
    request.setAttribute("jhd_locale", request.getLocale());
    return request.getLocale();
}

From source file:io.seldon.api.controller.JsPortholeController.java

/**
 *
 * @param request .../*from   w  ww  .  ja  va 2 s.com*/
 * @param response ...
 * @param localId if non-null, use this local id instead of generating a {@link UUID}.
 *                Typically this will be used to propagate client-specific cookies where browser privacy issues have
 *                blocked the server-side setting.
 * @return
 */
private String ensureCookie(HttpServletRequest request, HttpServletResponse response, String localId) {
    final Cookie[] cookies = request.getCookies();
    String uuid = null;
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(RL_COOKIE_ID)) {
                uuid = cookie.getValue();
            }
        }
    }
    if (uuid == null) {
        if (localId != null) {
            logger.info("Using local ID for porthole session: " + localId);
            uuid = localId;
        } else {
            uuid = UUID.randomUUID().toString();
        }
        final Cookie cookie = new Cookie(RL_COOKIE_ID, uuid);
        cookie.setMaxAge(COOKIE_MAX_AGE);
        response.addCookie(cookie);
        response.addHeader("P3P", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
    }
    return uuid;
}

From source file:com.jaspersoft.jasperserver.war.JSSessionLocaleResolver.java

private Locale getLocaleFromCookies(HttpServletRequest req) {
    Cookie[] cookies = req.getCookies();

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(JasperServerConstImpl.getUserLocaleSessionAttr())) {
                if (cookie.getValue() != null && cookie.getValue().length() > 0) {
                    return LocaleUtils.toLocale(cookie.getValue());
                }//from  w  ww .  j  av  a 2  s .co m

                break;
            }
        }
    }

    return null;
}

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

public void deleteLoginCookie(HttpServletRequest request, HttpServletResponse response) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(COOKIE_LOGIN_TOKEN)) {
                if (cookie.getValue() != null && cookie.getValue().split(":").length == 2) {
                    LoginCookie loginCookie = loginCookieDAO.findByUUID(cookie.getValue().split(":")[0]);
                    if (loginCookie != null) {
                        loginCookieDAO.deleteById(loginCookie.getId());
                        break;
                    }//from   w w  w. ja  v  a  2 s .  c  om
                }
            }
        }
    }
    deleteCookie(request, response, null);
    deleteCookie(request, response, "/");
    deleteCookie(request, response, "/page");
    deleteCookie(request, response, "/admin");
    deleteCookie(request, response, "/login");
    deleteCookie(request, response, "/admin/events");
    deleteCookie(request, response, "/admin/events/edit");
    deleteCookie(request, response, "/events/event");
    Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, null);
    cookie.setDomain(request.getServerName());
    cookie.setMaxAge(0);
    response.addCookie(cookie);
}