Search in sources :

Example 36 with UserSession

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

the class BulkAssessmentTask method run.

/**
 * Used by to task executor, without any GUI
 */
@Override
public void run() {
    final List<BulkAssessmentFeedback> feedbacks = new ArrayList<>();
    try {
        log.audit("Start process bulk assessment");
        LoggingResourceable[] infos = new LoggingResourceable[2];
        if (task != null && task.getCreator() != null) {
            UserSession session = new UserSession();
            session.setIdentity(task.getCreator());
            session.setSessionInfo(new SessionInfo(task.getCreator().getKey(), task.getCreator().getName()));
            ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(session);
            infos[0] = LoggingResourceable.wrap(courseRes, OlatResourceableType.course);
            ThreadLocalUserActivityLogger.addLoggingResourceInfo(infos[0]);
            infos[1] = LoggingResourceable.wrap(getCourseNode());
            ThreadLocalUserActivityLogger.addLoggingResourceInfo(infos[1]);
        }
        doProcess(feedbacks);
        log.audit("End process bulk assessment");
        cleanup();
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_BULK, getClass(), infos);
    } catch (Exception e) {
        log.error("", e);
        feedbacks.add(new BulkAssessmentFeedback("", "bulk.assessment.error"));
        throw e;
    } finally {
        cleanupUnzip();
        sendFeedback(feedbacks);
    }
}
Also used : BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) UserSession(org.olat.core.util.UserSession) ArrayList(java.util.ArrayList) SessionInfo(org.olat.core.util.SessionInfo) LoggingResourceable(org.olat.util.logging.activity.LoggingResourceable) FileNotFoundException(java.io.FileNotFoundException)

Example 37 with UserSession

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

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

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

the class UserSessionController method event.

/**
 * @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)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            int selRow = te.getRowId();
            // session info (we only have authenticated sessions here
            UserSessionView usessw = (UserSessionView) tableCtr.getTableDataModel().getObject(selRow);
            if ("sess.chat".equals(te.getActionId())) {
                Buddy buddy = imService.getBuddyById(usessw.getIdentityKey());
                OpenInstantMessageEvent e = new OpenInstantMessageEvent(ureq, buddy);
                ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, InstantMessagingService.TOWER_EVENT_ORES);
            } else if ("sess.details".equals(te.getActionId())) {
                UserSession usess = usessw.getUserSession();
                UserSessionDetailsController detailsCtrl = new UserSessionDetailsController(ureq, getWindowControl(), usess);
                listenTo(detailsCtrl);
                String username = usess.getIdentity() == null ? "-" : UserManager.getInstance().getUserDisplayName(usess.getIdentity());
                stackController.pushController(username, detailsCtrl);
            }
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) UserSession(org.olat.core.util.UserSession) OpenInstantMessageEvent(org.olat.instantMessaging.OpenInstantMessageEvent) UserSessionView(org.olat.admin.sysinfo.model.UserSessionView) Buddy(org.olat.instantMessaging.model.Buddy)

Example 39 with UserSession

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

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

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

the class AuthHelper method doHeadlessLogin.

/**
 * @param identity
 * @param authProvider
 * @param ureq
 * @param Is login via REST API?
 * @return
 */
public static int doHeadlessLogin(Identity identity, String authProvider, UserRequest ureq, boolean rest) {
    int initializeStatus = initializeLogin(identity, authProvider, ureq, rest);
    if (initializeStatus != LOGIN_OK) {
        // login not successful
        return initializeStatus;
    }
    // Set session info to reflect the REST headless login
    UserSession usess = ureq.getUserSession();
    usess.getSessionInfo().setREST(true);
    usess.getIdentityEnvironment().getAttributes().put(ATTRIBUTE_IS_REST, "true");
    // 
    ThreadLocalUserActivityLogger.log(OlatLoggingAction.OLAT_LOGIN, AuthHelper.class, LoggingResourceable.wrap(identity));
    return LOGIN_OK;
}
Also used : UserSession(org.olat.core.util.UserSession)

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