List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:com.tenduke.example.scribeoauth.SessionManager.java
/** * Validates an authenticated session and will provide the logged in user's session information as validation result. * @param request Client HTTP request./*from ww w . j av a2 s . co m*/ * @param response HTTP response. * @return Session information or null if session is not valid. */ public SessionInformation validateSession(final HttpServletRequest request, final HttpServletResponse response) { // SessionInformation retValue = null; // String sessionId = null; final Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { // for (Cookie cookie : cookies) { // if (SIGNED_SESSION_COOKIE_NAME.equals(cookie.getName())) { // sessionId = cookie.getValue().split("_")[0]; } } } // if (sessionId != null) { // retValue = getSessionInformation(sessionId); } // return retValue; }
From source file:m.c.m.proxyma.resource.ProxymaResponseDataBeanTest.java
/** * Test of getCookie method, of class ProxymaResponseDataBean. *///from w ww. ja v a 2 s .c o m public void testGetCookie() { System.out.println("getCookie"); ProxymaResponseDataBean instance = new ProxymaResponseDataBean(); instance.addCookie(new Cookie("name1", "value1")); instance.addCookie(new Cookie("name2", "value2")); instance.addCookie(new Cookie("name1", "value3")); Cookie result = instance.getCookie("name1"); assertEquals("value3", result.getValue()); result = instance.getCookie("name2"); assertEquals("value2", result.getValue()); //Test unexisting value result = instance.getCookie("unexistent"); assertNull(result); }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * Cookie/*ww w . j ava 2 s. c om*/ * * @param name * ?? * @param defaultVal * * @param req * * @return */ public static String getCookieValue(String name, String defaultVal, HttpServletRequest req) { if (req.getCookies() != null) { for (Cookie cookie : req.getCookies()) { if (cookie.getName().equals(name)) return cookie.getValue(); } } // nothing found return defaultVal; }
From source file:com.braintree.cscockpit.widgets.renderers.impl.customer.CustomerPaymentMethodAddWidgetRenderer.java
private String getNonceFromCookie() { final String nonce = null; final Cookie[] cookies = ((HttpServletRequest) Executions.getCurrent().getNativeRequest()).getCookies(); for (final Cookie cookie : cookies) { if (COOKIE_PAYMENT_METHOD_NONCE.equals(cookie.getName())) { LOG.info("payment method nonce received from virtual client: " + nonce); return cookie.getValue(); }/*from ww w .j a v a 2 s . c o m*/ } return nonce; }
From source file:net.sf.j2ep.servers.ClusterContainer.java
/** * Locates any specification of which server that issued a * session. If there is no session or the session isn't mapped * to a specific server null is returned. * //from w ww . j a va2 s. c o m * @param cookies The cookies so look for a session in * @return the server's ID or null if no server is found */ private String getServerIdFromCookie(Cookie[] cookies) { String serverId = null; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (isSessionCookie(cookie.getName())) { String value = cookie.getValue(); String id = value.substring(value.indexOf(".") + 1); if (id.startsWith("server")) { serverId = id; } } } } return serverId; }
From source file:grails.plugin.cookielayout.CookiePageLayoutFinder.java
private String getLayoutFromCookie(HttpServletRequest request, String cookieName) { if (checkRequest) { final Object requestLayout = request.getAttribute(cookieName); if (requestLayout != null) { return requestLayout.toString(); }//from w ww.j ava 2s . c om } Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie c : cookies) { if (c.getName().equals(cookieName)) { return c.getValue(); } } } return ""; }
From source file:com.boylesoftware.web.impl.auth.SessionlessAuthenticationService.java
/** * Get authentication cookie value./*from w w w . ja v a2 s.co m*/ * * @param request The HTTP request. * * @return The cookie value, or {@code null} if not found. */ private String getAuthCookieValue(final HttpServletRequest request) { final Cookie[] cookies = request.getCookies(); if (cookies != null) for (final Cookie cookie : request.getCookies()) if (cookie.getName().equals(AUTH_COOKIE_NAME)) return cookie.getValue(); return null; }
From source file:fr.mby.portal.coreimpl.EndToEndTest.java
/** * End to end test.// w ww. j ava 2s .co m * * @throws Exception */ @Test public void testDispatch() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); this.sessionManager.initPortalSession(request, response); this.userActionDispatcher.dispatch(request, response); // Test headers final String actionHeader1 = response.getHeader("actionProp1"); final String renderHeader1 = response.getHeader("renderProp1"); Assert.assertEquals("Bad action header value !", "actionVal1", actionHeader1); Assert.assertEquals("Bad render header value !", "renderVal1", renderHeader1); final Cookie actionCookie1 = response.getCookie("actionCookie1"); final Cookie renderCookie1 = response.getCookie("renderCookie1"); Assert.assertNotNull("Action cookie is null !", actionCookie1); Assert.assertNotNull("Render cookie is null !", renderCookie1); Assert.assertEquals("Bad action cookie value !", "actionCookieVal1", actionCookie1.getValue()); Assert.assertEquals("Bad render cookie value !", "renderCookieVal1", renderCookie1.getValue()); // Test response response.flushBuffer(); final String reponseOutputStream = response.getContentAsString(); Assert.assertEquals("Bad response output stream !", "<html><body><h1>Test</h1></body></html>", reponseOutputStream); }
From source file:com.adobe.acs.commons.wcm.views.impl.WCMViewsFilter.java
/** * Get the WCM Views from the Request passed by QueryParam. * *//w w w . j a va 2 s . c o m * * @param request the request * @return the WCM Views from the Request */ private List<String> getRequestViews(final SlingHttpServletRequest request) { final List<String> views = new ArrayList<String>(); // Respect Query Parameters first final RequestParameter[] requestParameters = request.getRequestParameters(RP_WCM_VIEWS); if (requestParameters != null) { for (final RequestParameter requestParameter : requestParameters) { if (StringUtils.isNotBlank(requestParameter.getString())) { views.add(requestParameter.getString()); } } } if (CollectionUtils.isNotEmpty(views)) { return views; } // If not Query Params can be found, check Cookie final Cookie cookie = CookieUtil.getCookie(request, COOKIE_WCM_VIEWS); if (cookie != null && StringUtils.isNotBlank(cookie.getValue())) { views.add(cookie.getValue()); } return views; }
From source file:org.gatein.sso.agent.opensso.OpenSSOAgentImpl.java
public void validateTicket(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws Exception { // Start with processing message from CDCServlet if this message is available (it should be in servlet request parameter "LARES") if (tryMessageFromCDC(httpRequest, httpResponse)) { return;/*w ww. j a v a 2 s.c o m*/ } // Now cookie should be set and we can continue with cookie processing String token = null; Cookie[] cookies = httpRequest.getCookies(); if (cookies == null) { return; } for (Cookie cookie : cookies) { if (cookie.getName().equals(this.cookieName)) { token = cookie.getValue(); break; } } if (token == null) { throwIllegalStateException("No SSO Tokens Found"); } if (token != null) { boolean isValid = this.isTokenValid(token); if (!isValid) { throwIllegalStateException("OpenSSO Token is not valid!!"); } String subject = this.getSubject(token); if (subject != null) { this.saveSSOCredentials(subject, httpRequest); } } }