use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method getJSessionScope.
/**
* return j session scope
*
* @param pc PageContext
* @param isNew
* @return j session matching the context
* @throws PageException
*/
private Session getJSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
HttpSession httpSession = pc.getSession();
ApplicationContext appContext = pc.getApplicationContext();
// this is from type object, because it is possible that httpSession return object from
Object session = null;
// prior restart
int s = (int) appContext.getSessionTimeout().getSeconds();
if (maxSessionTimeout < s)
maxSessionTimeout = s;
if (httpSession != null) {
httpSession.setMaxInactiveInterval(maxSessionTimeout + 60);
session = httpSession.getAttribute(appContext.getName());
} else {
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
session = context.get(pc.getCFID());
}
JSession jSession = null;
if (session instanceof JSession) {
jSession = (JSession) session;
try {
if (jSession.isExpired()) {
jSession.touch();
}
info(getLog(), "use existing JSession for " + appContext.getName() + "/" + pc.getCFID());
} catch (ClassCastException cce) {
error(getLog(), cce);
// if there is no HTTPSession
if (httpSession == null)
return getCFSessionScope(pc, isNew);
jSession = new JSession();
httpSession.setAttribute(appContext.getName(), jSession);
isNew.setValue(true);
}
} else {
// if there is no HTTPSession
if (httpSession == null)
return getCFSessionScope(pc, isNew);
info(getLog(), "create new JSession for " + appContext.getName() + "/" + pc.getCFID());
jSession = new JSession();
httpSession.setAttribute(appContext.getName(), jSession);
isNew.setValue(true);
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
context.put(pc.getCFID(), jSession);
}
jSession.touchBeforeRequest(pc);
return jSession;
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method hasExistingCFSessionScope.
private boolean hasExistingCFSessionScope(PageContext pc) {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
// get Session
String storage = appContext.getSessionstorage();
if (StringUtil.isEmpty(storage, true))
storage = "memory";
else if ("ram".equalsIgnoreCase(storage))
storage = "memory";
else if ("registry".equalsIgnoreCase(storage))
storage = "file";
else
storage = storage.toLowerCase();
Session session = (Session) context.get(pc.getCFID());
if (!(session instanceof StorageScope) || session.isExpired() || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
if ("memory".equals(storage))
return false;
else if ("file".equals(storage))
return SessionFile.hasInstance(appContext.getName(), pc);
else if ("cookie".equals(storage))
return SessionCookie.hasInstance(appContext.getName(), pc);
else {
DataSource ds = pc.getConfig().getDataSource(storage, null);
if (ds != null && ds.isStorage()) {
if (INVIDUAL_STORAGE_KEYS) {
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc);
} else {
if (SessionDatasource.hasInstance(storage, pc))
return true;
}
}
if (INVIDUAL_STORAGE_KEYS)
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc);
return SessionCache.hasInstance(storage, appContext.getName(), pc);
}
}
return true;
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method invalidateUserScope.
public void invalidateUserScope(PageContextImpl pc, boolean migrateSessionData, boolean migrateClientData) throws PageException {
ApplicationContext appContext = pc.getApplicationContext();
RefBoolean isNew = new RefBooleanImpl();
// get in memory scopes
Map<String, Scope> clientContext = getSubMap(cfClientContexts, appContext.getName());
UserScope oldClient = (UserScope) clientContext.get(pc.getCFID());
Map<String, Scope> sessionContext = getSubMap(cfSessionContexts, appContext.getName());
UserScope oldSession = (UserScope) sessionContext.get(pc.getCFID());
// remove Scopes completly
removeCFSessionScope(pc);
removeClientScope(pc);
pc.resetIdAndToken();
if (oldSession != null)
migrate(pc, oldSession, getCFSessionScope(pc, isNew), migrateSessionData);
if (oldClient != null)
migrate(pc, oldClient, getClientScope(pc), migrateClientData);
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method removeCFSessionScope.
public void removeCFSessionScope(PageContext pc) throws PageException {
Session sess = getCFSessionScope(pc, new RefBooleanImpl());
ApplicationContext appContext = pc.getApplicationContext();
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
if (context != null) {
context.remove(pc.getCFID());
if (sess instanceof StorageScope)
((StorageScope) sess).unstore(pc.getConfig());
}
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method hasExistingClientScope.
private boolean hasExistingClientScope(PageContext pc, String cfid) {
ApplicationContext appContext = pc.getApplicationContext();
Map<String, Scope> context = getSubMap(cfClientContexts, appContext.getName());
return context.containsKey(cfid);
}
Aggregations