List of usage examples for javax.servlet.http HttpServletRequest getCookies
public Cookie[] getCookies();
Cookie
objects the client sent with this request. From source file:com.persistent.cloudninja.utils.RoleBasedAccessControlInterceptor.java
/** * Returns the cookie based on name otherwise null object * @param request/*from w w w .jav a2 s. c o m*/ * @param cookieName * @return Auth cookie */ protected Cookie getCookie(HttpServletRequest request, String cookieName) { Cookie reqCookie = null; Cookie[] cookies = request.getCookies(); if (cookies != null) for (Cookie cookie : cookies) if (cookie.getName().equals(cookieName)) { reqCookie = cookie; break; } return reqCookie; }
From source file:com.google.identitytoolkit.GitkitClientTest.java
public void testGetOobCodeInvalidCaptchaCode() throws Exception { Cookie[] gitkitCookie = { new Cookie("gtoken", "fake-token") }; HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getCookies()).thenReturn(gitkitCookie); when(mockRequest.getParameter("action")).thenReturn("resetPassword"); when(mockRequest.getParameter("email")).thenReturn("1111@example.com"); when(mockRequest.getParameter("challenge")).thenReturn("what is the number"); when(mockRequest.getParameter("response")).thenReturn("8888"); when(mockRequest.getRemoteUser()).thenReturn("1.1.1.1"); String expectedApiUrl = GitkitClient.GITKIT_API_BASE + "getOobConfirmationCode"; when(mockSender.post(eq(expectedApiUrl), anyString(), eq(headers))) .thenReturn("{ \"error\": { \"code\": \"4xx\", \"message\": \"CAPTCHA_CHECK_FAILED\" }}"); GitkitClient.OobResponse oobResponse = gitkitClient.getOobResponse(mockRequest); // the client collapses the error message down to a simple error:value assertEquals("{\"error\": \"CAPTCHA_CHECK_FAILED\" }", oobResponse.getResponseBody()); }
From source file:com.glaf.core.util.RequestUtils.java
public static void removeLoginUser(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), Constants.COOKIE_NAME)) { cookie.setMaxAge(0);/*from w w w .j a v a 2 s . co m*/ cookie.setPath("/"); cookie.setValue(UUID32.getUUID()); response.addCookie(cookie); logger.debug("remove user from cookie"); } } } HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(Constants.LOGIN_INFO); session.invalidate(); } }
From source file:com.google.identitytoolkit.GitkitClientTest.java
public void testGetOobCode() throws Exception { Cookie[] gitkitCookie = { new Cookie("gtoken", "fake-token") }; HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getCookies()).thenReturn(gitkitCookie); when(mockRequest.getParameter("action")).thenReturn("resetPassword"); when(mockRequest.getParameter("email")).thenReturn("1111@example.com"); when(mockRequest.getParameter("challenge")).thenReturn("what is the number"); when(mockRequest.getParameter("response")).thenReturn("8888"); when(mockRequest.getRemoteUser()).thenReturn("1.1.1.1"); String expectedApiUrl = GitkitClient.GITKIT_API_BASE + "getOobConfirmationCode"; when(mockSender.post(eq(expectedApiUrl), anyString(), eq(headers))) .thenReturn("{'oobCode':'fake-oob-code'}"); GitkitClient.OobResponse oobResponse = gitkitClient.getOobResponse(mockRequest); assertEquals(GitkitClient.OobAction.RESET_PASSWORD, oobResponse.getOobAction()); assertEquals("http://example.com:80/gitkit?mode=resetPassword&oobCode=fake-oob-code", oobResponse.getOobUrl().get()); }
From source file:com.glaf.core.util.RequestUtils.java
public static String getTheme(HttpServletRequest request) { String theme = "default"; Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), Constants.THEME_COOKIE)) { if (cookie.getValue() != null) { theme = cookie.getValue(); }//from w w w. j a v a2s .co m } } } if (StringUtils.isNotEmpty(request.getParameter("theme"))) { theme = request.getParameter("theme"); } return theme; }
From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthWebFilter.java
private Cookie[] getCookies(HttpServletRequest httpRequest) { Cookie[] cookies = httpRequest.getCookies(); return cookies == null ? new Cookie[0] : cookies; }
From source file:com.ctc.storefront.filters.CartRestorationFilter.java
protected void processRestoration(final HttpServletRequest request) { String cartGuid = null;/*from w w w .jav a 2s . 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:es.logongas.ix3.web.security.impl.WebSessionSidStorageImplAbstractJws.java
private String getJwsCompactInCookie(HttpServletRequest httpServletRequest) { Cookie[] cookies = httpServletRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (jwsCookieName.equals(cookie.getName())) { return cookie.getValue(); }/*from www . j a v a 2s . co m*/ } } return null; }
From source file:org.uaa.security.core.LogoutHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { String uri = request.getRequestURI(); // clear Cookies Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { log.debug(cookie.getName());// w w w . j a va2 s . c o m cookie.setMaxAge(0); response.addCookie(cookie); } // set response message ResponseWithStatus res = new ResponseWithStatus(uri, "0", ConfigUtil.getValue("00000")); response.setContentType("application/json;charset=UTF-8"); response.getOutputStream().write(res.toJson().getBytes()); return; }
From source file:com.glaf.core.util.RequestUtils.java
public static String getCookieValue(HttpServletRequest request, String name) { String value = null;//from w w w . j ava2s. c o m Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), name)) { value = cookie.getValue(); } } } return value; }