Search in sources :

Example 1 with AuthCookieData

use of lucee.runtime.listener.AuthCookieData in project Lucee by lucee.

the class Loginuser method doStartTag.

@Override
public int doStartTag() throws PageException {
    Resource rolesDir = pageContext.getConfig().getConfigDir().getRealResource("roles");
    CredentialImpl login = new CredentialImpl(name, password, roles, rolesDir);
    pageContext.setRemoteUser(login);
    Tag parent = getParent();
    while (parent != null && !(parent instanceof Login)) {
        parent = parent.getParent();
    }
    ApplicationContext appContext = pageContext.getApplicationContext();
    if (parent != null) {
        int loginStorage = appContext.getLoginStorage();
        String name = Login.getApplicationName(appContext);
        if (loginStorage == Scope.SCOPE_SESSION && pageContext.getApplicationContext().isSetSessionManagement())
            pageContext.sessionScope().set(KeyImpl.init(name), login.encode());
        else {
            ApplicationContext ac = pageContext.getApplicationContext();
            TimeSpan tsExpires = AuthCookieDataImpl.DEFAULT.getTimeout();
            if (ac instanceof ApplicationContextSupport) {
                ApplicationContextSupport acs = (ApplicationContextSupport) ac;
                AuthCookieData data = acs.getAuthCookie();
                if (data != null) {
                    TimeSpan tmp = data.getTimeout();
                    if (tmp != null)
                        tsExpires = tmp;
                }
            }
            int expires;
            long tmp = tsExpires.getSeconds();
            if (Integer.MAX_VALUE < tmp)
                expires = Integer.MAX_VALUE;
            else
                expires = (int) tmp;
            ((CookieImpl) pageContext.cookieScope()).setCookie(KeyImpl.init(name), login.encode(), expires, false, "/", Login.getCookieDomain(appContext));
        }
    }
    return SKIP_BODY;
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ApplicationContext(lucee.runtime.listener.ApplicationContext) CredentialImpl(lucee.runtime.security.CredentialImpl) CookieImpl(lucee.runtime.type.scope.CookieImpl) Resource(lucee.commons.io.res.Resource) Tag(javax.servlet.jsp.tagext.Tag) AuthCookieData(lucee.runtime.listener.AuthCookieData)

Aggregations

Tag (javax.servlet.jsp.tagext.Tag)1 Resource (lucee.commons.io.res.Resource)1 ApplicationContext (lucee.runtime.listener.ApplicationContext)1 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)1 AuthCookieData (lucee.runtime.listener.AuthCookieData)1 CredentialImpl (lucee.runtime.security.CredentialImpl)1 TimeSpan (lucee.runtime.type.dt.TimeSpan)1 CookieImpl (lucee.runtime.type.scope.CookieImpl)1