Search in sources :

Example 96 with UserSession

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

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 97 with UserSession

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

the class ResumeSessionController method isResumeInteractionRequired.

private Redirect isResumeInteractionRequired(UserRequest ureq) {
    UserSession usess = ureq.getUserSession();
    Redirect option;
    if (isREST(ureq)) {
        String url = getRESTRedirectURL(ureq);
        option = new Redirect(url);
    } else if (!historyModule.isResumeEnabled()) {
        String url = toUrl(getLandingBC(ureq));
        option = new Redirect(url);
    } else if (usess.getRoles().isGuestOnly()) {
        String url = toUrl(getLandingBC(ureq));
        option = new Redirect(url);
    } else {
        Preferences prefs = usess.getGuiPreferences();
        String resumePrefs = (String) prefs.get(WindowManager.class, "resume-prefs");
        if (!StringHelper.containsNonWhitespace(resumePrefs)) {
            resumePrefs = historyModule.getResumeDefaultSetting();
        }
        if ("none".equals(resumePrefs)) {
            String url = toUrl(getLandingBC(ureq));
            option = new Redirect(url);
        } else if ("auto".equals(resumePrefs)) {
            HistoryPoint historyEntry = HistoryManager.getInstance().readHistoryPoint(ureq.getIdentity());
            if (historyEntry != null && StringHelper.containsNonWhitespace(historyEntry.getBusinessPath())) {
                List<ContextEntry> cloneCes = BusinessControlFactory.getInstance().cloneContextEntries(historyEntry.getEntries());
                String bc = BusinessControlFactory.getInstance().getAsRestPart(cloneCes, true);
                option = new Redirect(bc);
            } else {
                String url = toUrl(getLandingBC(ureq));
                option = new Redirect(url);
            }
        } else if ("ondemand".equals(resumePrefs)) {
            HistoryPoint historyEntry = historyManager.readHistoryPoint(ureq.getIdentity());
            if (historyEntry != null && StringHelper.containsNonWhitespace(historyEntry.getBusinessPath())) {
                List<ContextEntry> cloneCes = BusinessControlFactory.getInstance().cloneContextEntries(historyEntry.getEntries());
                String url = BusinessControlFactory.getInstance().getAsRestPart(cloneCes, true);
                String landingPage = getLandingBC(ureq);
                option = new Redirect(url, landingPage);
            } else {
                String url = toUrl(getLandingBC(ureq));
                option = new Redirect(url);
            }
        } else {
            String url = toUrl(getLandingBC(ureq));
            option = new Redirect(url);
        }
    }
    return option;
}
Also used : UserSession(org.olat.core.util.UserSession) ArrayList(java.util.ArrayList) List(java.util.List) Preferences(org.olat.core.util.prefs.Preferences) HistoryPoint(org.olat.core.id.context.HistoryPoint) ContextEntry(org.olat.core.id.context.ContextEntry) WindowManager(org.olat.core.gui.WindowManager)

Example 98 with UserSession

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

the class BaseFullWebappController method activate.

/**
 * Activating a tab is like focusing a new window - we need to adjust the
 * guipath since e.g. the button triggering the activation is not
 * part of the guipath, but rather the new tab in its initial state.
 * in all other cases the "focus of interest" (where the calculation of the
 * guipath is started) matches the controller which listens to the
 * event caused by a user interaction.
 * this is the starting point.
 */
@Override
public void activate(UserRequest ureq, DTab dTab, List<ContextEntry> entries) {
    UserSession usess = ureq.getUserSession();
    if ((lockStatus != null || usess.isInAssessmentModeProcess()) && !usess.matchLockResource(dTab.getOLATResourceable())) {
        return;
    }
    // update window settings if needed
    setWindowSettings(getWindowControl().getWindowBackOffice().getWindowSettings());
    // jump here via external link or just open a new tab from e.g. repository
    if (dTab == null && contentCtrl instanceof Activateable2) {
        ((Activateable2) contentCtrl).activate(ureq, entries, null);
    } else {
        DTabImpl dtabi = (DTabImpl) dTab;
        Controller c = dtabi.getController();
        if (c == null) {
            throw new AssertException("no controller set yet! " + dTab);
        }
        doActivateDTab(dtabi);
        if (c instanceof Activateable2) {
            final Activateable2 activateable = ((Activateable2) c);
            activateable.activate(ureq, entries, null);
        }
        updateBusinessPath(ureq, dtabi);
        // update the panels after activation
        setGuiStack(dtabi.getGuiStackHandle());
    }
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) AssertException(org.olat.core.logging.AssertException) UserSession(org.olat.core.util.UserSession) DTabImpl(org.olat.core.gui.control.generic.dtabs.DTabImpl) ResumeSessionController(org.olat.core.commons.controllers.resume.ResumeSessionController) AssessmentModeGuardController(org.olat.course.assessment.ui.mode.AssessmentModeGuardController) BasicController(org.olat.core.gui.control.controller.BasicController) ChiefController(org.olat.core.gui.control.ChiefController) BaseChiefController(org.olat.core.commons.chiefcontrollers.BaseChiefController) VetoableCloseController(org.olat.core.gui.control.VetoableCloseController) Controller(org.olat.core.gui.control.Controller) UserToolsMenuController(org.olat.gui.control.UserToolsMenuController)

Example 99 with UserSession

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

the class UserSessionInformationsController method getUsersSessionAsString.

private String getUsersSessionAsString() {
    StringBuilder sb = new StringBuilder(50000);
    int ucCnt = sessionManager.getUserSessionsCnt();
    Set<UserSession> usesss = sessionManager.getAuthenticatedUserSessions();
    int contcnt = DefaultController.getControllerCount();
    sb.append("total usersessions (auth and non auth): " + ucCnt + "<br />auth usersessions: " + usesss.size() + "<br />Total Controllers (active, not disposed) of all users:" + contcnt + "<br /><br />");
    for (Iterator<UserSession> iter = usesss.iterator(); iter.hasNext(); ) {
        UserSession usess = iter.next();
        Identity iden = usess.getIdentity();
        sb.append("authusersession (").append(usess.hashCode()).append(") of ");
        if (iden != null) {
            sb.append(iden.getName()).append(" ").append(iden.getKey());
        } else {
            sb.append(" - ");
        }
        sb.append("<br />");
        Windows ws = Windows.getWindows(usess);
        for (Iterator<Window> iterator = ws.getWindowIterator(); iterator.hasNext(); ) {
            Window window = iterator.next();
            sb.append("- window ").append(window.getDispatchID()).append(" ").append(window.getLatestDispatchComponentInfo()).append("<br />");
        }
        sb.append("<br />");
    }
    return sb.toString();
}
Also used : Window(org.olat.core.gui.components.Window) UserSession(org.olat.core.util.UserSession) Windows(org.olat.core.gui.Windows) Identity(org.olat.core.id.Identity)

Example 100 with UserSession

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

the class MapperDispatcher method execute.

/**
 * @param hreq
 * @param hres
 */
@Override
public void execute(HttpServletRequest hreq, HttpServletResponse hres) throws IOException {
    String pathInfo = DispatcherModule.subtractContextPath(hreq);
    // e.g. non-cacheable: 	23423/bla/blu.html
    // e.g. cacheable: 		my.mapper.path/bla/blu.html
    String subInfo = pathInfo.substring(DispatcherModule.PATH_MAPPED.length());
    int slashPos = subInfo.indexOf('/');
    String smappath;
    if (slashPos == -1) {
        smappath = subInfo;
    } else {
        smappath = subInfo.substring(0, slashPos);
    }
    // legacy???
    DBFactory.getInstance().commitAndCloseSession();
    // e.g. non-cacheable: 	23423
    // e.g. cacheable: 		my.mapper.path
    UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(hreq);
    Mapper m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(usess, smappath);
    if (m == null) {
        // an anonymous mapper?
        m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(null, smappath);
        if (m == null) {
            logWarn("Call to mapped resource, but mapper does not exist for path::" + smappath, null);
            DispatcherModule.sendNotFound(pathInfo, hres);
            return;
        }
    }
    String mod = slashPos > 0 ? subInfo.substring(slashPos) : "";
    if (mod.indexOf("..") != -1) {
        logWarn("Illegal mapper path::" + mod + " contains '..'", null);
        DispatcherModule.sendForbidden(pathInfo, hres);
        return;
    }
    // /bla/blu.html
    MediaResource mr = m.handle(mod, hreq);
    ServletUtil.serveResource(hreq, hres, mr);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) MediaResource(org.olat.core.gui.media.MediaResource)

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