Search in sources :

Example 81 with UserSession

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

the class OpenOLATStatisticsWebService method getSessionsVO.

protected SessionsVO getSessionsVO() {
    SessionsVO vo = new SessionsVO();
    SessionStatsManager sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class);
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    vo.setCount(sessionManager.getUserSessionsCnt());
    Set<UserSession> userSessions = sessionManager.getAuthenticatedUserSessions();
    int webdavcount = 0;
    int secureWebdavCount = 0;
    int authenticatedcount = 0;
    int secureAuthenticatedCount = 0;
    int restCount = 0;
    int secureRestCount = 0;
    for (UserSession usess : userSessions) {
        SessionInfo sessInfo = usess.getSessionInfo();
        if (sessInfo.isWebDAV()) {
            webdavcount++;
            if (sessInfo.isSecure()) {
                secureWebdavCount++;
            }
        } else if (sessInfo.isREST()) {
            restCount++;
            if (sessInfo.isSecure()) {
                secureRestCount++;
            }
        } else {
            authenticatedcount++;
            if (sessInfo.isSecure()) {
                secureAuthenticatedCount++;
            }
        }
    }
    vo.setAuthenticatedCount(authenticatedcount);
    vo.setSecureAuthenticatedCount(secureAuthenticatedCount);
    vo.setWebdavCount(webdavcount);
    vo.setSecureWebdavCount(secureWebdavCount);
    vo.setRestCount(restCount);
    vo.setSecureRestCount(secureRestCount);
    // Instant messaging
    vo.setInstantMessagingCount(-1);
    SessionsStats statsLastMinute = sessionStatsManager.getSessionsStatsLast(60);
    SessionsStats statsLast5Minutes = sessionStatsManager.getSessionsStatsLast(300);
    vo.setAuthenticatedClickCountLastMinute(statsLastMinute.getAuthenticatedClickCalls());
    vo.setAuthenticatedClickCountLastFiveMinutes(statsLast5Minutes.getAuthenticatedPollerCalls());
    vo.setAuthenticatedPollCountLastMinute(statsLastMinute.getAuthenticatedPollerCalls());
    vo.setAuthenticatedPollCountLastFiveMinutes(statsLast5Minutes.getAuthenticatedPollerCalls());
    vo.setRequestLastMinute(statsLastMinute.getRequests());
    vo.setRequestLastFiveMinutes(statsLast5Minutes.getRequests());
    vo.setConcurrentDispatchThreads(sessionStatsManager.getConcurrentCounter());
    return vo;
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) SessionsStats(org.olat.admin.sysinfo.model.SessionsStats) SessionsVO(org.olat.restapi.system.vo.SessionsVO) UserSession(org.olat.core.util.UserSession) SessionInfo(org.olat.core.util.SessionInfo) SessionStatsManager(org.olat.admin.sysinfo.manager.SessionStatsManager)

Example 82 with UserSession

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

the class MapperServiceTest method testGetMapper.

@Test
public void testGetMapper() {
    // create a mapper
    UserSession session = createUserSession();
    DummyMapper mapper = new DummyMapper();
    MapperKey mapperKey = mapperService.register(session, mapper);
    dbInstance.commitAndCloseSession();
    // retrieve the mapper
    Mapper reloadedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper);
    Assert.assertEquals(mapper, reloadedMapper);
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 83 with UserSession

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

the class MapperServiceTest method createUserSession.

private UserSession createUserSession() {
    HttpSession httpSession = new MockHttpSession();
    UserSession userSession = sessionManager.getUserSession(httpSession);
    SessionInfo infos = new SessionInfo(CodeHelper.getRAMUniqueID(), UUID.randomUUID().toString(), httpSession);
    userSession.setSessionInfo(infos);
    // check if our mocked HTTP session makes what we want
    Assert.assertNotNull(userSession.getSessionInfo());
    Assert.assertNotNull(userSession.getSessionInfo().getSession());
    Assert.assertNotNull(userSession.getSessionInfo().getSession().getId());
    return userSession;
}
Also used : HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) UserSession(org.olat.core.util.UserSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) SessionInfo(org.olat.core.util.SessionInfo)

Example 84 with UserSession

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

the class MapperServiceTest method testRegister.

@Test
public void testRegister() {
    UserSession session = createUserSession();
    MapperKey mapperKey = mapperService.register(session, new DummyMapper());
    Assert.assertNotNull(mapperKey);
    Assert.assertNotNull(mapperKey.getMapperId());
    Assert.assertNotNull(mapperKey.getSessionId());
    Assert.assertNotNull(mapperKey.getUrl());
    Assert.assertTrue(mapperService.inMemoryCount() > 0);
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 85 with UserSession

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

the class MapperServiceTest method testChangingMapper_serializable.

@Test
public void testChangingMapper_serializable() {
    // create a mapper
    int initialNumOfMappers = mapperService.inMemoryCount();
    UserSession session = createUserSession();
    PersistentMapper mapper = new PersistentMapper(UUID.randomUUID().toString());
    MapperKey mapperKey = mapperService.register(session, mapper);
    dbInstance.commitAndCloseSession();
    // retrieve the mapper
    PersistentMapper reloadedMapper = (PersistentMapper) mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper);
    Assert.assertEquals(mapper, reloadedMapper);
    Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
    // changing the key in the mapper
    String modKey = UUID.randomUUID().toString();
    reloadedMapper.setKey(modKey);
    // remove in memory mappers
    mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
    mapperService.cleanUp(session.getSessionInfo().getSession().getId());
    Assert.assertEquals(initialNumOfMappers, mapperService.inMemoryCount());
    // reloaded episode 2
    PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(null, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper2);
    Assert.assertEquals(modKey, reloadedMapper2.getKey());
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

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