Remove expired session only portlet cookies.

@param request
552650
protected void removeExpiredPortletCookies(HttpServletRequest request) {
        Map<String, SessionOnlyPortletCookieImpl> sessionOnlyCookies =
                getSessionOnlyPortletCookieMap(request);
        for (Entry<String, SessionOnlyPortletCookieImpl> entry : sessionOnlyCookies.entrySet()) {
            String key = entry.getKey();
            SessionOnlyPortletCookieImpl sessionOnlyCookie = entry.getValue();
            if (sessionOnlyCookie.getExpires().isBeforeNow()) {
                sessionOnlyCookies.remove(key);
            }
        }
    }
135684
@Override
	public void serviceRequest(final Request request) {
		// Get the expected session token
		UIContext uic = UIContextHolder.getCurrent();
		String expected = uic.getEnvironment().getSessionToken();

		// Session token should already be set
		if (expected == null) {
			LOG.error("Session token should already be set on the session before AJAX request. Can be due to the session timing out.");
			handleError();
		}

		// Get the session token from the request
		String got = request.getParameter(Environment.SESSION_TOKEN_VARIABLE);

		// Check tokens match (both must be provided)
		if (Util.equals(expected, got)) {
			// Process Service Request
			getBackingComponent().serviceRequest(request);
		} else { // Invalid token
			LOG.error("Wrong session token detected for AJAX request. Expected token [" + expected
					+ "] but got token [" + got + "].");
			handleError();
		}
	}
1287042
protected function cancelCookie(Request $request)
    {
        if (null !== $this->logger) {
            $this->logger->debug('Clearing remember-me cookie.', ['name' => $this->options['name']]);
        }

        $request->attributes->set(self::COOKIE_ATTR_NAME, new Cookie($this->options['name'], null, 1, $this->options['path'], $this->options['domain'], $this->options['secure'] ?? $request->isSecure(), $this->options['httponly'], false, $this->options['samesite'] ?? null));
    }
1346021
public void deleteCookie(Cookie cookie) {
        cookies.remove(cookie.name());
        deletePersistedCookie(cookie.name());
    }
927741
public void closeSession(long index, long timestamp, RaftSession session, boolean expired) {
    log.debug("Closing session {}", session.sessionId());

    // Update the session's timestamp to prevent it from being expired.
    session.setLastUpdated(timestamp);

    // Update the state machine index/timestamp.
    tick(index, timestamp);

    // Expire sessions that have timed out.
    expireSessions(currentTimestamp);

    // Remove the session from the sessions list.
    if (expired) {
      session = sessions.removeSession(session.sessionId());
      if (session != null) {
        session.expire();
        service.expire(session.sessionId());
      }
    } else {
      session = sessions.removeSession(session.sessionId());
      if (session != null) {
        session.close();
        service.close(session.sessionId());
      }
    }

    // Commit the index, causing events to be sent to clients if necessary.
    commit();
  }
1189149
private boolean isFresh(final YokeRequest request) {
        // defaults
        boolean etagMatches = true;
        boolean notModified = true;

        // fields
        String modifiedSince = request.getHeader("if-modified-since");
        String noneMatch = request.getHeader("if-none-match");
        String[] noneMatchTokens = null;
        String lastModified = request.response().getHeader("last-modified");
        String etag = request.response().getHeader("etag");

        // unconditional request
        if (modifiedSince == null && noneMatch == null) {
            return false;
        }

        // parse if-none-match
        if (noneMatch != null) {
            noneMatchTokens = noneMatch.split(" *, *");
        }

        // if-none-match
        if (noneMatchTokens != null) {
            etagMatches = false;
            for (String s : noneMatchTokens) {
                if (etag.equals(s) || "*".equals(noneMatchTokens[0])) {
                    etagMatches = true;
                    break;
                }
            }
        }

        // if-modified-since
        if (modifiedSince != null) {
            try {
                Date modifiedSinceDate = parse(modifiedSince);
                Date lastModifiedDate = parse(lastModified);
                notModified = lastModifiedDate.getTime() <= modifiedSinceDate.getTime();
            } catch (ParseException e) {
                notModified = false;
            }
        }

        return etagMatches && notModified;
    }
734786
protected IPortalCookie getPortalCookie(HttpServletRequest request) {
        final Cookie cookie = this.getCookieFromRequest(this.cookieName, request);
        if (cookie == null) {
            // check the session
            IPortalCookie portalCookieInSession = locatePortalCookieInSession(request.getSession());
            if (null != portalCookieInSession) {
                return portalCookieInSession;
            }

            return null;
        }

        final String value = cookie.getValue();
        return this.portletCookieDao.getPortalCookie(value);
    }
319476
function expireSessionIDs(){
    var tssec = Date.now();
    var expired = [];
    for(var sid in sessionIDs){
        if(sessionIDs[sid] < (tssec + 500)){
            expired.push(sid);
        }
    }
    for(var i=0;i<expired.length;i++){
        delete sessionIDs[expired[i]];
        debug('Session ID expired: %s', expired[i]);
    }
}
908088
synchronized void unregisterRequest(HttpRequest request) {
		assertTrue(this == request.requestManager);
		boolean removed = activeRequests.remove(request);
		assertTrue(removed, "Attempted to unregister missing request: %s", request);

		if (removed) {
			notifyRequestFinished(request);
		}
	}
403648
public void remove(Cookie cookie) {
		cookie.getHttpCookie().setExpiryDate(new Date(0));
		cookieRepresentationCache.remove(cookie.getHttpCookie());
		getStore().clearExpired(new Date(1));
	}
199046
public void init(HttpServletRequest request) {
		resetTimers();
		
		if (request != null) {
			String p = request.getPathInfo();
			final int pathLength = (p == null ? 0 : p.length());
			
			final StringBuffer urlSb = request.getRequestURL();
			String simpleUrl = urlSb.toString(); // without qs
			
			String qs = request.getQueryString();
			if (qs != null) urlSb.append("?").append(qs);
			final String fullUrl = urlSb.toString();
			contextUrl.set(fullUrl);
		
			requestCookies.remove();
			responseCookies.remove();
			
			StringBuilder cookiesDump = new StringBuilder();
			Map<String, Cookie> cookiez = requestCookies.get();
			for (javax.servlet.http.Cookie c : Check.ifNull(request.getCookies(), new javax.servlet.http.Cookie[0])) {
				cookiez.put(c.getName(), new BasicClientCookie(c.getName(), c.getValue()));
				cookiesDump.append(c.toString()).append(";");
			}
	
			String xForwardedFor = request.getHeader(HEADER_X_FORWARDED_FOR);
			clientIp.set(xForwardedFor != null ? xForwardedFor : request.getRemoteAddr());
			
			String xForwardedUrl = request.getHeader(HEADER_X_FORWARDED_URL);
			if (xForwardedUrl != null) {
				int i = xForwardedUrl.lastIndexOf("?");
				simpleUrl = (i == -1 ? xForwardedUrl : xForwardedUrl.substring(0, i));
			}
			
			try {
				simpleUrl = URLDecoder.decode(simpleUrl, "UTF-8"); // convert "%xx" stuff before working with lengths
			} catch (UnsupportedEncodingException e) {
				log.error(e.toString());
			}
			contextPath.set(simpleUrl.substring(0, simpleUrl.length() - pathLength));

			if (verbose) log.info(">>> Time 0 [" + fullUrl + "]. cookies from client: " + cookiesDump.toString());
		}
		
		initialized.set(true);
	}
1173323
@RequestHandler(dynamic = true)
    public void onRequest(Request.In event) {
        if (event.associated(Session.class).isPresent()) {
            return;
        }
        final HttpRequest request = event.httpRequest();
        Optional<String> requestedSessionId = request.findValue(
            HttpField.COOKIE, Converters.COOKIE_LIST)
            .flatMap(cookies -> cookies.stream().filter(
                cookie -> cookie.getName().equals(idName()))
                .findFirst().map(HttpCookie::getValue));
        if (requestedSessionId.isPresent()) {
            String sessionId = requestedSessionId.get();
            synchronized (this) {
                Optional<Session> session = lookupSession(sessionId);
                if (session.isPresent()) {
                    Instant now = Instant.now();
                    if ((absoluteTimeout <= 0
                        || Duration.between(session.get().createdAt(),
                            now).toMillis() < absoluteTimeout)
                        && (idleTimeout <= 0
                            || Duration.between(session.get().lastUsedAt(),
                                now).toMillis() < idleTimeout)) {
                        event.setAssociated(Session.class, session.get());
                        session.get().updateLastUsedAt();
                        return;
                    }
                    // Invalidate, too old
                    removeSession(sessionId);
                }
            }
        }
        String sessionId = createSessionId(request.response().get());
        Session session = createSession(sessionId);
        event.setAssociated(Session.class, session);
    }
1115922
def add_cookie_header(self, request):
        
        _debug("add_cookie_header")
        self._cookies_lock.acquire()
        try:

            self._policy._now = self._now = int(time.time())

            cookies = self._cookies_for_request(request)

            attrs = self._cookie_attrs(cookies)
            if attrs:
                if not request.has_header("Cookie"):
                    request.add_unredirected_header(
                        "Cookie", "; ".join(attrs))

            # if necessary, advertise that we know RFC 2965
            if (self._policy.rfc2965 and not self._policy.hide_cookie2 and
                not request.has_header("Cookie2")):
                for cookie in cookies:
                    if cookie.version != 1:
                        request.add_unredirected_header("Cookie2", '$Version="1"')
                        break

        finally:
            self._cookies_lock.release()

        self.clear_expired_cookies()
309603
@Override
	public void removeRequest(HttpServletRequest request, HttpServletResponse response) {
		HttpUtils.removeStateParam(Config.RETURNTO_COOKIE, request, response);
	}
24386
def delete_expired_requests():
    """"""
    InclusionRequest.query.filter_by(
        InclusionRequest.expiry_date > datetime.utcnow()).delete()
    db.session.commit()
389777
public DeleteSessionResponse deleteSession(DeleteSessionRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        checkStringNotEmpty(request.getSessionId(), "The parameter sessionId should NOT be null or empty string.");
        InternalRequest internalRequest = createRequest(HttpMethodName.DELETE, request, LIVE_SESSION,
                request.getSessionId());
        return invokeHttpClient(internalRequest, DeleteSessionResponse.class);
    }
1350935
public final void removeBrowserSession(AOBrowserSessionKey key)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "removeBrowserSession", key);

    browserSessionTable.remove(key);

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "removeBrowserSession");

  }