Search in sources :

Example 66 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.

the class WebDAVManagerImpl method getWebDAVRoot.

@Override
public WebResourceRoot getWebDAVRoot(HttpServletRequest req) {
    UserSession usess = getUserSession(req);
    if (usess == null || usess.getIdentity() == null) {
        return createEmptyRoot(usess);
    }
    usess.getSessionInfo().setLastClickTime();
    VFSResourceRoot fdc = (VFSResourceRoot) usess.getEntry("_DIRCTX");
    if (fdc != null) {
        return fdc;
    }
    IdentityEnvironment identityEnv = usess.getIdentityEnvironment();
    VFSContainer webdavContainer = getMountableRoot(identityEnv);
    // create the / folder
    VirtualContainer rootContainer = new VirtualContainer("");
    rootContainer.addItem(webdavContainer);
    rootContainer.setLocalSecurityCallback(new ReadOnlyCallback());
    fdc = new VFSResourceRoot(identityEnv.getIdentity(), rootContainer);
    usess.putEntry("_DIRCTX", fdc);
    return fdc;
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserSession(org.olat.core.util.UserSession) VFSContainer(org.olat.core.util.vfs.VFSContainer) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 67 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.

the class MembersAvatarDisplayRunController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Comparator<Identity> idComparator = new IdentityComparator();
    Collections.sort(owners, idComparator);
    Collections.sort(coaches, idComparator);
    Collections.sort(participants, idComparator);
    Collections.sort(waiting, idComparator);
    if (canEmail) {
        allEmailLink = uifactory.addFormLink("email", "members.email.title", null, formLayout, Link.BUTTON);
        allEmailLink.setIconLeftCSS("o_icon o_icon_mail");
    }
    IdentityEnvironment idEnv = ureq.getUserSession().getIdentityEnvironment();
    Identity ownId = idEnv.getIdentity();
    Roles roles = idEnv.getRoles();
    if (editable && (roles.isOLATAdmin() || roles.isGroupManager() || owners.contains(ownId) || coaches.contains(ownId) || (canDownload && !waiting.contains(ownId)))) {
        downloadLink = uifactory.addFormLink("download", "members.download", null, formLayout, Link.BUTTON);
        downloadLink.setIconLeftCSS("o_icon o_icon_download");
        if (formLayout instanceof FormLayoutContainer) {
            printLink = LinkFactory.createButton("print", ((FormLayoutContainer) formLayout).getFormItemComponent(), this);
            printLink.setIconLeftCSS("o_icon o_icon_print o_icon-lg");
            printLink.setPopup(new LinkPopupSettings(700, 500, "print-members"));
            ((FormLayoutContainer) formLayout).getFormItemComponent().put("print", printLink);
        }
    }
    Set<Long> duplicateCatcher = deduplicateList ? new HashSet<Long>() : null;
    ownerList = initFormMemberList("owners", owners, duplicateCatcher, formLayout, canEmail);
    coachList = initFormMemberList("coaches", coaches, duplicateCatcher, formLayout, canEmail);
    participantList = initFormMemberList("participants", participants, duplicateCatcher, formLayout, canEmail);
    waitingtList = initFormMemberList("waiting", waiting, duplicateCatcher, formLayout, canEmail);
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("showOwners", showOwners);
        layoutCont.contextPut("hasOwners", new Boolean(!ownerList.isEmpty()));
        layoutCont.contextPut("showCoaches", showCoaches);
        layoutCont.contextPut("hasCoaches", new Boolean(!coachList.isEmpty()));
        layoutCont.contextPut("showParticipants", showParticipants);
        layoutCont.contextPut("hasParticipants", new Boolean(!participantList.isEmpty()));
        layoutCont.contextPut("showWaiting", showWaiting);
        layoutCont.contextPut("hasWaiting", new Boolean(!waitingtList.isEmpty()));
    }
}
Also used : LinkPopupSettings(org.olat.core.gui.components.link.LinkPopupSettings) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 68 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.

the class QTI21ResetDataController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (courseNode instanceof IQTESTCourseNode) {
        IQTESTCourseNode testCourseNode = (IQTESTCourseNode) courseNode;
        RepositoryEntry testEntry = courseNode.getReferencedRepositoryEntry();
        RepositoryEntry courseEntry = courseEnv.getCourseGroupManager().getCourseEntry();
        ICourse course = CourseFactory.loadCourse(courseEntry);
        archiveData(course, options);
        qtiService.deleteAssessmentTestSession(identities, testEntry, courseEntry, courseNode.getIdent());
        for (Identity identity : identities) {
            ScoreEvaluation scoreEval = new ScoreEvaluation(null, null, AssessmentEntryStatus.notStarted, null, Boolean.FALSE, 0.0d, AssessmentRunStatus.notStarted, null);
            IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
            UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, courseEnv);
            testCourseNode.updateUserScoreEvaluation(scoreEval, uce, getIdentity(), false, Role.coach);
            testCourseNode.updateCurrentCompletion(uce, getIdentity(), null, AssessmentRunStatus.notStarted, Role.coach);
        }
    } else if (assessedEntry != null) {
        archiveData(assessedEntry);
        qtiService.deleteAssessmentTestSession(identities, assessedEntry, null, null);
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 69 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.

the class UserSessionManager method signOffAndClearWithout.

/**
 * called from signOffAndClear()
 * called from event -> MUEvent
 * the real work to do during sign off but without sending the multiuserevent
 * this is used in case the user logs in to node1 and was logged in on node2 =>
 * node2 catches the sign on event and invalidates the user on node2 "silently", e.g.
 * without firing an event.
 */
private void signOffAndClearWithout(final UserSession usess) {
    boolean isDebug = log.isDebug();
    if (isDebug)
        log.debug("signOffAndClearWithout() START");
    final IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
    final SessionInfo sessionInfo = usess.getSessionInfo();
    final Identity ident = identityEnvironment.getIdentity();
    if (isDebug)
        log.debug("UserSession:::logging off: " + sessionInfo);
    if (usess.isAuthenticated() && usess.getLastHistoryPoint() != null && !usess.getRoles().isGuestOnly()) {
        historyManager.persistHistoryPoint(ident, usess.getLastHistoryPoint());
    }
    /**
     * use not RunnableWithException, as exceptionHandlng is inside the run
     */
    Runnable run = new Runnable() {

        @Override
        public void run() {
            Object obj = null;
            try {
                // do logging
                if (ident != null) {
                    ThreadLocalUserActivityLogger.log(OlatLoggingAction.OLAT_LOGOUT, UserSession.class, CoreLoggingResourceable.wrap(ident));
                }
                // notify all variables in the store (the values) about the disposal
                // if
                // Disposable
                List<Object> storeList = usess.getStoreValues();
                for (Iterator<Object> it_storevals = storeList.iterator(); it_storevals.hasNext(); ) {
                    obj = it_storevals.next();
                    if (obj instanceof Disposable) {
                        // synchronous, since triggered by tomcat session timeout or user
                        // click and
                        // asynchronous, if kicked out by administrator.
                        // we assume synchronous
                        // !!!!
                        // As a reminder, this .dispose() calls dispose on
                        // DefaultController which is synchronized.
                        // (Windows/WindowManagerImpl/WindowBackOfficeImpl/BaseChiefController/../
                        // dispose()
                        // !!!! was important for bug OLAT-3390
                        ((Disposable) obj).dispose();
                    }
                }
            } catch (Exception e) {
                String objtostr = "n/a";
                try {
                    objtostr = obj.toString();
                } catch (Exception ee) {
                // ignore
                }
                log.error("exception in signOffAndClear: while disposing object:" + objtostr, e);
            }
        }
    };
    ThreadLocalUserActivityLoggerInstaller.runWithUserActivityLogger(run, UserActivityLoggerImpl.newLoggerForValueUnbound(usess));
    if (authUserSessions.remove(usess)) {
        // remove only from identityEnvironment if found in sessions.
        // see also SIDEEFFECT!! line in signOn(..)
        Identity previousSignedOn = identityEnvironment.getIdentity();
        if (previousSignedOn != null && previousSignedOn.getKey() != null) {
            if (isDebug)
                log.debug("signOffAndClearWithout() removing from userNameToIdentity: " + previousSignedOn.getName().toLowerCase());
            userNameToIdentity.remove(previousSignedOn.getKey());
            userSessionCache.remove(previousSignedOn.getKey());
        }
    } else if (isDebug) {
        log.info("UserSession already removed! for [" + ident + "]");
    }
    // update logged in users counters
    if (sessionInfo != null) {
        if (sessionInfo.isREST()) {
            sessionCountRest.decrementAndGet();
        } else if (sessionInfo.isWebDAV()) {
            sessionCountDav.decrementAndGet();
        } else {
            sessionCountWeb.decrementAndGet();
        }
    }
    if (isDebug)
        log.debug("signOffAndClearWithout() END");
}
Also used : Disposable(org.olat.core.gui.control.Disposable) SessionInfo(org.olat.core.util.SessionInfo) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) AssertException(org.olat.core.logging.AssertException)

Example 70 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.

the class UserSessionManager method signOn.

/**
 * prior to calling this method, all instance vars must be set.
 */
public void signOn(UserSession usess) {
    boolean isDebug = log.isDebug();
    // fix a possible dead-lock see also OLAT-3390
    synchronized (usess) {
        if (isDebug)
            log.debug("signOn() START");
        if (usess.isAuthenticated()) {
            throw new AssertException("sign on: already signed on!");
        }
        IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
        Identity identity = identityEnvironment.getIdentity();
        if (identity == null) {
            throw new AssertException("identity is null in identityEnvironment!");
        }
        SessionInfo sessionInfo = usess.getSessionInfo();
        if (sessionInfo == null) {
            throw new AssertException("sessionInfo was null for identity " + identity);
        }
        usess.setAuthenticated(true);
        if (sessionInfo.isWebDAV()) {
            // load user prefs
            usess.reloadPreferences();
            // we're only adding this webdav session to the authUserSessions - not to the userNameToIdentity.
            // userNameToIdentity is only needed for IM which can't do anything with a webdav session
            authUserSessions.add(usess);
            log.audit("Logged on [via webdav]: " + sessionInfo.toString());
        } else {
            UserSession invalidatedSession = null;
            if (isDebug) {
                log.debug("signOn() authUsersNamesOtherNodes.contains " + identity.getName() + ": " + authUsersNamesOtherNodes.contains(identity.getKey()));
            }
            // check if already a session exist for this user
            if ((userNameToIdentity.contains(identity.getKey()) || userSessionCache.containsKey(identity.getKey())) && !sessionInfo.isWebDAV() && !sessionInfo.isREST() && !usess.getRoles().isGuestOnly()) {
                log.info("Loggin-process II: User has already a session => signOffAndClear existing session");
                invalidatedSession = getUserSessionForGui(identity.getKey());
                // signOffAndClear does not remove the identity.getName().toLowerCase() from the userNameToIdentity
                if (invalidatedSession != null) {
                    authUserSessions.remove(invalidatedSession);
                }
            }
            authUserSessions.add(usess);
            // characters -> map stores values as such
            if (isDebug)
                log.debug("signOn() adding to userNameToIdentity: " + identity.getName().toLowerCase());
            userNameToIdentity.add(identity.getKey());
            userSessionCache.put(identity.getKey(), new Integer(Settings.getNodeId()));
            // reload user prefs
            usess.reloadPreferences();
            log.audit("Logged on: " + sessionInfo.toString());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, true), ORES_USERSESSION);
            // check if a session from any browser was invalidated (IE has a cookie set per Browserinstance!!)
            if (invalidatedSession != null || authUsersNamesOtherNodes.contains(identity.getKey())) {
                // put flag killed-existing-session into session-store to show info-message 'only one session for each user' on user-home screen
                usess.putEntry(STORE_KEY_KILLED_EXISTING_SESSION, Boolean.TRUE);
                if (isDebug)
                    log.debug("signOn() removing from authUsersNamesOtherNodes: " + identity.getName());
                authUsersNamesOtherNodes.remove(identity.getKey());
                // OLAT-3381 & OLAT-3382
                if (invalidatedSession != null) {
                    signOffAndClear(invalidatedSession);
                }
            }
            if (isDebug)
                log.debug("signOn() END");
        }
        // update logged in users counters
        if (sessionInfo.isREST()) {
            sessionCountRest.incrementAndGet();
        } else if (sessionInfo.isWebDAV()) {
            sessionCountDav.incrementAndGet();
        } else {
            sessionCountWeb.incrementAndGet();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertException(org.olat.core.logging.AssertException) UserSession(org.olat.core.util.UserSession) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SessionInfo(org.olat.core.util.SessionInfo) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Aggregations

IdentityEnvironment (org.olat.core.id.IdentityEnvironment)96 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 Identity (org.olat.core.id.Identity)56 ICourse (org.olat.course.ICourse)52 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Roles (org.olat.core.id.Roles)30 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Test (org.junit.Test)20 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)20 CourseNode (org.olat.course.nodes.CourseNode)18 ArrayList (java.util.ArrayList)16 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 File (java.io.File)14 INode (org.olat.core.util.nodes.INode)12 Visitor (org.olat.core.util.tree.Visitor)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 URL (java.net.URL)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10