List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubLogin.java
private String getScopesKey(HttpServletRequest request, HttpServletResponse response) { String scopeRequested = request.getParameter("scope"); if (scopeRequested == null) { scopeRequested = getScopesKeyFromCookie(request); }//from www . j a v a2s . c o m if (scopeRequested != null) { Cookie scopeCookie = new Cookie("scope", scopeRequested); scopeCookie.setPath("/"); scopeCookie.setMaxAge((int) SCOPE_COOKIE_NEVER_EXPIRES); response.addCookie(scopeCookie); } return Objects.firstNonNull(scopeRequested, "scopes"); }
From source file:org.apereo.portal.url.UrlCanonicalizingFilter.java
protected void setRedirectCount(HttpServletRequest request, HttpServletResponse response, int count) { final Cookie cookie = new Cookie(COOKIE_NAME, Integer.toString(count)); cookie.setPath(request.getContextPath()); cookie.setMaxAge(30);/*from w w w. j av a 2 s.c om*/ response.addCookie(cookie); }
From source file:nl.strohalm.cyclos.controls.access.ExternalLoginAction.java
@Override public void prepareForm(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request, final HttpServletResponse response) { // Resolve the translation messages for each status final Map<String, String> statusMessages = new HashMap<String, String>(); for (final Status status : Status.values()) { final String key = status.getKey(); if (key != null) { String argument = status.getArgument(); if (argument != null) { // The argument is actually a key to another message argument = messageHelper.message(argument); }//from w ww . j a va2s. com statusMessages.put(status.name(), messageHelper.message(key, argument)); } } request.setAttribute("statusMessages", statusMessages); // Store a cookie in order to know where to go after logout String afterLogout = request.getParameter("afterLogout"); afterLogout = StringUtils.trimToEmpty(afterLogout); try { final LocalSettings settings = settingsService.getLocalSettings(); afterLogout = URLEncoder.encode(StringUtils.trimToEmpty(afterLogout), settings.getCharset()); } catch (final UnsupportedEncodingException e) { } final Cookie cookie = new Cookie("afterLogout", afterLogout); cookie.setPath(request.getContextPath()); response.addCookie(cookie); }
From source file:de.appsolve.padelcampus.utils.LoginUtil.java
private void deleteCookie(HttpServletRequest request, HttpServletResponse response, String path) { Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, null); cookie.setDomain(request.getServerName()); cookie.setMaxAge(0);/*from w w w . ja va 2s . c om*/ if (!StringUtils.isEmpty(path)) { cookie.setPath(path); } response.addCookie(cookie); }
From source file:es.logongas.ix3.web.security.impl.WebSessionSidStorageImplAbstractJws.java
@Override public void deleteSid(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { Cookie cookie = new Cookie(jwsCookieName, ""); cookie.setHttpOnly(false);/*from w ww . j a v a 2 s . com*/ cookie.setPath(httpServletRequest.getContextPath() + "/"); httpServletResponse.addCookie(cookie); }
From source file:com.companyname.services.OnLoginSuccessHandler.java
private Cookie createCookie(HttpServletRequest request, String name, String value) { logger.info("create a new token with name: " + name); Cookie cookie = new Cookie(name, value); cookie.setDomain(getCookieDomain()); cookie.setPath(getCookiePath(request)); cookie.setMaxAge(getCookieExpireTimeLength()); return cookie; }
From source file:com.persistent.cloudninja.web.security.CNAuthenticationProcessingFilter.java
/** * This method queries the database for the respective member and tries to get the logo url.<br/> * if found create the cookie with value as URL returns cookie with empty string * /* w w w . j a v a 2 s . c om*/ * * @param memberId * @return */ private Cookie createLogoCookie(String tenantId) { String logoUrl = ""; // DAO to get the URL Tenant tenant = hibernateTemplate.get(Tenant.class, tenantId); String logoFilename = tenant.getLogoFileName(); if (null == logoFilename || logoFilename.trim().length() == 0) { // logoUrl = ""; } else { // create logo URL from config property file logoUrl = getUrlFromConfig(logoFilename, tenantId); } Cookie logoCokie = new Cookie("CLOUDNINJALOGO", logoUrl); logoCokie.setMaxAge(-1); logoCokie.setPath("/"); return logoCokie; }
From source file:com.liferay.portal.action.LogoutAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception { try {//w w w .j av a 2 s .c o m HttpSession ses = req.getSession(); try { // Logger.info(this, "User " + // PortalUtil.getUser(req).getFullName() + " (" + // PortalUtil.getUser(req).getUserId() + // ") has logged out from IP: " + req.getRemoteAddr()); SecurityLogger.logInfo(this.getClass(), "User " + PortalUtil.getUser(req).getFullName() + " (" + PortalUtil.getUser(req).getUserId() + ") has logged out from IP: " + req.getRemoteAddr()); } catch (Exception e) { //Logger.info(this, "User has logged out from IP: " + req.getRemoteAddr()); SecurityLogger.logInfo(this.getClass(), "User has logged out from IP: " + req.getRemoteAddr()); } EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_PRE), req, res); ArrayList<Cookie> al = new ArrayList<Cookie>(); Cookie[] cookies = req.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; al.add(cookie); cookie.setMaxAge(0); cookie.setPath("/"); res.addCookie(cookie); } } Map sessions = PortletSessionPool.remove(ses.getId()); if (sessions != null) { Iterator itr = sessions.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); HttpSession portletSession = (HttpSession) entry.getValue(); portletSession.invalidate(); } } try { ses.invalidate(); } catch (Exception e) { } EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_POST), req, res); // ActionForward af = mapping.findForward("referer"); // return af; return mapping.findForward(Constants.COMMON_REFERER); } catch (Exception e) { req.setAttribute(PageContext.EXCEPTION, e); return mapping.findForward(Constants.COMMON_REFERER); } }
From source file:org.openo.auth.service.impl.TokenServiceImpl.java
/** * Perform Login Operation./*from w ww .j a v a 2s .c o m*/ * <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:com.concursive.connect.web.modules.login.auth.session.SessionValidator.java
/** * Follow the current session validation schema and determine if there is a * valid session for the user. If there is a valid session, return the * <code>User</code> associated with that session, otherwise, return * <i>null</i>./*from w w w . j a v a 2 s. c o m*/ * * @param request - * The servlet request as provided by the * <code>ControllerServlet</code>. * @return A valid <code>User</code> upon successful validation.<br> * <code>Null</code> upon validation failure */ public User validateSession(ServletContext context, HttpServletRequest request, HttpServletResponse response) { User thisUser = (User) request.getSession(false).getAttribute(Constants.SESSION_USER); LOG.debug("Has user session: " + (thisUser != null)); if (thisUser == null || !thisUser.isLoggedIn()) { LOG.debug("Checking for cookie..."); // Check cookie for session info and generate a logged in user String guid = CookieUtils.getCookieValue(request, Constants.COOKIE_USER_GUID); if (guid == null) { LOG.debug("No cookie found."); return (thisUser == null ? null : thisUser); } LOG.debug("Cookie found with guid: " + guid); // Retrieve prefs to see if user with guid exists ApplicationPrefs prefs = (ApplicationPrefs) context.getAttribute(Constants.APPLICATION_PREFS); // Connection info ConnectionElement ce = new ConnectionElement(); ce.setDriver(prefs.get("SITE.DRIVER")); ce.setUrl(prefs.get("SITE.URL")); ce.setUsername(prefs.get("SITE.USER")); ce.setPassword(prefs.get("SITE.PASSWORD")); ConnectionPool sqlDriver = (ConnectionPool) context.getAttribute(Constants.CONNECTION_POOL); Connection db = null; try { db = sqlDriver.getConnection(ce); // Load the user record from the guid thisUser = UserUtils.loadUserFromGuid(db, guid); if (thisUser != null) { // Track the login thisUser.updateLogin(db, request, prefs, null); thisUser.setBrowserType(request.getHeader("USER-AGENT")); // Apply defaults UserUtils.createLoggedInUser(thisUser, db, prefs, context); // Extend the cookie Cookie userCookie = new Cookie(Constants.COOKIE_USER_GUID, UserUtils.generateGuid(thisUser)); userCookie.setPath("/"); // 14 day cookie userCookie.setMaxAge(14 * 24 * 60 * 60); response.addCookie(userCookie); } } catch (Exception e) { thisUser = null; e.printStackTrace(); } finally { if (db != null) { sqlDriver.free(db); } } // Add to session request.getSession().setAttribute(Constants.SESSION_USER, thisUser); request.getSession().setAttribute(Constants.SESSION_CONNECTION_ELEMENT, ce); } return thisUser; }