List of usage examples for javax.servlet.http Cookie Cookie
public Cookie(String name, String value)
From source file:com.woonoz.proxy.servlet.CookieFormatterTest.java
@Test(expected = InvalidCookieException.class) public void testCookieNullValue() throws InvalidCookieException { Cookie cookie = new Cookie("JSESSIONID", null); cookie.setPath("/"); CookieFormatter.createFromServletCookie(cookie); }
From source file:com.skilrock.lms.embedded.roleMgmt.common.PrivsInterceptor.java
public void createCookie() { boolean found = false; Cookie userSessionId = null;//w w w.j a v a2s . c o m Cookie[] cookies = request.getCookies(); for (Cookie element : cookies) { userSessionId = element; if (userSessionId.getName().equals("LMSCookie")) { found = true; break; } if (!found) { userSessionId = new Cookie("LMSCookie", ""); userSessionId.setMaxAge(24 * 60 * 60); userSessionId.setPath("/"); response.addCookie(userSessionId); } else { userSessionId.setMaxAge(24 * 60 * 60); userSessionId.setPath("/"); response.addCookie(userSessionId); } } }
From source file:com.parleys.server.frontend.web.ipad.filters.LoginFilter.java
@Override public void doFilter(final ServletRequest req, final ServletResponse response, final FilterChain chain) throws IOException { final HttpServletResponse res = (HttpServletResponse) response; final PrintWriter writer = res.getWriter(); res.setStatus(HttpServletResponse.SC_OK); res.setHeader("Cache-Control", "must-revalidate"); res.setHeader("Expires", "Fri, 30 Oct 1998 14:19:41 GMT"); try {// w w w . j a va 2s. c om final String username = req.getParameter("username"); final String password = req.getParameter("password"); if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { final ParleysService bean = applicationContext.getBean(ParleysService.class); final Long userId = bean.getUserId(username, password); final String usernameAndPassword = username + ";" + password; final String encrypted = AESEncrypter.INSTANCE.encrypt(usernameAndPassword); final Cookie rememberMeCookie = new Cookie(PARLEYS_REMEMBER_ME_IPAD, encrypted); rememberMeCookie.setMaxAge(3600 * 24 * 7 * 26); // A half year res.addCookie(rememberMeCookie); writeUserId(writer, userId); } else { writeError(writer); } } catch (Exception e) { writeError(writer); } }
From source file:cec.easyshop.storefront.security.cookie.EnhancedCookieGeneratorTest.java
@Test public void testClientSideCookieDynamicPath() { cookieGenerator.setCookieName(JSESSIONID); cookieGenerator.setHttpOnly(false);//client side cookieGenerator.setCookieSecure(true); cookieGenerator.setUseDefaultPath(false); BDDMockito.given(request.getContextPath()).willReturn("/some_path"); cookieGenerator.addCookie(response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(true);//from w w w . j a va2 s . c o m expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); assertNoHeaderAdjustments(); }
From source file:com.acc.storefront.security.cookie.EnhancedCookieGeneratorTest.java
@Test public void testClientSideCookieDynamicPath() { cookieGenerator.setCookieName(JSESSIONID); cookieGenerator.setHttpOnly(false);//client side cookieGenerator.setCookieSecure(true); cookieGenerator.setUseDefaultPath(false); BDDMockito.given(request.getContextPath()).willReturn("/some_path"); cookieGenerator.addCookie(response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(true);//from ww w . j a v a 2 s . c o m expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); assertNoHeaderAdjustments(); }
From source file:com.kcs.action.GenerateXmlDfFxmAction.java
private void setCookieDownloadStatus(String status) { Cookie cookie = new Cookie("downloadStatus", status); cookie.setMaxAge(60 * 60 * 24 * 365); // Make the cookie last a year HttpServletResponse response = ServletActionContext.getResponse(); response.addCookie(cookie);//from w w w . j a va 2 s . c o m }
From source file:org.craftercms.security.processors.impl.CurrentAuthenticationResolvingProcessorTest.java
@Test public void testGetAuthentication() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class); Date profileLastModified = new Date(); Cookie ticketCookie = new Cookie(SecurityUtils.TICKET_COOKIE_NAME, TICKET); Cookie profileLastModifiedCookie = new Cookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME, String.valueOf(profileLastModified.getTime())); request.setCookies(ticketCookie, profileLastModifiedCookie); Profile profile = new Profile(); profile.setLastModified(profileLastModified); Authentication auth = new DefaultAuthentication(TICKET, profile); when(authenticationManager.getAuthentication(TICKET, false)).thenReturn(auth); processor.processRequest(context, chain); verify(chain).processRequest(context); Authentication newAuth = SecurityUtils.getAuthentication(request); assertNotNull(newAuth);// w w w .j ava 2 s . co m assertEquals(auth.getTicket(), newAuth.getTicket()); assertEquals(auth.getProfile().getLastModified(), newAuth.getProfile().getLastModified()); }
From source file:com.skilrock.lms.web.roleMgmt.common.PrivsInterceptor.java
public void createCookie() { boolean found = false; Cookie userSessionId = null;//from ww w . j ava 2 s .com Cookie[] cookies = request.getCookies(); for (Cookie element : cookies) { userSessionId = element; if (userSessionId.getName().equals("LMSCookie")) { found = true; break; } } if (!found) { userSessionId = new Cookie("LMSCookie", ""); userSessionId.setMaxAge(24 * 60 * 60); userSessionId.setPath("/"); response.addCookie(userSessionId); } else { userSessionId.setMaxAge(24 * 60 * 60); userSessionId.setPath("/"); response.addCookie(userSessionId); } }
From source file:com.demandware.vulnapp.challenge.impl.CookieChallenge.java
@SuppressWarnings("unchecked") private Cookie generateCookie() { JSONObject o = new JSONObject(); o.put(ACCESS_KEY, "false"); String value = new String(Base64.encodeBase64(o.toJSONString().getBytes())); Cookie c = new Cookie(COOKIE_NAME, value); c.setMaxAge(MAX_AGE);//ww w . ja v a2 s. co m c.setPath("/"); return c; }
From source file:com.arya.latihan.config.SecurityConfiguration.java
/** * Method untuk menyimpan CSRF TOKEN di cookie browser. * Token disimpan dengan nama XSRF-TOKEN karena AngularJS mengenal CSRF sebagai XSRF * @return Filter/*from w w w. j a v a 2s .c o m*/ */ private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrfToken != null) { String token = csrfToken.getToken(); Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");// angular js menamai CSRF dengan XSRF if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie); } } filterChain.doFilter(request, response); } }; }