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.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;/*from   ww w.  j av a  2  s .  c om*/
    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:org.uaa.security.core.AuthenticationManager.java

public UsernamePasswordToken getToken(HttpServletRequest request) {
    UsernamePasswordToken token = null;/* www .  j av  a2  s  .c  o m*/

    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(ConfigUtil.getValue("SESSION_ID"))) {
            String content = cookie.getValue();
            String sessionInfo = Crypto.decrypt(content);

            try {
                JSONObject result = new JSONObject(sessionInfo);
                Integer uid = result.getInt("uid");
                String username = result.getString("username");
                String password = result.getString("password");
                JSONArray array = result.getJSONArray("roles");
                List<Integer> roles = new ArrayList<Integer>();
                for (int i = 0; i < array.length(); i++) {
                    roles.add(array.getInt(i));
                }

                token = new UsernamePasswordToken(uid, username, password, roles);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    return token;
}

From source file:org.codemucker.testserver.capturing.CapturedCookie.java

public CapturedCookie(org.apache.http.cookie.Cookie c) {
    domain = c.getDomain();/*from  ww  w  .  j  a v a 2 s.  c o m*/
    path = c.getPath();
    name = c.getName();
    value = c.getValue();
    secure = c.isSecure();
    maxAge = c.getExpiryDate() == null ? -1 : 0;
    version = c.getVersion();
}

From source file:com.salesmanager.catalog.CatalogInterceptor.java

@Override
protected String doIntercept(ActionInvocation invoke, HttpServletRequest req, HttpServletResponse resp)
        throws Exception {

    /** remove profile url **/
    req.getSession().removeAttribute("profileUrl");

    /** synchronize mini shopping cart**/

    //get http session shopping cart
    ShoppingCart cart = SessionUtil.getMiniShoppingCart(req);
    MerchantStore mStore = SessionUtil.getMerchantStore(req);

    if (cart == null) {//synch only when the cart is null or empty

        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                if (cookie.getName().equals(CatalogConstants.SKU_COOKIE + mStore.getMerchantId())) {

                    Locale locale = LocaleUtil.getLocale(req);

                    String cookieValue = StringUtil.unescape(cookie.getValue());

                    ShoppingCart sc = MiniShoppingCartSerializationUtil.deserializeJSON(cookieValue, mStore,
                            locale);/*from   www. j  a v  a2  s.co  m*/
                    if (sc != null) {

                        MiniShoppingCartUtil.calculateTotal(sc, mStore);
                        SessionUtil.setMiniShoppingCart(sc, req);

                    } else {//expire cookie
                        cookie.setValue(null);
                        cookie.setMaxAge(0);
                        resp.addCookie(cookie);
                    }
                }
            }
        }

    }

    return null;

}

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 .  jav a  2 s  .co  m*/

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

    return "";
}

From source file:fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.security.WSSOSessionTrackingFilter.java

/**
 * {@inheritDoc}/* www. j a va  2s  .  c om*/
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    LuteceUser user = SecurityService.getInstance().getRegisteredUser(req);

    if (user != null) {
        Cookie[] cookies = req.getCookies();
        String strUserID = null;

        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];

                if (cookie.getName().equals(AppPropertiesService.getProperty(PROPERTY_COOKIE_WSSOGUID))) {
                    strUserID = cookie.getValue();
                    if (!StringUtils.isEmpty(strUserID) && !strUserID.equals(user.getName())) {

                        SecurityService.getInstance().unregisterUser(req);

                    }

                    break;

                }
            }
        }
    }

    chain.doFilter(request, response);
}

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

/**
 * Returns the specified Cookie object, or null if the cookie does not exist.
 * <p/>//from   www  . j  av  a 2s . co  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:au.gov.dto.springframework.security.web.csrf.CookieCsrfTokenRepository.java

@Override
public CsrfToken loadToken(HttpServletRequest request) {
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (cookie != null && csrfCookieName.equals(cookie.getName())) {
                return new DefaultCsrfToken(csrfHeaderName, csrfParameterName, cookie.getValue());
            }//from   w  w w .  j a v a2 s  . c om
        }
    }
    return null;
}

From source file:com.pokerweb.Area.CheckBetArea.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/* w ww  .  j  a v  a  2 s.c  o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String Token = "";
    for (Cookie object : request.getCookies())
        if (object.getName().equals("JSESSIONID"))
            Token = object.getValue();
    if (Token.length() <= 0)
        return;
    JSONObject js = new JSONObject();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    long UserId = DBManager.GetInstance().GetCurrentUserId(auth.getName());
    for (Map.Entry<Long, StatisticBet> object : TableStatus.GetInstance().RequestStatisticBet.entrySet())
        if (object.getValue().ToketUserRequest.equals(Token) && object.getKey() == UserId)
            if (TableStatus.GetInstance().StatisticBetCurrentUser.containsKey(object.getValue().IdBet)) {
                try {
                    Game GMData = new Game();
                    String data = data = GMData.GetDateFromBet(object.getValue().IdBet);
                    TableStatus.GetInstance().StatisticBetCurrentUser.get(object.getValue().IdBet).put("date",
                            data);
                    TableStatus.GetInstance().StatisticBetCurrentUser.get(object.getValue().IdBet).put("round",
                            GMData.GetRoundFromBet(object.getValue().IdBet));
                    js.put("StatisticCurrentUser",
                            TableStatus.GetInstance().StatisticBetCurrentUser.get(object.getValue().IdBet));
                    TableStatus.GetInstance().StatisticBetCurrentUser.remove(object.getValue().IdBet);
                    TableStatus.GetInstance().RequestStatisticBet.remove(
                            TableStatus.GetInstance().StatisticBetCurrentUser.get(object.getValue().IdBet));
                } catch (JSONException ex) {
                    Logger.getLogger(CheckBetArea.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
    response.setContentType("application/json; charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.getWriter().write(js.toString());
}

From source file:org.tonguetied.web.CookieUtilsTest.java

/**
 * Test method for {@link org.tonguetied.web.CookieUtils#getCookie(HttpServletRequest, String)}.
 *//*from w  w w  . j  av  a2s.com*/
@Test
public final void testGetCookieWhenCookieExists() {
    Cookie[] cookies = new Cookie[] { new Cookie("name", "value"), new Cookie("other1", "value"),
            new Cookie("other2", "value"), new Cookie("other3", "value"), new Cookie("other4", "value"),
            new Cookie("other5", "value") };
    request.setCookies(cookies);
    Cookie cookie = CookieUtils.getCookie(request, "name");
    assertEquals("name", cookie.getName());
    assertEquals("value", cookie.getValue());
}