/*
Stores signed cookies data and returns a token which can be used
to retrieve the data from the /aux/cookies DuraStore path
489572
private String storeCookies(Map<String, String> signedCookies,
                                String streamingHost,
                                String redirectUrl) {
        SignedCookieData signedCookieData = new SignedCookieData();
        signedCookieData.setSignedCookies(signedCookies);
        signedCookieData.setStreamingHost(streamingHost);
        signedCookieData.setRedirectUrl(redirectUrl);

        String cookiesData = signedCookieData.serialize();

        StringDataStore signedCookieStore = dataStoreFactory.create(Constants.HIDDEN_COOKIE_SPACE);
        return signedCookieStore.storeData(cookiesData);
    }
681014
function serializeCookie(cookie) {
  return {
    path: cookie.path,
    name: cookie.key,
    value: cookie.value,
    domain: cookie.domain
  };
}
225047
function (path, onDone) {

		var options = {cookie: cookie};
		var contentType = contentTypesByExtension[pathLib.extname(path)];
		if (contentType) 
			options['content_type'] = contentType;
				
		LOG.sys('try to serve: ' + path, 'handlers.REST_web');

		/*
		*/
		
		// NOTE: file can either not exist, or path can be a directory, need to consider both cases
		l_readFile(path, function (data) {				
			if (data) {
				LOG.sys('finished reading file: ' + path, 'handlers.REST_web');
				onReturnFile(data, options);
				UTIL.safeCall(onDone, true);
			}
			else
				UTIL.safeCall(onDone, false);
		});		
	}
138416
function _fnReadCookie ( sName )
		{
			var
				aParts = window.location.pathname.split('/'),
				sNameEQ = sName + '_' + aParts[aParts.length-1].replace(/[\/:]/g,"").toLowerCase() + '=',
			 	sCookieContents = document.cookie.split(';');
			
			for( var i=0 ; i<sCookieContents.length ; i++ )
			{
				var c = sCookieContents[i];
				
				while (c.charAt(0)==' ')
				{
					c = c.substring(1,c.length);
				}
				
				if (c.indexOf(sNameEQ) === 0)
				{
					return decodeURIComponent( c.substring(sNameEQ.length,c.length) );
				}
			}
			return null;
		}
232783
public void saveToken(CsrfToken t, HttpServletRequest request, HttpServletResponse response) {
		String ident = getIdentifierFromCookie(request);
		if (ident != null) {
			String key = ident.concat(parameterName);
			CsrfToken token = loadToken(request);
			if (token == null) {
				token = generateToken(null);
				if (Config.isCacheEnabled()) {
					cache.put(Config.getRootAppIdentifier(), key, token, (long) Config.SESSION_TIMEOUT_SEC);
				} else {
					localCache.put(key, new Object[]{token, System.currentTimeMillis()});
				}
			}
			storeTokenAsCookie(token, request, response);
		}
	}
671199
def store_location
      if request.get? && Adeia.api_patterns.all? { |pattern| /^#{pattern}$/.match(request.path).nil? }
        cookies[:return_to] = { value: request.fullpath, expires: 2.minutes.from_now }
      end
    end
1047633
function getFormToken() {
		/*jshint validthis:true */
		if (this._csrfFormToken)
			return this._csrfFormToken;
		checkSecure(this.req);

		var cookieToken = getCookieToken(this) || createCookie(this);
		var salt = base64Random(saltSize);

		var hasher = crypto.createHmac(options.algorithm, formKey);
		hasher.update(cookieToken);
		hasher.update("|");
		hasher.update(salt);

		this._csrfFormToken = salt + "|" + hasher.digest('base64');
		return this._csrfFormToken;
	}
336718
function() {
  var app = this;
  var config = app.config;
  var cookiesecret = config.cookie_secret;
  if (!cookiesecret) {
    cookiesecret = crypto.randomBytes(64).toString('base64');
    log.warn('no cookie_secret set in config/app.js, randomly choosing %s', cookiesecret);
  }
  app.use(cookieParser(cookiesecret));
  var sessionconfig = {
    secret: cookiesecret,
    resave: false,
    saveUninitialized: false,
  //the rolling feature doesn't impact how long session live on the server-side
  //but it does update the expire time on the session cookie
  //and as a side effect forces the session cookie to be set every request
  //without this the cookie for existing sessions will not be sent if it doesn't have an expires
  //but we need it to be in the case where we downgrade a persistent session to browser-session one
  //when the user logs in again without "rememberme" checked
  //(search for "debug('already set browser-session cookie');" in express-session)
    rolling: !!config.persistentSessionSeconds,
  };
  if (config.sessionfactory) {
    config.sessionfactory(sessionconfig, app, session);
  } else {
    // /es5 needed for node 0.10 and 0.12 compatibility
    var MongoStore = require('connect-mongo/es5')(session);
    sessionconfig.store = new MongoStore({
          url: config.dburl,
          //would be nice to save session natively but that fails if keys have '.' or '$'
          //stringify: false,
          //the session ttl if session.cookie.expires isn't set:
          ttl: config.browsersessionSessionSeconds
    });
  }
  //the session middleware works as follows:
  //if no req.session is set read sessionid out of session cookie and load the session
  //if session cookie isn't present generates a new session
  //at the end of the request the session is stored if modified and set-cookie header is sent

  //XXX express-session deprecated undefined resave option; provide resave option
  //express-session deprecated undefined saveUninitialized option; provide saveUninitialized option

  app.use(session(sessionconfig));
}
172733
function matchPath(ctx) {
    const pathname = parse(ctx).pathname;
    if (pathname.indexOf(cookie.path || '/') !== 0) {
      debug('cookie path not match');
      return false;
    }
    return true;
  }
761745
function setSecret (req, res, sessionKey, val, cookie) {
  if (cookie) {
    // set secret on cookie
    var value = val

    if (cookie.signed) {
      value = 's:' + sign(val, req.secret)
    }

    setCookie(res, cookie.key, value, cookie)
  } else {
    // set secret on session
    req[sessionKey].csrfSecret = val
  }
}
1105396
function (cookieV1) {
        return {
            expires: (new Date(cookieV1.expirationDate * 1000)).toString(),
            hostOnly: cookieV1.hostOnly,
            httpOnly: cookieV1.httpOnly,
            domain: cookieV1.domain,
            path: cookieV1.path,
            secure: cookieV1.secure,
            session: cookieV1.session,
            value: cookieV1.value,
            key: cookieV1.name
        };
    }
72125
function logon() {
    var dfrd = Q.defer();
    var token = cache.get('token');

    function extractToken(xml) {
      var r = _parse(xml, dfrd);
      if (r) {
        return r.response.token[0];
      }
    }

    if (token) {
      dfrd.resolve({
        token: token,
        cached: true
      });
    }

    request(format(URLs.logon, PROTOCOL, conf.host, conf.username,
        conf.password),
      function(err, res, body) {
        var newToken;
        if (err) {
          dfrd.reject(err);
        } else {
          newToken = extractToken(body);
          if (!newToken) {
            dfrd.reject(MODULE_ERRORS.unknown);
          } else {
            cache.put('token', newToken);
            dfrd.resolve({
              token: newToken,
              cached: false
            });
          }
        }
      });
    return dfrd.promise;
  }
657984
function getIdToken(forceRefresh) {
  if (activeUser() == null) {
    alertError('No user logged in.');
    return;
  }
  if (activeUser().getIdToken) {
    activeUser().getIdToken(forceRefresh).then(alertSuccess, function() {
      log("No token");
    });
  } else {
    activeUser().getToken(forceRefresh).then(alertSuccess, function() {
      log("No token");
    });
  }
}
472474
function getSecretBag (req, sessionKey, cookie) {
  if (cookie) {
    // get secret from cookie
    var cookieKey = cookie.signed
      ? 'signedCookies'
      : 'cookies'

    return req[cookieKey]
  } else {
    // get secret from session
    return req[sessionKey]
  }
}
107638
function fetchTokensData (tokenRegContract, tokenIndexes) {
  return (dispatch, getState) => {
    const { api, tokens } = getState();
    const allTokens = Object.values(tokens);

    const tokensIndexesMap = allTokens
      .reduce((map, token) => {
        map[token.index] = token;
        return map;
      }, {});

    const fetchedTokenIndexes = allTokens
      .filter((token) => token.fetched)
      .map((token) => token.index);

    const fullIndexes = [];
    const partialIndexes = [];

    tokenIndexes.forEach((tokenIndex) => {
      if (fetchedTokenIndexes.includes(tokenIndex)) {
        partialIndexes.push(tokenIndex);
      } else {
        fullIndexes.push(tokenIndex);
      }
    });

    log.debug('need to fully fetch', fullIndexes);
    log.debug('need to partially fetch', partialIndexes);

    const fullPromise = fetchTokensInfo(api, tokenRegContract, fullIndexes);
    const partialPromise = fetchTokensImages(api, tokenRegContract, partialIndexes)
      .then((imagesResult) => {
        return imagesResult.map((image, index) => {
          const tokenIndex = partialIndexes[index];
          const token = tokensIndexesMap[tokenIndex];

          return { ...token, image };
        });
      });

    return Promise.all([ fullPromise, partialPromise ])
      .then(([ fullResults, partialResults ]) => {
        log.debug('fetched', { fullResults, partialResults });

        return []
          .concat(fullResults, partialResults)
          .filter(({ address }) => !/0x0*$/.test(address))
          .reduce((tokens, token) => {
            const { id } = token;

            tokens[id] = token;
            return tokens;
          }, {});
      })
      .then((tokens) => {
        dispatch(setTokens(tokens));
      });
  };
}
349736
protected String getStoredToken(HttpServletRequest req) {
		HttpSession session = req.getSession(false);
		
		if (session == null)
			return null;
		
		return (String) session.getAttribute(ATR_SESSION_TOKEN);
	}
819823
@Sensitive
    private String getStoredReq(HttpServletRequest req, ReferrerURLCookieHandler referrerURLHandler) {
        String storedReq = referrerURLHandler.getReferrerURLFromCookies(req, ReferrerURLCookieHandler.REFERRER_URL_COOKIENAME);
        if (storedReq != null) {
            if (storedReq.equals("/"))
                storedReq = "";
            else if (storedReq.startsWith("/"))
                storedReq = storedReq.substring(1);
        } else {
            storedReq = "";
        }
        return storedReq;
    }