Search in sources :

Example 66 with UserSession

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

the class CourseSiteContextEntryControllerCreator method createLaunchController.

/**
 * Create a launch controller used to launch the given repo entry.
 * @param re
 * @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
 * @param ureq
 * @param wControl
 * @return null if no entry was found, a no access message controller if not allowed to launch or the launch
 * controller if successful.
 */
private Controller createLaunchController(RepositoryEntry re, UserRequest ureq, WindowControl wControl) {
    if (re == null) {
        return messageController(ureq, wControl, "repositoryentry.not.existing");
    }
    UserSession usess = ureq.getUserSession();
    if (re.getAccess() == RepositoryEntry.DELETED) {
        Roles roles = usess.getRoles();
        if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
            return messageController(ureq, wControl, "repositoryentry.deleted");
        }
    }
    if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(re.getOlatResource())) {
        return null;
    }
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, re);
    if (!reSecurity.canLaunch()) {
        return messageController(ureq, wControl, "launch.noaccess");
    }
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    rs.incrementLaunchCounter(re);
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    WindowControl bwControl;
    OLATResourceable businessOres = re;
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
    if (ce.equals(wControl.getBusinessControl().getCurrentContextEntry())) {
        bwControl = wControl;
    } else {
        bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
    }
    MainLayoutController ctrl = handler.createLaunchController(re, reSecurity, ureq, bwControl);
    if (ctrl == null) {
        throw new AssertException("could not create controller for repositoryEntry " + re);
    }
    return ctrl;
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) UserSession(org.olat.core.util.UserSession) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 67 with UserSession

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

the class CourseSiteDef method createSite.

protected SiteInstance createSite(UserRequest ureq, CourseSiteConfiguration courseConfig, SiteConfiguration config) {
    if (courseConfig == null)
        return null;
    String secCallbackBeanId = config.getSecurityCallbackBeanId();
    SiteSecurityCallback siteSecCallback = (SiteSecurityCallback) CoreSpringFactory.getBean(secCallbackBeanId);
    UserSession usess = ureq.getUserSession();
    if (usess == null || usess.getRoles() == null)
        return null;
    boolean canSeeToolController = usess.getRoles().isAuthor() || usess.getRoles().isOLATAdmin() || usess.getRoles().isInstitutionalResourceManager();
    boolean showToolController = true;
    if (!canSeeToolController && !courseConfig.isToolbar()) {
        showToolController = false;
    }
    LanguageConfiguration langConfig = getLanguageConfiguration(ureq, courseConfig);
    if (langConfig == null) {
        return null;
    }
    String icon = courseConfig.getNavIconCssClass();
    return createCourseSiteInstance(langConfig, showToolController, siteSecCallback, icon);
}
Also used : SiteSecurityCallback(org.olat.core.gui.control.navigation.SiteSecurityCallback) UserSession(org.olat.core.util.UserSession) LanguageConfiguration(org.olat.course.site.model.LanguageConfiguration)

Example 68 with UserSession

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

the class CourseSite method createController.

@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
    if (entry == null) {
        return getAlternativeController(ureq, wControl, config);
    }
    MainLayoutController c;
    ICourse course = CourseFactory.loadCourse(entry);
    UserSession usess = ureq.getUserSession();
    // course-launch-state depending course-settings
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
    boolean isAllowedToLaunch = reSecurity.canLaunch();
    boolean hasAccess = false;
    if (isAllowedToLaunch) {
        // either check with securityCallback or use access-settings from course-nodes
        if (siteSecCallback != null) {
            hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
        } else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
            hasAccess = false;
        } else {
            // check within course: accessibility of course root node
            CourseNode rootNode = course.getRunStructure().getRootNode();
            UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
            NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
            boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
            hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
        }
    }
    // load course (admins always see content) or alternative controller if course is not launchable
    if (hasAccess || usess.getRoles().isOLATAdmin()) {
        rs.incrementLaunchCounter(entry);
        // build up the context path for linked course
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
        CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {

            @Override
            public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
                return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
            }
        }, false, true);
        // Configure run controller
        // a: don't show close link, is opened as site not tab
        runCtr.setCourseCloseEnabled(false);
        // b: don't show toolbar
        if (!showToolController) {
            runCtr.setToolControllerEnabled(false);
        }
        c = runCtr;
    } else {
        // access restricted (not in group / author) -> show controller
        // defined in olat_extensions (type autoCreator)
        c = getAlternativeController(ureq, wControl, config);
    }
    return c;
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) StateSite(org.olat.core.id.context.StateSite) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) RunMainController(org.olat.course.run.RunMainController) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RunMainController(org.olat.course.run.RunMainController) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) Controller(org.olat.core.gui.control.Controller) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) UserSession(org.olat.core.util.UserSession) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RepositoryManager(org.olat.repository.RepositoryManager) CourseNode(org.olat.course.nodes.CourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService)

Example 69 with UserSession

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

the class NewBGController method event.

/* (non-Javadoc)
	 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
	 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == groupCreateController) {
        if (event == Event.DONE_EVENT) {
            String bgDesc = groupCreateController.getGroupDescription();
            Integer bgMax = groupCreateController.getGroupMax();
            Integer bgMin = groupCreateController.getGroupMin();
            boolean enableWaitingList = groupCreateController.isWaitingListEnabled();
            boolean enableAutoCloseRanks = groupCreateController.isAutoCloseRanksEnabled();
            UserSession usess = ureq.getUserSession();
            Object wildcard = usess.removeEntry("wild_card_new");
            newGroups = new ArrayList<BusinessGroup>();
            if (bulkMode) {
                for (String bgName : groupCreateController.getGroupNames()) {
                    BusinessGroup group = businessGroupService.createBusinessGroup(getIdentity(), bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, re);
                    newGroups.add(group);
                }
            } else {
                String bgName = groupCreateController.getGroupName();
                BusinessGroup group = businessGroupService.createBusinessGroup(getIdentity(), bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, re);
                newGroups.add(group);
                if (wildcard != null && Boolean.TRUE.equals(wildcard)) {
                    usess.putEntry("wild_card_" + group.getKey(), Boolean.TRUE);
                }
            }
            if (newGroups != null) {
                for (BusinessGroup bg : newGroups) {
                    LoggingResourceable resourceInfo = LoggingResourceable.wrap(bg);
                    ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CREATED, getClass(), resourceInfo);
                }
                // workflow successfully finished
                // so far no events on the systembus to inform about new groups in BGContext
                fireEvent(ureq, Event.DONE_EVENT);
            }
        } else if (event == Event.CANCELLED_EVENT) {
            // workflow cancelled
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) UserSession(org.olat.core.util.UserSession) LoggingResourceable(org.olat.util.logging.activity.LoggingResourceable)

Example 70 with UserSession

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

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)

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