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:de.inetsource.jsfforum.beans.user.UserBean.java

public void loginUserViaCookie() {
    if (!loginViaCookieTried) {
        try {//from   w  w  w  .  j a v a  2s . c o  m
            CookieHelper ch = new CookieHelper();
            Cookie cookie = ch.getCookie(COOKIE_NAME);
            if (cookie != null && cookie.getValue() != null) {
                String cookieValue = cookie.getValue();
                Users dbUser = userFacade.findUserByCookie(cookieValue);
                if (dbUser != null) {
                    user = dbUser;
                    theme = user.getTheme();
                } else {
                    ch.removeCookie(cookie);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            loginViaCookieTried = true;
            user.setPassword(null);
        }
    }
}

From source file:iddb.web.security.service.CommonUserService.java

private String getCookie(Cookie[] cookies, String key) {
    if (cookies == null || cookies.length == 0) {
        log.trace("No cookies sent");
        return null;
    }/*  w  ww.  ja v  a2s. c o m*/
    for (Cookie c : cookies) {
        log.trace("List cookie {} with value {}", c.getName(), c.getValue());
        if (key.equals(c.getName())) {
            return c.getValue();
        }
    }
    return null;
}

From source file:cn.vlabs.umt.ui.servlet.LogoutServlet.java

private String getUserName(HttpServletRequest request) {
    User user = SessionUtils.getUser(request);
    String username = null;//w  w w .ja v a  2 s  .  co  m
    if (user == null) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (Attributes.COOKIE_NAME.equals(cookie.getName())
                        && StringUtils.isNotEmpty(cookie.getValue())) {
                    try {
                        username = new String(cred.decrypt(HexUtil.toBytes(cookie.getValue())), "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                    }
                }
            }
        }
    } else {
        username = user.getCstnetId();
    }
    return username;
}

From source file:com.ebook.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

protected boolean isGuidStoredinCookies(final HttpServletRequest request, final HttpServletResponse response,
        final String guid, final String guidCookieName) {
    for (final Cookie cookie : request.getCookies()) {
        if (guidCookieName.equals(cookie.getName())) {
            if (guid.equals(cookie.getValue())) {
                return true;
            } else {
                LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual ["
                        + cookie.getValue() + "]. removing.");
                getCookieGenerator().removeCookie(response);
            }/*from w ww  .  j  av a2  s.c o  m*/
        }
    }
    return false;
}

From source file:com.companyname.services.PlatCookieService.java

public String getCookieValue(HttpServletRequest request, String key) {
    Cookie cookie = getCookie(request, key);
    if (cookie == null) {
        logger.info("cookie for key \"" + key + "\" is not found");
    } else {//from w  w  w  .j  a  v  a 2  s .c  o m
        logger.info("cookie for key \"" + key + "\" = " + cookie.getValue());
    }
    return (cookie == null) ? null : cookie.getValue();
}

From source file:fedroot.dacs.http.DacsCookie.java

/** 
 * Creates a new instance of DacsCookie from a javax.servlet.http.net.Cookie
 *//*from  ww  w . ja va 2 s.  co  m*/
public DacsCookie(String domain, javax.servlet.http.Cookie cookie) throws DacsRuntimeException {
    //        super(federationDomain, jcookie.getName(),jcookie.getValue(),"/", jcookie.getMaxAge(),jcookie.getSecure());
    super(cookie.getName(), cookie.getValue());

    if (!isDacsCookie(cookie)) {
        throw new DacsRuntimeException("invalid DACS cookie: " + cookie.getName());
    }

    // the domain of a DACS federation never refers to a single host
    // if there is no leading dot we add one to the domain,
    // so a cookie with domain "foo.com" becomes a DACS
    // cookie with domain ".foo.com" causing user agents to send the cookie
    // to hosts foo.com, bar.foo.com, baz.foo.com etc

    setVersion(1);
    if (domain.startsWith(".")) {
        setDomain(domain);
    } else {
        setDomain("." + domain);
    }
    setPath("/");

    if (cookie.getMaxAge() == -1) {
    } else {
        Date expires = new Date();
        expires.setTime(expires.getTime() + cookie.getMaxAge());
        setExpiryDate(expires);
    }

    setSecure(cookie.getSecure());
}

From source file:com.ctc.storefront.filters.CartRestorationFilter.java

protected void processRestoration(final HttpServletRequest request) {
    String cartGuid = null;//from  w w  w  .j a  v  a 2  s .c om

    if (request.getCookies() != null) {
        final String anonymousCartCookieName = getCartRestoreCookieGenerator().getCookieName();

        for (final Cookie cookie : request.getCookies()) {
            if (anonymousCartCookieName.equals(cookie.getName())) {
                cartGuid = cookie.getValue();
                break;
            }
        }
    }

    if (!StringUtils.isEmpty(cartGuid)) {
        getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
        try {
            getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                    getCartFacade().restoreSavedCart(cartGuid));
        } catch (final CommerceCartRestorationException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
            getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS,
                    WebConstants.CART_RESTORATION_ERROR_STATUS);
        }
    }
}

From source file:edu.usu.sdl.openstorefront.web.action.BaseAction.java

protected String getCookieValue(String key) {
    String value = null;//from   w w w.j a  v  a2s  . c om

    Cookie cookies[] = getContext().getRequest().getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(key)) {
                value = cookie.getValue();
            }
        }
    }

    return value;
}

From source file:org.alfresco.web.app.servlet.LanguageCookieFilter.java

protected void dumpCookies(ServletRequest servletRequest) {
    Cookie[] cookies = ((HttpServletRequest) servletRequest).getCookies();
    if (cookies == null)
        return;/*from  ww  w.j a v  a2s  .c om*/
    Cookie cookie;
    for (int i = 0; i < cookies.length; i++) {
        cookie = cookies[i];
        System.out.println("Cookie Name: " + cookie.getName() + " Value:*" + cookie.getValue() + "*");
    }
}

From source file:it.publisys.liferay.hook.shibboleth.ShibbolethPostLogoutAction.java

/**
 * Prepara i {@link Cookie}s da inoltrare
 *
 * @param request {@link HttpServletRequest}
 * @return cookies string/*ww  w .j ava2  s  .  c om*/
 */
private String _prepareCookies(HttpServletRequest request) {
    StringBuilder _cookieBuffer = new StringBuilder();
    try {
        Cookie[] _cookies = request.getCookies();
        for (Cookie _cookie : _cookies) {
            _cookieBuffer.append(_cookie.getName()).append("=")
                    .append(URLEncoder.encode(_cookie.getValue(), "UTF-8"));
            _cookieBuffer.append("; ");
        }
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace(System.err);
    }

    if (_cookieBuffer.length() > 2) {
        _cookieBuffer.delete(_cookieBuffer.length() - 2, _cookieBuffer.length());
    }
    return _cookieBuffer.toString();
}