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:com.evon.injectTemplate.InjectTemplateFilter.java

private String getCookieHashs(HttpServletRequest httpRequest) {
    Cookie cookies[] = httpRequest.getCookies();
    if (cookies == null) {
        return "";
    }/*from  w  w w  . j a  va  2 s.c o  m*/
    StringBuffer ret = new StringBuffer();
    for (Cookie cookie : cookies) {
        ret.append(cookie.getName().hashCode());
        ret.append(";");
        ret.append(cookie.getValue().hashCode());
        ret.append(";");
    }
    return ret.toString();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.OAuthAction.java

public ActionForward redirectToRedirectUrl(ActionMapping mapping, HttpServletRequest request,
        HttpServletResponse response, Person person, final Cookie cookie) {
    String cookieValue = new String(Base64.getDecoder().decode(cookie.getValue()));
    final int indexOf = cookieValue.indexOf("|");
    String clientApplicationId = cookieValue.substring(0, indexOf);
    String redirectUrl = cookieValue.substring(indexOf + 1, cookieValue.length());

    return redirectToRedirectUrl(mapping, request, response, person, clientApplicationId, redirectUrl);
}

From source file:com.adito.core.CoreUtil.java

/**
 * Get a cookie value from a request given its name. The specified default
 * will be returned if the cookie cannot be found
 * /* w  w  w  .  j ava 2  s  .c  om*/
 * @param name cookie name
 * @param request request
 * @param defaultValue default value
 * @return cookie value
 */
public static String getCookieValue(String name, HttpServletRequest request, String defaultValue) {
    Cookie c = getCookie(name, request);
    return c == null ? defaultValue : c.getValue();
}

From source file:com.acc.storefront.security.cookie.EnhancedCookieGenerator.java

@Override
public void addCookie(final HttpServletResponse response, final String cookieValue) {
    super.addCookie(new HttpServletResponseWrapper(response) {
        @Override/* w w w.ja v a  2 s  . co  m*/
        public void addCookie(final Cookie cookie) {
            setEnhancedCookiePath(cookie);

            if (isHttpOnly()) {
                // Custom code to write the cookie including the httpOnly flag
                final StringBuffer headerBuffer = new StringBuffer(100);
                ServerCookie.appendCookieValue(headerBuffer, cookie.getVersion(), cookie.getName(),
                        cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(),
                        cookie.getMaxAge(), cookie.getSecure(), true);
                response.addHeader(HEADER_COOKIE, headerBuffer.toString());
            } else {
                // Write the cookie as normal
                super.addCookie(cookie);
            }
        }
    }, cookieValue);
}

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

protected String positionCookie(ServletRequest servletRequest, ServletResponse servletResponse, String mlLang,
        String cookieName, boolean content) {
    if (mlLang == null || mlLang.length() == 0) {
        // try to get the cookie and set the content locale prop there
        Cookie[] cookies = ((HttpServletRequest) servletRequest).getCookies();
        Cookie cookie;
        boolean found = false;
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                cookie = cookies[i];//from  w w w. j  a v a 2s.  co  m
                if (cookie.getName().equals(cookieName)) {
                    String lang = cookie.getValue();
                    if (content) {
                        if (lang.length() == 0) {
                            I18NUtil.setContentLocale(null);
                        } else {
                            I18NUtil.setContentLocale(new Locale(lang));
                        }
                        return lang;
                    } else {
                        I18NUtil.setLocale(new Locale(lang));
                        return lang;
                    }

                }
            }
        }
    } else {
        Cookie mlpref = getCookie(servletRequest, cookieName);

        if (mlpref == null) {
            mlpref = new Cookie(cookieName, mlLang);
        } else
            mlpref.setValue(mlLang);
        // Set expiry date after 24 Hrs for both the cookies.
        //mlpref.setMaxAge(60 * 60 * 24);

        ((HttpServletResponse) servletResponse).addCookie(mlpref);
        if (content) {
            I18NUtil.setContentLocale(new Locale(mlLang));
            return mlLang;
        } else {
            I18NUtil.setLocale(new Locale(mlLang));
            return mlLang;
        }
        /*
         * { if(mlLang.equals("reset")) { Cookie mlpref = new
         * Cookie(cookieName, mlLang); // Set expiry date after 24 Hrs for
         * both the cookies. mlpref.setMaxAge(0); mlpref.setValue("");
         * ((HttpServletResponse) servletResponse).addCookie(mlpref); if
         * (content) { I18NUtil.setContentLocale(null); return mlLang; }
         * else { I18NUtil.setLocale(null); return mlLang; } } else
         */

    }

    return mlLang;
}

From source file:com.adobe.acs.commons.wcm.notifications.impl.SystemNotificationsImpl.java

private boolean isDismissed(final SlingHttpServletRequest request, final Page notificationPage) {
    final Cookie cookie = CookieUtil.getCookie(request, COOKIE_NAME);
    if (cookie != null) {
        return StringUtils.contains(cookie.getValue(), this.getNotificationId(notificationPage));
    } else {//from w  ww.j  a  v  a 2s. co  m
        // No cookie has been set, so nothing has been dismissed
        return false;
    }
}

From source file:org.obiba.shiro.web.filter.AuthenticationFilter.java

@Nullable
private Subject authenticateCookie(HttpServletRequest request) {
    Cookie sessionCookie = WebUtils.getCookie(request, sessionIdCookieName);
    Cookie requestCookie = WebUtils.getCookie(request, requestIdCookieName);
    if (isValid(sessionCookie)) {
        String sessionId = extractSessionId(request, sessionCookie);
        String requestId = requestCookie == null ? "" : requestCookie.getValue();
        AuthenticationToken token = new HttpCookieAuthenticationToken(sessionId, request.getRequestURI(),
                requestId);/*  w  ww.j a  va2s .  c o  m*/
        Subject subject = new Subject.Builder(securityManager).sessionId(sessionId).buildSubject();
        subject.login(token);
        return subject;
    }
    return null;
}

From source file:com.jaspersoft.jasperserver.war.control.JSCommonController.java

protected void setupLoginPage(HttpServletRequest req) {
    Cookie[] cookies = req.getCookies();
    String locale = null;/*from ww  w . j a v  a2s  .  com*/
    String preferredTz = null;
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie.getName().equals(JasperServerConstImpl.getUserLocaleSessionAttr()))
                locale = cookie.getValue();
            if (cookie.getName().equals(JasperServerConstImpl.getUserTimezoneSessionAttr()))
                preferredTz = cookie.getValue();
        }
    }

    Locale displayLocale = req.getLocale();
    String preferredLocale;
    if (locale == null || locale.length() == 0) {
        preferredLocale = displayLocale.toString();
    } else {
        preferredLocale = locale;
    }

    if (preferredTz == null) {
        preferredTz = timezones.getDefaultTimeZoneID();
    }

    req.setAttribute("preferredLocale", preferredLocale);
    req.setAttribute("userLocales", locales.getUserLocales(displayLocale));
    req.setAttribute("preferredTimezone", preferredTz);
    req.setAttribute("userTimezones", timezones.getTimeZones(displayLocale));
    try {
        if (Integer.parseInt(passwordExpirationInDays) > 0) {
            allowUserPasswordChange = "true";
        }
    } catch (NumberFormatException e) {
        // if the value is NaN, then assume it's non postive.
        // not overwrite allowUserPasswordChange
    }
    req.setAttribute("allowUserPasswordChange", allowUserPasswordChange);
    req.setAttribute("passwordExpirationInDays", passwordExpirationInDays);
    req.setAttribute("passwordPattern", userAuthService.getAllowedPasswordPattern().replace("\\", "\\\\"));
    req.setAttribute("autoCompleteLoginForm", autoCompleteLoginForm);
    req.setAttribute(IS_DEVELOPMENT_ENVIRONMENT_TYPE, false);
    req.setAttribute(USERS_EXCEEDED, false);
    req.setAttribute(BAN_USER, false);
    req.setAttribute("isEncryptionOn", SecurityConfiguration.isEncryptionOn());
}

From source file:com.mentor.questa.vrm.jenkins.QuestaVrmHostAction.java

private boolean getActionCookie(StaplerRequest req) {
    boolean showActions = false;

    // check the current preference value
    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("HostAction_showActions")) {
                showActions = Boolean.parseBoolean(cookie.getValue());
            }/*from   w  w w  .  j  ava  2s .c o m*/
        }
    }
    return showActions;
}

From source file:com.hypersocket.netty.HttpResponseServletWrapper.java

@Override
public void addCookie(Cookie cookie) {

    StringBuffer cookieHeader = new StringBuffer();

    cookieHeader.append(cookie.getName());
    cookieHeader.append("=");
    cookieHeader.append(cookie.getValue());
    if (cookie.getPath() != null) {
        cookieHeader.append("; Path=");
        cookieHeader.append(cookie.getPath());
    }//from w  w w .  j a v a2 s .  c o  m
    if (cookie.getDomain() != null) {
        cookieHeader.append("; Domain=");
        cookieHeader.append(cookie.getDomain());
    }
    if (cookie.getMaxAge() > 0) {
        cookieHeader.append("; Max-Age=");
        cookieHeader.append(cookie.getMaxAge());
        /**
         * This breaks IE when date of server and browser do not match
         */
        cookieHeader.append("; Expires=");
        if (cookie.getMaxAge() == 0) {
            cookieHeader.append(DateUtils.formatDate(new Date(10000), DateUtils.PATTERN_RFC1036));
        } else {
            cookieHeader.append(
                    DateUtils.formatDate(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L),
                            DateUtils.PATTERN_RFC1036));
        }
    }

    if (cookie.getSecure()) {
        cookieHeader.append("; Secure");
    }

    /**
     * Make sure we are not adding duplicate cookies
     */
    for (Entry<String, String> entry : response.getHeaders()) {
        if (entry.getKey().equals("Set-Cookie") && entry.getValue().equals(cookieHeader.toString())) {
            return;
        }
    }
    addHeader("Set-Cookie", cookieHeader.toString());

}