List of usage examples for javax.servlet.http Cookie setSecure
public void setSecure(boolean flag)
From source file:org.jasig.portlet.test.mvc.tests.CookieTestController.java
/** * Generates a new cookie with random name and value. * * @param response/*w w w .j a v a 2 s.co m*/ */ @ActionMapping(value = "randomCookieAction") protected void createRandomCookie(ActionRequest request, ActionResponse response) { final String name = RandomStringUtils.randomAlphabetic(8); final String value = RandomStringUtils.randomAlphanumeric(8); Cookie cookie = new Cookie(name, value); cookie.setComment("Random Cookie Test comment"); cookie.setMaxAge(-1); cookie.setSecure(request.isSecure()); response.addProperty(cookie); }
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); expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); assertNoHeaderAdjustments();// ww w . ja v a 2s . c om }
From source file:com.acc.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(response, "cookie_monster"); final Cookie expectedCookie = new Cookie(JSESSIONID, "cookie_monster"); expectedCookie.setPath("/some_path"); expectedCookie.setSecure(false); 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:org.apache.falcon.resource.admin.AdminResource.java
@GET @Path("clearuser") @Produces(MediaType.TEXT_PLAIN)/*from w w w. j a v a 2 s .co m*/ public String clearUser(@Context HttpServletResponse response) { if (!SecurityUtil.isSecurityEnabled()) { Cookie cookie = new Cookie("hadoop.auth", null); cookie.setPath("/"); cookie.setMaxAge(0); cookie.setSecure(false); response.addCookie(cookie); } // Else, Do not checkin User, security is handled via Kerberos. return "ok"; }
From source file:org.openo.auth.service.impl.TokenServiceImpl.java
/** * Perform Logout Operation.//from w w w .j a v a 2 s .com * <br/> * * @param request : HttpServletRequest Object * @param response : HttpServletResponse Object * @return response status for the operation. * @since */ public int logout(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); String authToken = ""; for (int i = 0; i < cookies.length; i++) { if (Constant.TOKEN_AUTH.equals(cookies[i].getName())) { authToken = cookies[i].getValue(); LOGGER.info("authToken " + authToken); break; } } Cookie authCookie = new Cookie(Constant.TOKEN_AUTH, null); authCookie.setMaxAge(0); authCookie.setSecure(true); response.addCookie(authCookie); int status = TokenServiceClient.getInstance().doLogout(authToken); response.setStatus(status); return status; }
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); expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); assertNoHeaderAdjustments();/*w ww . j a v a 2 s. co m*/ }
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); 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); expectedCookie.setMaxAge(NEVER_EXPIRES); expectedCookie.setDomain("what a domain"); Mockito.verify(response).addCookie(Mockito.argThat(new CookieArgumentMatcher(expectedCookie))); assertNoHeaderAdjustments();/*from w ww . j a v a 2 s.c o m*/ }
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); 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.mawujun.util.web.CookieGenerator.java
/** * Add a cookie with the given value to the response, * using the cookie descriptor settings of this generator. * <p>Delegates to <code>createCookie</code> for cookie creation. * @param response the HTTP response to add the cookie to * @param cookieValue the value of the cookie to add * @see #setCookieName/*w w w . j a v a2s . co m*/ * @see #setCookieDomain * @see #setCookiePath * @see #setCookieMaxAge * @see #createCookie */ public void addCookie(HttpServletResponse response, String cookieValue) { Cookie cookie = createCookie(cookieValue); cookie.setMaxAge(getCookieMaxAge()); if (isCookieSecure()) { cookie.setSecure(true); } response.addCookie(cookie); if (logger.isDebugEnabled()) { logger.debug("Added cookie with name [" + getCookieName() + "] and value [" + cookieValue + "]"); } }