Search in sources :

Example 16 with ApplicationContext

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;
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) HttpSession(javax.servlet.http.HttpSession)

Example 17 with ApplicationContext

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;
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) ApplicationContext(lucee.runtime.listener.ApplicationContext) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) IKHandlerCache(lucee.runtime.type.scope.storage.IKHandlerCache) HttpSession(javax.servlet.http.HttpSession) DataSource(lucee.runtime.db.DataSource) IKHandlerDatasource(lucee.runtime.type.scope.storage.IKHandlerDatasource)

Example 18 with ApplicationContext

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);
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) RefBoolean(lucee.commons.lang.types.RefBoolean) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 19 with ApplicationContext

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());
    }
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) ApplicationContext(lucee.runtime.listener.ApplicationContext) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) HttpSession(javax.servlet.http.HttpSession)

Example 20 with ApplicationContext

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);
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope)

Aggregations

ApplicationContext (lucee.runtime.listener.ApplicationContext)28 MemoryScope (lucee.runtime.type.scope.storage.MemoryScope)10 StorageScope (lucee.runtime.type.scope.storage.StorageScope)10 HttpSession (javax.servlet.http.HttpSession)6 DataSource (lucee.runtime.db.DataSource)4 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)4 Key (lucee.runtime.type.Collection.Key)4 CacheConnection (lucee.runtime.cache.CacheConnection)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 PageException (lucee.runtime.exp.PageException)3 TimeSpan (lucee.runtime.type.dt.TimeSpan)3 IKHandlerCache (lucee.runtime.type.scope.storage.IKHandlerCache)3 IKHandlerDatasource (lucee.runtime.type.scope.storage.IKHandlerDatasource)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Resource (lucee.commons.io.res.Resource)2 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 ClassicApplicationContext (lucee.runtime.listener.ClassicApplicationContext)2 ModernApplicationContext (lucee.runtime.listener.ModernApplicationContext)2