Search in sources :

Example 1 with AssessmentModeManager

use of org.olat.course.assessment.AssessmentModeManager in project OpenOLAT by OpenOLAT.

the class AuthHelper method initializeLogin.

/**
 * ONLY for authentication provider OLAT Authenticate Identity and do the
 * necessary work. Returns true if successfull, false otherwise.
 *
 * @param identity
 * @param authProvider
 * @param ureq
 * @return boolean
 */
private static int initializeLogin(Identity identity, String authProvider, UserRequest ureq, boolean rest) {
    // continue only if user has login permission.
    if (identity == null)
        return LOGIN_FAILED;
    // test if a user may not logon, since he/she is in the PERMISSION_LOGON
    if (!BaseSecurityManager.getInstance().isIdentityVisible(identity)) {
        log.audit("was denied login");
        return LOGIN_DENIED;
    }
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    // if the user sending the cookie did not log out and we are logging in
    // again, then we need to make sure everything is cleaned up. we cleanup in all cases.
    UserSession usess = ureq.getUserSession();
    // prepare for a new user: clear all the instance vars of the userSession
    // note: does not invalidate the session, since it is reused
    sessionManager.signOffAndClear(usess);
    // init the UserSession for the new User
    // we can set the identity and finish the log in process
    usess.setIdentity(identity);
    setRolesFor(identity, usess);
    // check if loginDenied or maxSession (only for non-admin)
    if ((loginBlocked && !usess.getRoles().isOLATAdmin()) || (((maxSessions != MAX_SESSION_NO_LIMIT) && (sessionManager.getUserSessionsCnt() >= maxSessions)) && !usess.getRoles().isOLATAdmin())) {
        log.audit("Login was blocked for username=" + usess.getIdentity().getName() + ", loginBlocked=" + loginBlocked + " NbrOfSessions=" + sessionManager.getUserSessionsCnt());
        sessionManager.signOffAndClear(usess);
        return LOGIN_NOTAVAILABLE;
    }
    // need to block the all things for assessment?
    if (usess.getRoles() != null && usess.getRoles().isOLATAdmin()) {
        usess.setAssessmentModes(Collections.<TransientAssessmentMode>emptyList());
    } else {
        AssessmentModule assessmentModule = CoreSpringFactory.getImpl(AssessmentModule.class);
        if (assessmentModule.isAssessmentModeEnabled()) {
            AssessmentModeManager assessmentManager = CoreSpringFactory.getImpl(AssessmentModeManager.class);
            List<AssessmentMode> modes = assessmentManager.getAssessmentModeFor(identity);
            if (modes.isEmpty()) {
                usess.setAssessmentModes(Collections.<TransientAssessmentMode>emptyList());
            } else {
                usess.setAssessmentModes(TransientAssessmentMode.create(modes));
            }
        }
    }
    // set the language
    usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage()));
    // update fontsize in users session globalsettings
    Windows.getWindows(ureq).getWindowManager().setFontSize(Integer.parseInt(identity.getUser().getPreferences().getFontsize()));
    // calculate session info and attach it to the user session
    setSessionInfoFor(identity, authProvider, ureq, rest);
    // confirm signedOn
    sessionManager.signOn(usess);
    // set users web delivery mode
    Windows.getWindows(ureq).getWindowManager().setAjaxWanted(ureq);
    // update web delivery mode in session info
    usess.getSessionInfo().setWebModeFromUreq(ureq);
    return LOGIN_OK;
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) TransientAssessmentMode(org.olat.course.assessment.model.TransientAssessmentMode) AssessmentMode(org.olat.course.assessment.AssessmentMode) UserSession(org.olat.core.util.UserSession) AssessmentModeManager(org.olat.course.assessment.AssessmentModeManager) AssessmentModule(org.olat.course.assessment.AssessmentModule)

Example 2 with AssessmentModeManager

use of org.olat.course.assessment.AssessmentModeManager in project OpenOLAT by OpenOLAT.

the class IsAssessmentModeFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    /*
		 * expression check only if cev != null
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    WindowControl wControl = getUserCourseEnv().getWindowControl();
    if (wControl == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    ChiefController chiefController = wControl.getWindowBackOffice().getChiefController();
    if (chiefController == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    OLATResourceable lockedResource = chiefController.getLockResource();
    if (lockedResource == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    Long resourceableId = getUserCourseEnv().getCourseEnvironment().getCourseResourceableId();
    if (lockedResource.getResourceableId().equals(resourceableId)) {
        RepositoryEntry entry = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        AssessmentModeManager assessmentModeMgr = CoreSpringFactory.getImpl(AssessmentModeManager.class);
        boolean inAssessment = assessmentModeMgr.isInAssessmentMode(entry, new Date());
        return inAssessment ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    } else {
        return ConditionInterpreter.INT_FALSE;
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ChiefController(org.olat.core.gui.control.ChiefController) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) AssessmentModeManager(org.olat.course.assessment.AssessmentModeManager) Date(java.util.Date)

Example 3 with AssessmentModeManager

use of org.olat.course.assessment.AssessmentModeManager in project openolat by klemens.

the class AuthHelper method initializeLogin.

/**
 * ONLY for authentication provider OLAT Authenticate Identity and do the
 * necessary work. Returns true if successfull, false otherwise.
 *
 * @param identity
 * @param authProvider
 * @param ureq
 * @return boolean
 */
private static int initializeLogin(Identity identity, String authProvider, UserRequest ureq, boolean rest) {
    // continue only if user has login permission.
    if (identity == null)
        return LOGIN_FAILED;
    // test if a user may not logon, since he/she is in the PERMISSION_LOGON
    if (!BaseSecurityManager.getInstance().isIdentityVisible(identity)) {
        log.audit("was denied login");
        return LOGIN_DENIED;
    }
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    // if the user sending the cookie did not log out and we are logging in
    // again, then we need to make sure everything is cleaned up. we cleanup in all cases.
    UserSession usess = ureq.getUserSession();
    // prepare for a new user: clear all the instance vars of the userSession
    // note: does not invalidate the session, since it is reused
    sessionManager.signOffAndClear(usess);
    // init the UserSession for the new User
    // we can set the identity and finish the log in process
    usess.setIdentity(identity);
    setRolesFor(identity, usess);
    // check if loginDenied or maxSession (only for non-admin)
    if ((loginBlocked && !usess.getRoles().isOLATAdmin()) || (((maxSessions != MAX_SESSION_NO_LIMIT) && (sessionManager.getUserSessionsCnt() >= maxSessions)) && !usess.getRoles().isOLATAdmin())) {
        log.audit("Login was blocked for username=" + usess.getIdentity().getName() + ", loginBlocked=" + loginBlocked + " NbrOfSessions=" + sessionManager.getUserSessionsCnt());
        sessionManager.signOffAndClear(usess);
        return LOGIN_NOTAVAILABLE;
    }
    // need to block the all things for assessment?
    if (usess.getRoles() != null && usess.getRoles().isOLATAdmin()) {
        usess.setAssessmentModes(Collections.<TransientAssessmentMode>emptyList());
    } else {
        AssessmentModule assessmentModule = CoreSpringFactory.getImpl(AssessmentModule.class);
        if (assessmentModule.isAssessmentModeEnabled()) {
            AssessmentModeManager assessmentManager = CoreSpringFactory.getImpl(AssessmentModeManager.class);
            List<AssessmentMode> modes = assessmentManager.getAssessmentModeFor(identity);
            if (modes.isEmpty()) {
                usess.setAssessmentModes(Collections.<TransientAssessmentMode>emptyList());
            } else {
                usess.setAssessmentModes(TransientAssessmentMode.create(modes));
            }
        }
    }
    // set the language
    usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage()));
    // update fontsize in users session globalsettings
    Windows.getWindows(ureq).getWindowManager().setFontSize(Integer.parseInt(identity.getUser().getPreferences().getFontsize()));
    // calculate session info and attach it to the user session
    setSessionInfoFor(identity, authProvider, ureq, rest);
    // confirm signedOn
    sessionManager.signOn(usess);
    // set users web delivery mode
    Windows.getWindows(ureq).getWindowManager().setAjaxWanted(ureq);
    // update web delivery mode in session info
    usess.getSessionInfo().setWebModeFromUreq(ureq);
    return LOGIN_OK;
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) TransientAssessmentMode(org.olat.course.assessment.model.TransientAssessmentMode) AssessmentMode(org.olat.course.assessment.AssessmentMode) UserSession(org.olat.core.util.UserSession) AssessmentModeManager(org.olat.course.assessment.AssessmentModeManager) AssessmentModule(org.olat.course.assessment.AssessmentModule)

Example 4 with AssessmentModeManager

use of org.olat.course.assessment.AssessmentModeManager in project openolat by klemens.

the class IsAssessmentModeFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    /*
		 * expression check only if cev != null
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    WindowControl wControl = getUserCourseEnv().getWindowControl();
    if (wControl == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    ChiefController chiefController = wControl.getWindowBackOffice().getChiefController();
    if (chiefController == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    OLATResourceable lockedResource = chiefController.getLockResource();
    if (lockedResource == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    Long resourceableId = getUserCourseEnv().getCourseEnvironment().getCourseResourceableId();
    if (lockedResource.getResourceableId().equals(resourceableId)) {
        RepositoryEntry entry = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        AssessmentModeManager assessmentModeMgr = CoreSpringFactory.getImpl(AssessmentModeManager.class);
        boolean inAssessment = assessmentModeMgr.isInAssessmentMode(entry, new Date());
        return inAssessment ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    } else {
        return ConditionInterpreter.INT_FALSE;
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ChiefController(org.olat.core.gui.control.ChiefController) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) AssessmentModeManager(org.olat.course.assessment.AssessmentModeManager) Date(java.util.Date)

Aggregations

AssessmentModeManager (org.olat.course.assessment.AssessmentModeManager)4 Date (java.util.Date)2 ChiefController (org.olat.core.gui.control.ChiefController)2 WindowControl (org.olat.core.gui.control.WindowControl)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 UserSession (org.olat.core.util.UserSession)2 UserSessionManager (org.olat.core.util.session.UserSessionManager)2 AssessmentMode (org.olat.course.assessment.AssessmentMode)2 AssessmentModule (org.olat.course.assessment.AssessmentModule)2 TransientAssessmentMode (org.olat.course.assessment.model.TransientAssessmentMode)2 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2