Search in sources :

Example 76 with UserSession

use of org.olat.core.util.UserSession in project openolat by klemens.

the class NewControllerFactory method launch.

/**
 * Launch a controller in a tab or site in the given window from a user
 * request url
 *
 * @param ureq
 * @param wControl
 */
public boolean launch(UserRequest ureq, WindowControl wControl) {
    BusinessControl bc = wControl.getBusinessControl();
    ContextEntry mainCe = bc.popLauncherContextEntry();
    if (mainCe == null) {
        // nothing to launch
        return false;
    }
    OLATResourceable ores = mainCe.getOLATResourceable();
    // Check for RepositoryEntry resource
    RepositoryEntry re = null;
    if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(RepositoryEntry.class))) {
        if (ores instanceof RepositoryEntry) {
            re = (RepositoryEntry) ores;
            ores = re.getOlatResource();
        } else {
            // It is a repository-entry => get OLATResourceable from RepositoryEntry
            RepositoryManager repom = RepositoryManager.getInstance();
            re = repom.lookupRepositoryEntry(ores.getResourceableId());
            if (re != null) {
                ores = re.getOlatResource();
                mainCe.upgradeOLATResourceable(re);
            }
        }
    }
    // was brasato:: DTabs dts = wControl.getDTabs();
    UserSession usess = ureq.getUserSession();
    Window window = Windows.getWindows(usess).getWindow(ureq);
    if (window == null) {
        log.debug("Found no window for jumpin => take WindowBackOffice", null);
        window = wControl.getWindowBackOffice().getWindow();
    }
    DTabs dts = window.getDTabs();
    String firstType = mainCe.getOLATResourceable().getResourceableTypeName();
    // String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup
    ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType);
    if (typeHandler == null) {
        log.warn("Cannot found an handler for context entry: " + mainCe, null);
        // simply return and don't throw a red screen
        return false;
    }
    if (!typeHandler.validateContextEntryAndShowError(mainCe, ureq, wControl)) {
        // simply return and don't throw a red screen
        return false;
    }
    List<ContextEntry> entries = new ArrayList<ContextEntry>(5);
    while (bc.hasContextEntry()) {
        entries.add(bc.popLauncherContextEntry());
    }
    List<ContextEntry> ces = new ArrayList<ContextEntry>(entries.size() + 1);
    ces.add(mainCe);
    if (entries.size() > 0) {
        ces.addAll(entries);
    }
    TabContext context = typeHandler.getTabContext(ureq, ores, mainCe, entries);
    String siteClassName = typeHandler.getSiteClassName(ces, ureq);
    // open in existing site
    boolean launched = false;
    boolean assessmentMode = usess.isInAssessmentModeProcess();
    if (siteClassName != null) {
        if (!assessmentMode) {
            dts.activateStatic(ureq, siteClassName, context.getContext());
            launched = true;
        }
    } else if (!assessmentMode || usess.matchLockResource(ores)) {
        // get current tab or create new tab
        DTab dt = dts.getDTab(ores);
        if (dt == null) {
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, dts.getWindowControl());
            usess.addToHistory(ureq, bc);
            Controller launchC = typeHandler.createController(ces, ureq, bwControl);
            if (launchC != null) {
                dt = dts.createDTab(context.getTabResource(), re, launchC, context.getName());
                if (dt == null) {
                    launched = false;
                } else if (dts.addDTab(ureq, dt)) {
                    dts.activate(ureq, dt, context.getContext());
                    launched = true;
                }
            }
        } else {
            dts.activate(ureq, dt, context.getContext());
            launched = true;
        }
    }
    return launched;
}
Also used : Window(org.olat.core.gui.components.Window) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntryControllerCreator(org.olat.core.id.context.ContextEntryControllerCreator) BusinessControl(org.olat.core.id.context.BusinessControl) DTabs(org.olat.core.gui.control.generic.dtabs.DTabs) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) BaseChiefController(org.olat.core.commons.chiefcontrollers.BaseChiefController) Controller(org.olat.core.gui.control.Controller) ContextEntry(org.olat.core.id.context.ContextEntry) TabContext(org.olat.core.id.context.TabContext) DTab(org.olat.core.gui.control.generic.dtabs.DTab) UserSession(org.olat.core.util.UserSession) RepositoryManager(org.olat.repository.RepositoryManager)

Example 77 with UserSession

use of org.olat.core.util.UserSession in project openolat by klemens.

the class SessionStatsManager method getActiveSessions.

public long getActiveSessions(int numOfSeconds) {
    long diff = numOfSeconds * 1000;
    Collection<UserSession> authUserSessions = sessionManager.getAuthenticatedUserSessions();
    long now = System.currentTimeMillis();
    long counter = 0;
    for (UserSession usess : authUserSessions) {
        long lastklick = usess.getSessionInfo() == null ? -1 : usess.getSessionInfo().getLastClickTime();
        if ((now - lastklick) <= diff) {
            counter++;
        }
    }
    return counter;
}
Also used : UserSession(org.olat.core.util.UserSession)

Example 78 with UserSession

use of org.olat.core.util.UserSession in project openolat by klemens.

the class UserSessionController method reset.

/**
 * Re-initialize this controller. Fetches sessions again.
 */
public void reset() {
    Collection<UserSession> authUserSessions = sessionManager.getAuthenticatedUserSessions();
    List<UserSessionView> authUserSessionViews = new ArrayList<UserSessionView>(authUserSessions.size());
    for (UserSession authUserSession : authUserSessions) {
        authUserSessionViews.add(new UserSessionView(authUserSession));
    }
    usessTableModel = new UserSessionTableModel(authUserSessionViews, getIdentity().getKey());
    tableCtr.setTableDataModel(usessTableModel);
}
Also used : UserSession(org.olat.core.util.UserSession) ArrayList(java.util.ArrayList) UserSessionView(org.olat.admin.sysinfo.model.UserSessionView)

Example 79 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class RestApiLoginFilter method upgradeIpAuthentication.

private void upgradeIpAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    UserSession usess = sessionManager.getUserSessionIfAlreadySet(request);
    if (usess == null) {
        usess = sessionManager.getUserSession(request.getSession(true));
    }
    if (usess.getIdentity() == null) {
        usess.setRoles(new Roles(false, false, false, false, false, false, false));
        String remoteAddr = request.getRemoteAddr();
        SessionInfo sinfo = new SessionInfo(new Long(-1), "REST", request.getSession());
        sinfo.setFirstname("REST");
        sinfo.setLastname(remoteAddr);
        sinfo.setFromIP(remoteAddr);
        sinfo.setFromFQN(remoteAddr);
        try {
            InetAddress[] iaddr = InetAddress.getAllByName(request.getRemoteAddr());
            if (iaddr.length > 0)
                sinfo.setFromFQN(iaddr[0].getHostName());
        } catch (UnknownHostException e) {
        // ok, already set IP as FQDN
        }
        sinfo.setAuthProvider("IP");
        sinfo.setUserAgent(request.getHeader("User-Agent"));
        sinfo.setSecure(request.isSecure());
        sinfo.setREST(true);
        sinfo.setWebModeFromUreq(null);
        // set session info for this session
        usess.setSessionInfo(sinfo);
    }
    UserRequest ureq = null;
    try {
        // upon creation URL is checked for
        String requestURI = request.getRequestURI();
        ureq = new UserRequestImpl(requestURI, request, response);
        ureq.getUserSession().putEntryInNonClearedStore(RestSecurityHelper.SYSTEM_MARKER, Boolean.TRUE);
    } catch (NumberFormatException nfe) {
        response.sendError(401);
        return;
    }
    request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) UnknownHostException(java.net.UnknownHostException) UserSession(org.olat.core.util.UserSession) SessionInfo(org.olat.core.util.SessionInfo) Roles(org.olat.core.id.Roles) InetAddress(java.net.InetAddress) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Example 80 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class RestApiLoginFilter method followToken.

private void followToken(String token, HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpSession session = request.getSession(true);
    session.setMaxInactiveInterval(TOKEN_BASED_SESSION_TIMEOUT);
    UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(session);
    if (uress != null) {
        UserRequest ureq = null;
        try {
            // upon creation URL is checked for
            String requestURI = request.getRequestURI();
            ureq = new UserRequestImpl(requestURI, request, response);
        } catch (Exception e) {
            response.sendError(500);
            return;
        }
        request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
        RestSecurityBean securityBean = (RestSecurityBean) CoreSpringFactory.getBean(RestSecurityBean.class);
        Identity identity = securityBean.getIdentity(token);
        int loginStatus = AuthHelper.doHeadlessLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq, true);
        if (loginStatus == AuthHelper.LOGIN_OK) {
            String renewedToken = securityBean.renewToken(token);
            if (renewedToken != null) {
                response.setHeader(RestSecurityHelper.SEC_TOKEN, renewedToken);
                synchronized (uress) {
                    chain.doFilter(request, response);
                }
            } else
                response.sendError(401);
        } else
            response.sendError(401);
    } else
        response.sendError(401);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) HttpSession(javax.servlet.http.HttpSession) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

UserSession (org.olat.core.util.UserSession)146 UserSessionManager (org.olat.core.util.session.UserSessionManager)26 Identity (org.olat.core.id.Identity)22 Roles (org.olat.core.id.Roles)20 SessionInfo (org.olat.core.util.SessionInfo)20 HttpSession (javax.servlet.http.HttpSession)18 UserRequest (org.olat.core.gui.UserRequest)18 Test (org.junit.Test)16 MapperKey (org.olat.core.dispatcher.mapper.manager.MapperKey)16 UserRequestImpl (org.olat.core.gui.UserRequestImpl)16 ContextEntry (org.olat.core.id.context.ContextEntry)14 IOException (java.io.IOException)12 AssertException (org.olat.core.logging.AssertException)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 Window (org.olat.core.gui.components.Window)10 UnknownHostException (java.net.UnknownHostException)8 ArrayList (java.util.ArrayList)8 ChiefController (org.olat.core.gui.control.ChiefController)8 Preferences (org.olat.core.util.prefs.Preferences)8 InetAddress (java.net.InetAddress)6