List of usage examples for javax.servlet.http Cookie setSecure
public void setSecure(boolean flag)
From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java
static void removeCredentialCookies(final HttpServletRequest request, final HttpServletResponse response) { Arrays.stream(request.getCookies()) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)).forEach(c -> { final Cookie removal = new Cookie(c.getName(), ""); removal.setPath("/"); removal.setMaxAge(0);/* w w w . j a va 2s . c o m*/ removal.setHttpOnly(true); removal.setSecure(true); response.addCookie(removal); }); }
From source file:org.beanfuse.utils.web.CookieUtils.java
/** * Convenience method to set a cookie <br> * value?<br>/*from w ww .j av a2 s. co m*/ * * @param response * @param name * @param value * @param path */ public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String path, int age) { LOG.debug("add cookie[name:{},value={},path={}]", new String[] { name, value, path }); Cookie cookie = null; try { cookie = new Cookie(name, new URLCodec().encode(value, "utf-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(age); response.addCookie(cookie); }
From source file:org.wso2.carbon.identity.oidc.session.util.OIDCSessionManagementUtil.java
/** * Adds the browser state cookie to the response * * @param response//www.j a v a 2 s . c o m * @return Cookie */ public static Cookie addOPBrowserStateCookie(HttpServletResponse response) { Cookie cookie = new Cookie(OIDCSessionConstants.OPBS_COOKIE_ID, UUID.randomUUID().toString()); cookie.setSecure(true); cookie.setPath("/"); response.addCookie(cookie); return cookie; }
From source file:io.lavagna.web.helper.UserSession.java
private static void addRememberMeCookie(int userId, HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { String token = userRepository.createRememberMeToken(userId); ///*from w w w.j a va 2s. c om*/ Cookie c = new Cookie("LAVAGNA_REMEMBER_ME", userId + "," + token); c.setPath(req.getContextPath() + "/"); c.setHttpOnly(true); c.setMaxAge(60 * 60 * 24 * 365); // 1 year if (req.getServletContext().getSessionCookieConfig().isSecure()) { c.setSecure(true); } resp.addCookie(c); }
From source file:org.wso2.carbon.identity.oidc.session.util.OIDCSessionManagementUtil.java
/** * Invalidate the browser state cookie//from w ww .jav a 2s.c o m * * @param request * @param response * @return invalidated cookie */ public static Cookie removeOPBrowserStateCookie(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(OIDCSessionConstants.OPBS_COOKIE_ID)) { cookie.setMaxAge(0); cookie.setSecure(true); cookie.setPath("/"); response.addCookie(cookie); return cookie; } } } return null; }
From source file:org.wso2.carbon.identity.provider.openid.util.OpenIDUtil.java
public static void setCookie(String name, String value, int expires, String path, boolean secure, HttpServletResponse resp) {// ww w .j a v a 2s . c o m Cookie cookie = new Cookie(name, value); cookie.setMaxAge(expires); cookie.setPath(path); cookie.setSecure(secure); resp.addCookie(cookie); }
From source file:com.lushapp.common.web.utils.WebUtils.java
/** * cookie.//w ww . j a va 2 s. c o m * @param response * @param name * @param value * @param path */ public static void setCookie(HttpServletResponse response, String name, String value, String path) { if (logger.isDebugEnabled()) { logger.debug("Cookie '" + name + "',?: '" + path + "'"); } Cookie cookie = new Cookie(name, value); cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(2592000); response.addCookie(cookie); }
From source file:com.vmware.identity.samlservice.Shared.java
/** * Adding a browser session cookie to browser. * @param cookieName// ww w . j a v a2 s .c o m * @param cookieValue * @param response */ public static void addSessionCookie(String cookieName, String cookieValue, HttpServletResponse response) { Validate.notNull(response); if (cookieName == null || cookieName.isEmpty() || cookieValue == null || cookieValue.isEmpty()) { log.warn("Cookie name/value is null or empty. Ignoring."); return; } log.debug("Setting cookie " + cookieName + " value " + cookieValue); Cookie sessionCookie = new Cookie(cookieName, cookieValue); sessionCookie.setPath("/"); sessionCookie.setSecure(true); sessionCookie.setHttpOnly(true); response.addCookie(sessionCookie); }
From source file:org.projectforge.web.UserFilter.java
/** * Adds or refresh the given cookie.//from w w w.j a va 2 s .c o m * @param request * @param response * @param stayLoggedInCookie */ public static void addStayLoggedInCookie(final HttpServletRequest request, final HttpServletResponse response, final Cookie stayLoggedInCookie) { stayLoggedInCookie.setMaxAge(COOKIE_MAX_AGE); stayLoggedInCookie.setPath("/"); if (request.isSecure() == true) { log.debug("Set secure cookie"); stayLoggedInCookie.setSecure(true); } else { log.debug("Set unsecure cookie"); } response.addCookie(stayLoggedInCookie); // Refresh cookie. }
From source file:org.projectforge.business.user.filter.UserFilter.java
/** * Adds or refresh the given cookie.//from w ww . ja va2s . c o m * * @param request * @param response * @param stayLoggedInCookie */ public static void addStayLoggedInCookie(final HttpServletRequest request, final HttpServletResponse response, final Cookie stayLoggedInCookie) { stayLoggedInCookie.setMaxAge(COOKIE_MAX_AGE); stayLoggedInCookie.setPath("/"); if (request.isSecure() == true) { log.debug("Set secure cookie"); stayLoggedInCookie.setSecure(true); } else { log.debug("Set unsecure cookie"); } stayLoggedInCookie.setHttpOnly(true); response.addCookie(stayLoggedInCookie); // Refresh cookie. }