List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:de.hybris.platform.ytelcoacceleratorstorefront.security.cookie.EnhancedCookieGeneratorTest.java
@Test public void testClientSideCookieDefaultPath() { cookieGenerator.setCookieName(JSESSIONID); cookieGenerator.setHttpOnly(false);//client side cookieGenerator.addCookie(request, response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/"); expectedCookie.setSecure(false);/* w ww .ja 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:org.nuxeo.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, Throwable t) throws IOException, ServletException { Throwable unwrappedException = unwrapException(t); if (!ExceptionHelper.isSecurityError(unwrappedException) && !response.containsHeader(SSO_INITIAL_URL_REQUEST_KEY)) { super.handleException(request, response, t); return;// www . ja v a 2s. c o m } Principal principal = request.getUserPrincipal(); NuxeoPrincipal nuxeoPrincipal = null; if (principal instanceof NuxeoPrincipal) { nuxeoPrincipal = (NuxeoPrincipal) principal; // redirect to login than to requested page if (nuxeoPrincipal.isAnonymous()) { response.resetBuffer(); String urlToReach = getURLToReach(request); Cookie cookieUrlToReach = new Cookie(NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY, urlToReach); cookieUrlToReach.setPath("/"); cookieUrlToReach.setMaxAge(60); response.addCookie(cookieUrlToReach); if (!response.isCommitted()) { request.getRequestDispatcher(CAS_REDIRECTION_URL).forward(request, response); } FacesContext.getCurrentInstance().responseComplete(); } } // go back to default handler super.handleException(request, response, t); }
From source file:com.epam.cme.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(request, response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(true);//from w w 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.epam.cme.storefront.security.cookie.EnhancedCookieGeneratorTest.java
@Test public void testServerSideCookieDynamicPath() { cookieGenerator.setCookieName(JSESSIONID); cookieGenerator.setHttpOnly(true);// server side cookieGenerator.setUseDefaultPath(false); BDDMockito.given(request.getContextPath()).willReturn("/some_path"); cookieGenerator.addCookie(request, response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(false);/*www . j a va 2 s. c o m*/ expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); Mockito.verify(response).addHeader(EnhancedCookieGenerator.HEADER_COOKIE, "JSESSIONID=cookie_monster; Domain=\"what a domain\"; Path=/; HttpOnly"); }
From source file:de.hybris.platform.ytelcoacceleratorstorefront.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(request, response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(true);/*from w ww. 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:de.hybris.platform.ytelcoacceleratorstorefront.security.cookie.EnhancedCookieGeneratorTest.java
@Test public void testServerSideCookieDynamicPath() { cookieGenerator.setCookieName(JSESSIONID); cookieGenerator.setHttpOnly(true);//server side cookieGenerator.setUseDefaultPath(false); BDDMockito.given(request.getContextPath()).willReturn("/some_path"); cookieGenerator.addCookie(request, response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(false);//w w w.j av a 2 s . c o m expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); Mockito.verify(response).addHeader(EnhancedCookieGenerator.HEADER_COOKIE, "JSESSIONID=cookie_monster; Domain=\"what a domain\"; Path=/; HttpOnly"); }
From source file:com.persistent.cloudninja.web.security.CNAuthenticationProcessingFilter.java
private Cookie createCookie(User user, String currentCookie) { String newCookieValue = userDetailsService.createCookieValueFromUser(user); String cookieToUse = currentCookie; if (!currentCookie.equals(newCookieValue)) cookieToUse = newCookieValue;/* w w w. j a v a 2 s . c o m*/ Cookie cookie = new Cookie(cookieName, cookieToUse); cookie.setMaxAge(-1); cookie.setPath("/"); return cookie; }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, Throwable t) throws IOException, ServletException { @SuppressWarnings("deprecation") Throwable unwrappedException = unwrapException(t); log.debug("handleException#in"); if (!ExceptionHelper.isSecurityError(unwrappedException) && !response.containsHeader(SSO_INITIAL_URL_REQUEST_KEY)) { super.handleException(request, response, t); return;/*from w w w. j a v a 2 s. c om*/ } Principal principal = request.getUserPrincipal(); NuxeoPrincipal nuxeoPrincipal = null; if (principal instanceof NuxeoPrincipal) { nuxeoPrincipal = (NuxeoPrincipal) principal; // redirect to login than to requested page if (nuxeoPrincipal.isAnonymous()) { response.resetBuffer(); String urlToReach = getURLToReach(request); log.debug(String.format("handleException#urlToReach#%s", urlToReach)); Cookie cookieUrlToReach = new Cookie(NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY, urlToReach); cookieUrlToReach.setPath("/"); cookieUrlToReach.setMaxAge(60); response.addCookie(cookieUrlToReach); log.debug(String.format("handleException#cookieUrlToReach#%s", cookieUrlToReach.getName())); if (!response.isCommitted()) { request.getRequestDispatcher(CAS_REDIRECTION_URL).forward(request, response); } FacesContext.getCurrentInstance().responseComplete(); } } // go back to default handler super.handleException(request, response, t); }
From source file:com.persistent.cloudninja.web.security.CloudNinjaRemembermeService.java
/** * On logout, invalidate the cookie and send back in the response *//*from www .jav a2s .c o m*/ public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { String cookieName = getCookieName(); Cookie cookieToInvalidate = getCoockieFromRequest(request, cookieName); if (null != cookieToInvalidate) { cookieToInvalidate.setMaxAge(0); cookieToInvalidate.setPath("/"); response.addCookie(cookieToInvalidate); } cookieToInvalidate = getCoockieFromRequest(request, "CLOUDNINJALOGO"); if (null != cookieToInvalidate) { cookieToInvalidate.setMaxAge(0); cookieToInvalidate.setPath("/"); response.addCookie(cookieToInvalidate); } }
From source file:org.sharetask.controller.UserController.java
@RequestMapping(value = "/login", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public void performLogin(@RequestBody final UserPassword login, final HttpServletRequest request, final HttpServletResponse response) { final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( login.getUsername(), login.getPassword()); try {//from w ww . j a va 2 s .co m final Authentication auth = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(auth); repository.saveContext(SecurityContextHolder.getContext(), request, response); rememberMeServices.loginSuccess(request, response, auth); // language cookie final UserInfoDTO user = userService.read(SecurityUtil.getCurrentSignedInUsername()); final Cookie locale = new Cookie(RequestUltil.LOCALE, user.getLanguage()); locale.setMaxAge(-1); locale.setPath("/"); response.addCookie(locale); response.setStatus(HttpStatus.OK.value()); } catch (final BadCredentialsException ex) { response.setStatus(HttpStatus.UNAUTHORIZED.value()); } }