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:AIR.Common.Web.Session.HttpContext.java

public void setRequest(HttpServletRequest request) {
    _request = request;// www  .  j  av  a2s.c o  m
    // update cookies list.
    _cookies = new CookieHolder(this, request.getCookies());
}

From source file:gr.abiss.calipso.web.filters.RestRequestNormalizerFilter.java

protected String getCookieToken(HttpServletRequest httpRequest) {
    String authToken = null;//from w w  w .j  a va2  s.  co m
    Cookie[] cookies = httpRequest.getCookies();
    String ssoCookieName = userDetailsConfig.getCookiesBasicAuthTokenName();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found cookie '" + cookie.getName() + "', secure:  " + cookie.getSecure()
                        + ", comment: " + cookie.getComment() + ", domain: " + cookie.getDomain() + ", value: "
                        + cookie.getValue());
            }
            if (cookie.getName().equalsIgnoreCase(ssoCookieName)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Matched calipso SSO cookie'" + cookie.getName() + "', secure:  "
                            + cookie.getSecure() + ", comment: " + cookie.getComment() + ", domain: "
                            + cookie.getDomain() + ", value: " + cookie.getValue());
                }
                authToken = cookie.getValue();
                break;
            }
        }
        if (LOGGER.isDebugEnabled() && authToken == null) {
            LOGGER.debug("Found no calipso SSO cookie with name: " + ssoCookieName);

        }
    }
    return authToken;
}

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

@RequestMapping("/admin")
public String admin(HttpServletRequest request, Model model) {
    for (Cookie cookie : request.getCookies()) {
        if (cookie.getName().equals("bm_permission")) {
            System.out.println(cookie.getValue());
            if ("1".equals(cookie.getValue())) {
                List<BookModel> bookmodel = joinService.selectBestBook();
                List<MemberModel> memberList = joinService.selectBest();
                model.addAttribute("bookmodel", bookmodel);
                model.addAttribute("bestList", memberList);
                return "admin";
            } else
                return "adminfail";
        }//from  w w w.  j a v a 2 s .  co m
    }
    return null;
}

From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String user = null;//from w w w  .  java 2s  .com
    Cookie[] cookieArray = request.getCookies();
    if (cookieArray != null) {
        for (int i = 0; i < cookieArray.length; i++) {
            Cookie c = cookieArray[i];
            if (c.getName().equals("ADMIN_TOOL_USER")) {
                user = c.getValue();
                System.out.println("Reading username from cookie :" + user);
                System.out.println("Domain: " + c.getDomain());
                System.out.println("Path: " + c.getPath());
            }
        }
    }
    if (user == null) {
        return mapping.findForward("login");
    }

    return executeAction(mapping, form, request, response);
}

From source file:org.mascherl.session.MascherlSessionStorage.java

public MascherlSession restoreSession(HttpServletRequest request) {
    MascherlSession mascherlSession = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        Optional<Cookie> cookieOptional = Arrays.stream(cookies)
                .filter((cookie) -> Objects.equals(cookieName, cookie.getName())).findAny();
        if (cookieOptional.isPresent()) {
            String encryptedValue = cookieOptional.get().getValue();
            try {
                String data = cryptoHelper.decryptAES(encryptedValue);
                mascherlSession = new MascherlSession(objectMapper, data);
            } catch (RuntimeException e) {
                logger.log(Level.WARNING, "Session could not be restored. Will continue with empty session.",
                        e);//from w  w  w.j a v a2  s  .  c om
            }
        }
    }
    if (mascherlSession == null) {
        mascherlSession = new MascherlSession(objectMapper); // no session available, return a new one
    }

    request.setAttribute(MASCHERL_SESSION_REQUEST_ATTRIBUTE, mascherlSession);
    return mascherlSession;
}

From source file:com.afousan.controller.CookieInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    // all non-root requests get analyzed
    Cookie[] cookies = request.getCookies();

    if (!ObjectUtils.isEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            if (RETWIS_COOKIE.equals(cookie.getName())) {
                String auth = cookie.getValue();
                String name = twitter.findNameForAuth(auth);
                if (name != null) {
                    String uid = twitter.findUid(name);
                    RetwisSecurity.setUser(name, uid);
                }//  w  ww.ja v a 2  s.  c om
            }
        }
    }
    return true;
}

From source file:co.id.app.sys.util.StringUtils.java

/**
 * Returns the specified Cookie object, or null if the cookie does not exist.
 * <p/>/*from ww  w . j  a v a2 s  . c om*/
 * 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 (int i = 0; i < cookies.length; i++) {
        if (cookies[i].getName().equals(name)) {
            return cookies[i];
        }
    }

    return null;
}

From source file:com.wavemaker.tools.security.CloudFoundrySecurityFilter.java

private void checkAuthenticationCookie(HttpServletRequest request)
        throws TransportTokenDigestMismatchException {
    Cookie[] allCookies = request.getCookies();
    Assert.state(allCookies.length < 12, "Way too many auth cookies.");
    Cookie[] authCookies = new Cookie[allCookies.length];
    int num = 0;/*  ww w  .  j a v  a 2  s  .co m*/
    for (Cookie cookie : allCookies) {
        if (cookie.getName().equals("wavemaker_authentication_token")) {
            authCookies[num++] = cookie;
        }
    }
    for (Cookie cookie : authCookies) {
        try {
            Assert.state(cookie != null, "This is no cookie");
            Assert.state(StringUtils.hasLength(cookie.getValue()), "This cookie has no value");
            log.debug("Trying = " + cookie.getValue());
            SharedSecret sharedSecret = this.propagation.getForSelf(true);
            sharedSecret.decrypt(TransportToken.decode(cookie.getValue()));
            return;
        } catch (TransportTokenDigestMismatchException ttdme) {
            log.debug("Invalid cookie");
        }
    }
    log.warn("NO valid cookie - redirecting " + request.getRequestURI() + " to spinup app");
    throw (new TransportTokenDigestMismatchException("Unable to find valid secret token"));
}

From source file:com.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator.java

@Override
public String getToken(HttpServletRequest request) {
    final Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (TOKEN_HTTP_SESSION_KEY.equalsIgnoreCase(cookie.getName())) {
                return htmlEncode(cookie.getValue());
            }/*from  ww w  .j  av  a2 s .c o  m*/
        }
    }
    return null;
}

From source file:hudson.Functions.java

public static Cookie getCookie(HttpServletRequest req, String name) {
    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(name)) {
                return cookie;
            }/*from   w w  w  .  j a v  a 2  s  .c o  m*/
        }
    }
    return null;
}