use of org.olat.core.util.UserSession in project openolat by klemens.
the class UserSessionManager method getUserSessionIfAlreadySet.
/**
* Return the UserSession of the given request if it is already set or null otherwise
* @param hreq
* @return
*/
public UserSession getUserSessionIfAlreadySet(HttpServletRequest hreq) {
HttpSession session = hreq.getSession(false);
if (session == null) {
return null;
}
UserSession us = (UserSession) session.getAttribute(USERSESSIONKEY);
setHttpSessionTimeout(session, us);
return us;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class RestApiLoginFilter method followToken.
private void followToken(String token, HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpSession session = request.getSession(true);
session.setMaxInactiveInterval(TOKEN_BASED_SESSION_TIMEOUT);
UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(session);
if (uress != null) {
UserRequest ureq = null;
try {
// upon creation URL is checked for
String requestURI = request.getRequestURI();
ureq = new UserRequestImpl(requestURI, request, response);
} catch (Exception e) {
response.sendError(500);
return;
}
request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
RestSecurityBean securityBean = (RestSecurityBean) CoreSpringFactory.getBean(RestSecurityBean.class);
Identity identity = securityBean.getIdentity(token);
int loginStatus = AuthHelper.doHeadlessLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq, true);
if (loginStatus == AuthHelper.LOGIN_OK) {
String renewedToken = securityBean.renewToken(token);
if (renewedToken != null) {
response.setHeader(RestSecurityHelper.SEC_TOKEN, renewedToken);
synchronized (uress) {
chain.doFilter(request, response);
}
} else
response.sendError(401);
} else
response.sendError(401);
} else
response.sendError(401);
}
use of org.olat.core.util.UserSession in project openolat by klemens.
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;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class StatusWebservice method getSystemSummaryVO.
/**
* Return the statistics about runtime: uptime, classes loaded, memory
* summary, threads count...
*
* @response.representation.200.qname {http://www.example.com}runtimeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The version of the instance
* @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param request The HTTP request
* @return The informations about runtime, uptime, classes loaded, memory summary...
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
StatusVO stats = new StatusVO();
// File
try {
long startFile = System.nanoTime();
File infoFile = setInfoFiles("ping");
WorkThreadInformations.unset();
stats.setWriteFileInMilliseconds(CodeHelper.nanoToMilliTime(startFile));
stats.setWriteFile(infoFile.exists());
infoFile.delete();
} catch (Exception e) {
stats.setWriteFile(false);
stats.setWriteFileInMilliseconds(-1l);
log.error("", e);
}
// Datebase
try {
stats.setWriteDb(true);
PropertyManager propertyManager = CoreSpringFactory.getImpl(PropertyManager.class);
List<Property> props = propertyManager.findProperties((Identity) null, (BusinessGroup) null, PING_RESOURCE, PING_REF, PING_REF);
if (props != null && props.size() > 0) {
for (Property prop : props) {
propertyManager.deleteProperty(prop);
}
DBFactory.getInstance().commit();
}
long startDB = System.nanoTime();
Property prop = propertyManager.createPropertyInstance(null, null, PING_RESOURCE, PING_REF, PING_REF, 0f, 0l, "-", "-");
DBFactory.getInstance().commit();
stats.setWriteDbInMilliseconds(CodeHelper.nanoToMilliTime(startDB));
propertyManager.deleteProperty(prop);
DBFactory.getInstance().commit();
} catch (Exception e) {
stats.setWriteDb(false);
stats.setWriteDbInMilliseconds(-1l);
log.error("", e);
}
// Secure authenticated user
UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
Set<UserSession> userSessions = sessionManager.getAuthenticatedUserSessions();
int secureAuthenticatedCount = 0;
for (UserSession usess : userSessions) {
SessionInfo sessInfo = usess.getSessionInfo();
if (sessInfo.isWebDAV() || sessInfo.isREST()) {
//
} else if (sessInfo.isSecure()) {
secureAuthenticatedCount++;
}
}
stats.setSecureAuthenticatedCount(secureAuthenticatedCount);
// Concurrent dispatch threads
SessionStatsManager sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class);
stats.setConcurrentDispatchThreads(sessionStatsManager.getConcurrentCounter());
return Response.ok(stats).build();
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class MapperServiceTest method testGetMapper_serializable.
@Test
public void testGetMapper_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.getKey(), reloadedMapper.getKey());
Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
// remove in memory mappers
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(mapper.getKey(), reloadedMapper2.getKey());
}
Aggregations