use of lucee.runtime.type.scope.Cookie in project Lucee by lucee.
the class PageContextImpl method initIdAndToken.
/**
* initialize the cfid and the cftoken
*/
private void initIdAndToken() {
boolean setCookie = true;
// From URL
Object oCfid = urlScope().get(KeyConstants._cfid, null);
Object oCftoken = urlScope().get(KeyConstants._cftoken, null);
// if CFID comes from URL, we only accept if already exists
if (oCfid != null) {
if (Decision.isGUIdSimple(oCfid)) {
if (!scopeContext.hasExistingCFID(this, Caster.toString(oCfid, null))) {
oCfid = null;
oCftoken = null;
}
} else {
oCfid = null;
oCftoken = null;
}
}
// Cookie
if (oCfid == null) {
setCookie = false;
oCfid = cookieScope().get(KeyConstants._cfid, null);
oCftoken = cookieScope().get(KeyConstants._cftoken, null);
}
// check cookie value
if (oCfid != null) {
// cookie value is invalid, maybe from ACF
if (!Decision.isGUIdSimple(oCfid)) {
oCfid = null;
oCftoken = null;
Charset charset = getWebCharset();
// check if we have multiple cookies with the name "cfid" and a other one is valid
javax.servlet.http.Cookie[] cookies = getHttpServletRequest().getCookies();
String name, value;
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
name = ReqRspUtil.decode(cookies[i].getName(), charset.name(), false);
// CFID
if ("cfid".equalsIgnoreCase(name)) {
value = ReqRspUtil.decode(cookies[i].getValue(), charset.name(), false);
if (Decision.isGUIdSimple(value))
oCfid = value;
ReqRspUtil.removeCookie(getHttpServletResponse(), name);
} else // CFToken
if ("cftoken".equalsIgnoreCase(name)) {
value = ReqRspUtil.decode(cookies[i].getValue(), charset.name(), false);
if (isValidCfToken(value))
oCftoken = value;
ReqRspUtil.removeCookie(getHttpServletResponse(), name);
}
}
}
if (oCfid != null) {
setCookie = true;
if (oCftoken == null)
oCftoken = "0";
}
}
}
// New One
if (oCfid == null || oCftoken == null) {
setCookie = true;
cfid = ScopeContext.getNewCFId();
cftoken = ScopeContext.getNewCFToken();
} else {
cfid = Caster.toString(oCfid, null);
cftoken = Caster.toString(oCftoken, "0");
}
if (setCookie && applicationContext.isSetClientCookies())
setClientCookies();
}
use of lucee.runtime.type.scope.Cookie in project Lucee by lucee.
the class StorageScopeCookie method touchAfterRequest.
@Override
public void touchAfterRequest(PageContext pc) {
boolean _isInit = isinit;
super.touchAfterRequest(pc);
if (!_isInit)
return;
ApplicationContext ac = pc.getApplicationContext();
TimeSpan timespan = (getType() == SCOPE_CLIENT) ? ac.getClientTimeout() : ac.getSessionTimeout();
Cookie cookie = pc.cookieScope();
Date exp = new DateTimeImpl(pc, System.currentTimeMillis() + timespan.getMillis(), true);
try {
String ser = serializer.serializeStruct(sct, ignoreSet);
if (hasChanges()) {
cookie.setCookie(KeyImpl.init(cookieName), ser, exp, false, "/", null);
}
cookie.setCookie(KeyImpl.init(cookieName + "_LV"), Caster.toString(_lastvisit.getTime()), exp, false, "/", null);
if (getType() == SCOPE_CLIENT) {
cookie.setCookie(KeyImpl.init(cookieName + "_TC"), Caster.toString(timecreated.getTime()), exp, false, "/", null);
cookie.setCookie(KeyImpl.init(cookieName + "_HC"), Caster.toString(sct.get(HITCOUNT, "")), exp, false, "/", null);
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
Aggregations