List of usage examples for javax.servlet.http Cookie setSecure
public void setSecure(boolean flag)
From source file:org.openo.auth.service.impl.TokenServiceImpl.java
/** * Perform Login Operation./*from w w w . j a v a2 s. c om*/ * <br/> * * @param request : HttpServletRequest Object * @param response : HttpServletResponse Object * @return response for the login operation. * @since */ public Response login(HttpServletRequest request, HttpServletResponse response) { final UserCredentialUI userInfo = CommonUtil.getInstance().getUserInfoCredential(request); final KeyStoneConfiguration keyConf = KeyStoneConfigInitializer.getKeystoneConfiguration(); final String json = getJsonService().getLoginJson(userInfo, keyConf); LOGGER.info("json is created = " + json); ClientResponse resp = TokenServiceClient.getInstance().doLogin(json); int status = resp.getStatus(); Cookie authToken = new Cookie(Constant.TOKEN_AUTH, resp.getHeader()); authToken.setPath("/"); authToken.setSecure(true); response.addCookie(authToken); LOGGER.info("login result status : " + status); LOGGER.info("login's user is : " + userInfo.getUserName()); LOGGER.info("login's token is : " + resp.getHeader()); return Response.status(status).cookie(new NewCookie(Constant.TOKEN_AUTH, resp.getHeader())).entity("[]") .header(Constant.TOKEN_AUTH, resp.getHeader()).build(); }
From source file:org.josso.gateway.signon.RememberMeLoginAction.java
@Override protected boolean onFatalError(Exception e, HttpServletRequest request, HttpServletResponse response) { logger.debug("Removing cookie with 'JOSSO_REMEMBERME_TOKEN' (fatal error)"); // Clear the remember me cookie Cookie ssoCookie = new Cookie( Constants.JOSSO_REMEMBERME_TOKEN + "_" + SSOContext.getCurrent().getSecurityDomain().getName(), "-"); ssoCookie.setMaxAge(0);// w w w . j a v a 2 s . c o m ssoCookie.setSecure(true); ssoCookie.setPath("/"); response.addCookie(ssoCookie); return super.onFatalError(e, request, response); }
From source file:org.josso.gateway.signon.RememberMeLoginAction.java
@Override protected boolean onLoginAuthenticationException(AuthenticationFailureException e, HttpServletRequest request, HttpServletResponse response, Credential[] credentials) throws IOException { logger.debug("Removing cookie with 'JOSSO_REMEMBERME_TOKEN' (login auth exception)"); // Clear the remember me cookie Cookie ssoCookie = new Cookie(org.josso.gateway.Constants.JOSSO_REMEMBERME_TOKEN + "_" + SSOContext.getCurrent().getSecurityDomain().getName(), "-"); ssoCookie.setMaxAge(0);/*from w ww . j av a 2 s. c o m*/ ssoCookie.setSecure(true); ssoCookie.setPath("/"); response.addCookie(ssoCookie); return super.onLoginAuthenticationException(e, request, response, credentials); }
From source file:org.orcid.core.manager.impl.InternalSSOManagerImpl.java
private void populateCookie(String orcid, String token, HttpServletRequest request, HttpServletResponse response) {/*from w ww . j a v a2s . co m*/ HashMap<String, String> cookieValues = new HashMap<String, String>(); cookieValues.put(COOKIE_KEY_ORCID, orcid); cookieValues.put(COOKIE_KEY_TOKEN, token); String jsonCookie = JsonUtils.convertToJsonString(cookieValues); // Return it as a cookie in the response Cookie tokenCookie = new Cookie(COOKIE_NAME, jsonCookie); tokenCookie.setMaxAge(maxAgeMinutes * 60); tokenCookie.setPath("/"); tokenCookie.setSecure(true); tokenCookie.setHttpOnly(true); tokenCookie.setDomain(allowedDomain.trim()); response.addCookie(tokenCookie); }
From source file:org.springframework.web.util.CookieGenerator.java
/** * Remove the cookie that this generator describes from the response. * Will generate a cookie with empty value and max age 0. * <p>Delegates to {@link #createCookie} for cookie creation. * @param response the HTTP response to remove the cookie from * @see #setCookieName/*from w w w.j av a 2s. c om*/ * @see #setCookieDomain * @see #setCookiePath */ public void removeCookie(HttpServletResponse response) { Assert.notNull(response, "HttpServletResponse must not be null"); Cookie cookie = createCookie(""); cookie.setMaxAge(0); if (isCookieSecure()) { cookie.setSecure(true); } if (isCookieHttpOnly()) { cookie.setHttpOnly(true); } response.addCookie(cookie); if (logger.isDebugEnabled()) { logger.debug("Removed cookie with name [" + getCookieName() + "]"); } }
From source file:com.vmware.identity.openidconnect.server.LogoutRequestProcessor.java
private Cookie loggedOutSessionCookie() { Cookie cookie = new Cookie(SessionManager.getSessionCookieName(this.tenant), ""); cookie.setPath("/openidconnect"); cookie.setSecure(true); cookie.setHttpOnly(true);// ww w. ja v a 2 s . c o m cookie.setMaxAge(0); return cookie; }
From source file:com.hypersocket.session.json.SessionUtils.java
public void addAPISession(HttpServletRequest request, HttpServletResponse response, Session session) { Cookie cookie = new Cookie(HYPERSOCKET_API_SESSION, session.getId()); cookie.setMaxAge(60 * session.getTimeout()); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setPath("/"); //cookie.setDomain(request.getServerName()); response.addCookie(cookie);/*from w ww . j a va 2 s.co m*/ }
From source file:org.orcid.core.manager.impl.InternalSSOManagerImpl.java
@Override public void getAndUpdateCookie(String orcid, HttpServletRequest request, HttpServletResponse response) { InternalSSOEntity existingCookie = internalSSODao.find(orcid); if (existingCookie != null) { internalSSODao.update(existingCookie.getId(), existingCookie.getToken()); HashMap<String, String> cookieValues = new HashMap<String, String>(); cookieValues.put(COOKIE_KEY_ORCID, orcid); cookieValues.put(COOKIE_KEY_TOKEN, existingCookie.getToken()); String jsonCookie = JsonUtils.convertToJsonString(cookieValues); Cookie tokenCookie = new Cookie(COOKIE_NAME, jsonCookie); tokenCookie.setMaxAge(maxAgeMinutes * 60); tokenCookie.setPath("/"); tokenCookie.setSecure(true); tokenCookie.setHttpOnly(true);/*from ww w . j a v a2 s.co m*/ tokenCookie.setDomain(allowedDomain.trim()); //Add new cookie to response response.addCookie(tokenCookie); } }
From source file:com.hypersocket.session.json.SessionUtils.java
public void setLocale(HttpServletRequest request, HttpServletResponse response, String locale) { request.getSession().setAttribute(USER_LOCALE, locale); Cookie cookie = new Cookie(HYPERSOCKET_LOCALE, locale); cookie.setMaxAge(Integer.MAX_VALUE); cookie.setPath("/"); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setDomain(request.getServerName()); response.addCookie(cookie);//from w w w . ja v a 2 s .c o m }
From source file:com.adito.language.actions.SelectLanguageAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String referer = DAVUtilities.encodePath(CoreUtil.getRequestReferer(request), false); if (referer == null) { throw new CoreException(ErrorConstants.ERR_MISSING_REQUEST_PARAMETER, ErrorConstants.CATEGORY_NAME, "referer"); }/*from ww w . j ava 2 s . c o m*/ String localeCode = request.getParameter("locale"); if (localeCode == null) { throw new CoreException(ErrorConstants.ERR_MISSING_REQUEST_PARAMETER, ErrorConstants.CATEGORY_NAME, "locale"); } /* Tokenize the locale parameter so we only get the first line. This prevents * a header injection exploit as the (not validated) locale gets added as * a cookie. */ StringTokenizer t = new StringTokenizer(localeCode); String locale = t.nextToken(); // Parse the locale code String country = ""; String variant = ""; String lang = locale; int idx = locale.indexOf("_"); if (idx != -1) { country = lang.substring(idx + 1); lang = lang.substring(0, idx); } idx = country.indexOf('_'); if (idx != -1) { variant = country.substring(idx + 1); country = country.substring(0, idx); } // Store the new locale in the session and set a persistant cookie Locale l = new Locale(lang, country, variant); request.getSession().setAttribute(Globals.LOCALE_KEY, l); Cookie cookie = new Cookie(SystemProperties.get("adito.cookie", "SSLX_SSESHID") + "_LANG", locale.toString()); cookie.setMaxAge(60 * 60 * 24 * 7); // a week cookie.setPath("/"); cookie.setSecure(true); response.addCookie(cookie); return referer == null ? mapping.findForward("home") : new ActionForward(referer, true); }