List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:hudson.Functions.java
public static String getCookie(HttpServletRequest req, String name, String defaultValue) { Cookie c = getCookie(req, name); if (c == null || c.getValue() == null) return defaultValue; return c.getValue(); }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.AnonymousAuthenticatorForCAS2.java
@Override public Boolean handleLogout(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { boolean isRedirectionToCas = false; log.debug(httpRequest.getRequestURL().toString()); Cookie[] cookies = httpRequest.getCookies(); for (Cookie cookie : cookies) { log.debug(String.format("ANONYMOUS_AUTH : cookie->%s:%s", cookie.getName(), cookie.getValue())); if (NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY.equals(cookie.getName())) { isRedirectionToCas = true;/*from ww w . j a v a2 s . c o m*/ log.debug("isRedirectionToCAS"); break; } } if (isRedirectionToCas) { String authURL = getCas2Authenticator().getServiceURL(httpRequest, Cas2Authenticator.LOGIN_ACTION); String appURL = getCas2Authenticator().getAppURL(httpRequest); try { Map<String, String> urlParameters = new HashMap<String, String>(); urlParameters.put("service", URLEncoder.encode(appURL, "UTF-8")); String location = URIUtils.addParametersToURIQuery(authURL, urlParameters); httpResponse.sendRedirect(location); return true; } catch (IOException e) { log.error("Unable to redirect to CAS logout screen:", e); return false; } } return super.handleLogout(httpRequest, httpResponse); }
From source file:de.knightsoftnet.validators.server.security.CsrfCookieHandler.java
/** * set csrf/xsrf cookie.// w w w.j av a2 s .c o m */ public void setCookie(final HttpServletRequest prequest, final HttpServletResponse presponse) throws IOException { final CsrfToken csrf = (CsrfToken) prequest.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(prequest, ResourcePaths.XSRF_COOKIE); final String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie(ResourcePaths.XSRF_COOKIE, token); cookie.setPath(StringUtils.defaultString(StringUtils.trimToNull(prequest.getContextPath()), "/")); presponse.addCookie(cookie); } } }
From source file:com.enonic.cms.business.resolver.ForceResolverValueServiceImpl.java
private String getForcedResolverValueFromCookie(HttpServletRequest request, String forcedValueKey) { Cookie cookie = CookieUtil.getCookie(request, forcedValueKey); return cookie == null || cookie.getMaxAge() == 0 ? null : decodeCookieValue(cookie.getValue()); }
From source file:org.tonguetied.web.CookieUtilsTest.java
/** * Test method for {@link org.tonguetied.web.CookieUtils#getCookie(HttpServletRequest, String)}. */// w w w .j a v a2 s . c o m @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()); }
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);//w w w . j a v a 2s. co m // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:uk.co.caprica.bootlace.security.web.filter.AngularJsCsrfHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { logger.debug("doFilterInternal()"); CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, CSRF_COOKIE_NAME); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { logger.debug("Setting new CSRF cookie"); cookie = new Cookie(CSRF_COOKIE_NAME, token); cookie.setPath(request.getServletContext().getContextPath() + "/"); response.addCookie(cookie);// w ww .ja v a 2s . c o m } } filterChain.doFilter(request, response); }
From source file:com.openthinks.webscheduler.service.WebSecurityService.java
public Optional<User> validateUserByCookie(WebAttributers was) { Cookie[] cookies = was.getRequest().getCookies(); if (cookies == null) return Optional.empty(); Cookie rememberCookie = null;/*from www .j a v a 2 s. c o m*/ for (Cookie cookie : cookies) { if (StaticDict.COOKIE_REMEMBER_ME.equals(cookie.getName()) && cookie.getValue() != null) { rememberCookie = cookie; break; } } if (rememberCookie != null) { User user = getUsers().findByCookie(rememberCookie.getValue()); if (user != null) { User loginUserInfo = user.clone();//fix second login failed issue loginUserInfo.setPass(null); return Optional.of(loginUserInfo); } } return Optional.empty(); }
From source file:com.data2semantics.yasgui.server.servlets.AppCacheServlet.java
private String getPermutationFromCookies(Cookie[] cookies) { String permutationStrongName = null; for (Cookie cookie : cookies) { if (cookie.getName().equals(CookieKeys.GWT_STRONG_NAME)) { permutationStrongName = cookie.getValue(); }/* ww w.j av a 2 s .co m*/ } return permutationStrongName; }