Example usage for javax.servlet.http Cookie getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the cookie.

Usage

From source file:com.nkapps.billing.services.SearchServiceImpl.java

@Override
public String execSearchWithinDate(HttpServletRequest request, HttpServletResponse response) {
    Cookie sbtCookie = null;/*from  w w  w.  j  a  v a2  s. co  m*/

    String searchWithinDate = request.getParameter("searchWithinDate");
    if (searchWithinDate == null) {
        Cookie[] requestCookies = request.getCookies();
        for (Cookie c : requestCookies) {
            if (c.getName().equals("searchWithinDate")) {
                sbtCookie = c;
            }
        }
        if (sbtCookie != null) {
            searchWithinDate = sbtCookie.getValue();
        } else {
            searchWithinDate = "true";
        }
    } else {
        sbtCookie = new Cookie("searchWithinDate", searchWithinDate);
        sbtCookie.setPath("/");
        response.addCookie(sbtCookie);
    }
    return searchWithinDate;
}

From source file:com.nkapps.billing.services.SearchServiceImpl.java

@Override
public String execSearchByDate(HttpServletRequest request, HttpServletResponse response) {
    Cookie sbdCookie = null;/*from w ww.ja  v a 2s.  c o m*/

    String searchByDate = request.getParameter("searchByDate");
    if (searchByDate == null) {
        Cookie[] requestCookies = request.getCookies();
        for (Cookie c : requestCookies) {
            if (c.getName().equals("searchByDate")) {
                sbdCookie = c;
            }
        }
        if (sbdCookie != null) {
            searchByDate = sbdCookie.getValue();
        } else {
            searchByDate = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime());
        }
    } else {
        sbdCookie = new Cookie("searchByDate", searchByDate);
        sbdCookie.setPath("/");
        response.addCookie(sbdCookie);
    }
    return searchByDate;
}

From source file:com.haulmont.cuba.web.sys.CubaUIProvider.java

protected String getCookieValue(Cookie[] cookies, String key) {
    if (cookies == null || key == null) {
        return null;
    }//from www. j  ava 2 s .co m
    for (final Cookie cookie : cookies) {
        if (Objects.equals(cookie.getName(), key)) {
            return cookie.getValue();
        }
    }
    return null;
}

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

/**
 *
 * @param request ...//from  www.  j  a  va2 s.c o m
 * @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.google.acre.script.AcreCookie.java

public AcreCookie(org.apache.http.cookie.Cookie c) {
    name = c.getName();
    value = c.getValue();//from w  w  w . j  a  v a2  s  .  com
    secure = c.isSecure();
    domain = c.getDomain();
    path = c.getPath();
    max_age = -1;
    // XXX translate into max-age?
    // c.getExpiryDate();
}

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;
                    }// w ww . j av  a2  s .c o  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.google.ie.web.interceptor.LoginInterceptor.java

/**
 * Checks if the fcauth cookie is present with a non empty value
 * /*from   w  w  w.jav  a  2s .  c om*/
 * @param request
 * @return true if a valid fcauth cookie is present in the request, else
 *         false
 */
private boolean checkAuthToken(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie != null && cookie.getName().equals(getFcauthCookieName())) {
                // Cookie found. Check for value
                String authToken = cookie.getValue();
                if (authToken != null && authToken.length() > 0) {
                    LOG.info("Auth token found. Allowing request to proceed");
                    return true;
                }
            }
        }
    }
    LOG.warn("Auth token not found. Stopping request to proceed");
    return false;
}

From source file:com.netpace.vzdn.webapp.vzdninterceptors.SecurityInterceptor.java

public String getUserNameFromCookie(HttpServletRequest request, HttpServletResponse response) {

    try {//  ww w .ja v  a  2s .c o  m
        SSOTokenManager stm = SSOTokenManager.getInstance();
        Cookie[] requestCookies = request.getCookies();
        String userName = "";
        for (int i = 0; i < requestCookies.length; i++) {
            Cookie cookie = requestCookies[i];
            if (cookie.getName().equals(VzdnConstants.OPENSSO_COOKIE)) {
                SSOToken st = stm.createSSOToken(request);
                userName = st.getPrincipal().getName();
                userName = userName.substring(userName.indexOf("=") + 1, userName.indexOf(",")).toLowerCase();
                System.out.println("got the cookie user name : " + userName);
                Cookie ssoCookie = new Cookie("loggedInUserInfo", userName);
                response.addCookie(ssoCookie);
                break;
            }
        }
        return userName;
    } catch (Exception ex) {
        log.error("Some issue in SecurityInterceptor while reading user info from cookie" + ex.getMessage());
        ex.printStackTrace();
        return null;
    }
}

From source file:au.gov.dto.dibp.appointments.security.csrf.CookieBasedCsrfTokenRepository.java

@Override
public CsrfToken loadToken(HttpServletRequest request) {
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (cookie != null && CSRF_COOKIE_AND_PARAMETER_NAME.equals(cookie.getName())) {
                return new DefaultCsrfToken(CSRF_HEADER_NAME, CSRF_COOKIE_AND_PARAMETER_NAME,
                        cookie.getValue());
            }//  w w w .j  a  va 2  s  . c  o m
        }
    }
    return null;
}

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;/*  w w w .  j ava  2s .  co  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);
}