Example usage for javax.servlet.http HttpServletRequest getCookies

List of usage examples for javax.servlet.http HttpServletRequest getCookies

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getCookies.

Prototype

public Cookie[] getCookies();

Source Link

Document

Returns an array containing all of the Cookie objects the client sent with this request.

Usage

From source file:org.glassmaker.spring.oauth.OAuth2LogoutFilter.java

protected String getCookieValue(HttpServletRequest request, String cookieName) {
    String cookieValue = null;//from   w w  w .  jav a 2  s  . c om
    Cookie[] cookies = request.getCookies();
    if (cookies != null)
        for (Cookie cookie : cookies)
            if (cookie.getName().equals(cookieName)) {
                cookieValue = cookie.getValue();
                break;
            }
    return cookieValue;
}

From source file:org.impalaframework.extension.mvc.annotation.resolver.CookieValueArgumentResolver.java

protected Object getValue(NativeWebRequest webRequest, String attributeName) {
    HttpServletRequest request = ObjectUtils.cast(webRequest.getNativeRequest(), HttpServletRequest.class);
    final Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }//from w w w . j  a  v a2  s . c o  m
    for (Cookie cookie : cookies) {
        final String name = cookie.getName();
        if (name.equals(attributeName)) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:au.gov.dto.springframework.security.web.context.CookieSecurityContextRepository.java

private Cookie getAuthenticationCookie(HttpServletRequest request) {
    if (request.getCookies() == null) {
        return null;
    }/*from  w w  w.j  av a 2 s .c o m*/
    Optional<Cookie> maybeCookie = Arrays.stream(request.getCookies())
            .filter(cookie -> cookie.getName().equals(authenticationCookieName)).findFirst();
    return maybeCookie.isPresent() ? maybeCookie.get() : null;
}

From source file:com.wikipy.security.AuthenticationFilter.java

public String getCookieTicket(HttpServletRequest httpReq) {

    Cookie[] cookies = httpReq.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(ARG_TICKET)) {
                return cookie.getValue();
            }/*w w w. j  av  a2  s.  c  o m*/
        }
    }
    return httpReq.getParameter(ARG_TICKET);
}

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 ww .j  av  a  2  s  . co  m
                }
            }
        }
    }
    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);
}

From source file:com.baidu.rigel.biplatform.ma.report.utils.QueryUtils.java

/**
 * //w w w.  j  a va 2 s.co  m
 * @param params
 * @param request
 * @return Map<String, String>
 */
private static Map<String, String> collectRequestParams(Collection<ReportParam> params,
        HttpServletRequest request) {
    Map<String, String> rs = Maps.newHashMap();
    request.getParameterMap().forEach((k, v) -> {
        rs.put(k, v[0]);
    });
    // cookie??url?
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            rs.put(cookie.getName(), cookie.getValue());
        }
    }

    // ???cookie?
    rs.putAll(ContextManager.getParams());
    // ???
    rs.remove(Constants.RANDOMCODEKEY);
    rs.remove(Constants.TOKEN);
    rs.remove(Constants.BIPLATFORM_PRODUCTLINE);

    return rs;
}

From source file:com.persistent.cloudninja.web.security.CloudNinjaRemembermeService.java

/**
 * Find the cookie in request and //from  w ww.  j  a v  a2s.  com
 * @param request
 * @param cookieName
 * @return
 */

protected String getCookieValue(HttpServletRequest request, String cookieName) {
    String cookieValue = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null)
        for (Cookie cookie : cookies)
            if (cookie.getName().equals(cookieName)) {
                cookieValue = cookie.getValue();
                break;
            }
    return cookieValue;
}

From source file:com.xybase.utils.StringUtils.java

/**
 * Returns the specified Cookie object, or null if the cookie does not exist.
 * <p/>/* w  w  w  .  j  av a  2  s .c o  m*/
 * This method was derived from Atlassian <tt>CookieUtils</tt> method of
 * the same name, release under the Apache License.
 *
 * @param request the servlet request
 * @param name the name of the cookie
 * @return the Cookie object if it exists, otherwise null
 */
public static Cookie getCookie(HttpServletRequest request, String name) {
    Cookie cookies[] = request.getCookies();

    if (cookies == null || name == null || name.length() == 0) {
        return null;
    }

    //Otherwise, we have to do a linear scan for the cookie.
    for (Cookie cooky : cookies) {
        if (cooky.getName().equals(name)) {
            return cooky;
        }
    }

    return null;
}

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

/**
 *
 * @param request .../*from  w  w  w  .  j av a 2 s.c  om*/
 * @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:de.sainth.recipe.backend.rest.controller.LogoutController.java

@RequestMapping()
@ResponseStatus(HttpStatus.NO_CONTENT)//ww  w .  j a  va  2 s .  c  o m
void logout(HttpServletRequest request, HttpServletResponse response) {
    if ("/logout".equals(request.getServletPath())) {
        Optional<Cookie> cookie = Arrays.stream(request.getCookies())
                .filter(c -> "recipe_bearer".equals(c.getName())).findFirst();
        if (cookie.isPresent()) {
            Cookie c = cookie.get();
            c.setValue("");
            c.setPath("/");
            c.setMaxAge(0);
            response.addCookie(c);
        }
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}