Search in sources :

Example 1 with UserSessionManager

use of org.olat.core.util.session.UserSessionManager 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 UserSessionManager

use of org.olat.core.util.session.UserSessionManager in project OpenOLAT by OpenOLAT.

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();
}
Also used : PropertyManager(org.olat.properties.PropertyManager) SessionInfo(org.olat.core.util.SessionInfo) SessionStatsManager(org.olat.admin.sysinfo.manager.SessionStatsManager) IOException(java.io.IOException) UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) File(java.io.File) Property(org.olat.properties.Property) StatusVO(org.olat.restapi.system.vo.StatusVO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with UserSessionManager

use of org.olat.core.util.session.UserSessionManager 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;
}
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 4 with UserSessionManager

use of org.olat.core.util.session.UserSessionManager 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();
}
Also used : PropertyManager(org.olat.properties.PropertyManager) SessionInfo(org.olat.core.util.SessionInfo) SessionStatsManager(org.olat.admin.sysinfo.manager.SessionStatsManager) IOException(java.io.IOException) UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) File(java.io.File) Property(org.olat.properties.Property) StatusVO(org.olat.restapi.system.vo.StatusVO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with UserSessionManager

use of org.olat.core.util.session.UserSessionManager in project OpenOLAT by OpenOLAT.

the class RestApiLoginFilter method upgradeIpAuthentication.

private void upgradeIpAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    UserSession usess = sessionManager.getUserSessionIfAlreadySet(request);
    if (usess == null) {
        usess = sessionManager.getUserSession(request.getSession(true));
    }
    if (usess.getIdentity() == null) {
        usess.setRoles(new Roles(false, false, false, false, false, false, false));
        String remoteAddr = request.getRemoteAddr();
        SessionInfo sinfo = new SessionInfo(new Long(-1), "REST", request.getSession());
        sinfo.setFirstname("REST");
        sinfo.setLastname(remoteAddr);
        sinfo.setFromIP(remoteAddr);
        sinfo.setFromFQN(remoteAddr);
        try {
            InetAddress[] iaddr = InetAddress.getAllByName(request.getRemoteAddr());
            if (iaddr.length > 0)
                sinfo.setFromFQN(iaddr[0].getHostName());
        } catch (UnknownHostException e) {
        // ok, already set IP as FQDN
        }
        sinfo.setAuthProvider("IP");
        sinfo.setUserAgent(request.getHeader("User-Agent"));
        sinfo.setSecure(request.isSecure());
        sinfo.setREST(true);
        sinfo.setWebModeFromUreq(null);
        // set session info for this session
        usess.setSessionInfo(sinfo);
    }
    UserRequest ureq = null;
    try {
        // upon creation URL is checked for
        String requestURI = request.getRequestURI();
        ureq = new UserRequestImpl(requestURI, request, response);
        ureq.getUserSession().putEntryInNonClearedStore(RestSecurityHelper.SYSTEM_MARKER, Boolean.TRUE);
    } catch (NumberFormatException nfe) {
        response.sendError(401);
        return;
    }
    request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) UnknownHostException(java.net.UnknownHostException) UserSession(org.olat.core.util.UserSession) SessionInfo(org.olat.core.util.SessionInfo) Roles(org.olat.core.id.Roles) InetAddress(java.net.InetAddress) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Aggregations

UserSession (org.olat.core.util.UserSession)8 UserSessionManager (org.olat.core.util.session.UserSessionManager)8 SessionInfo (org.olat.core.util.SessionInfo)6 SessionStatsManager (org.olat.admin.sysinfo.manager.SessionStatsManager)4 File (java.io.File)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 SessionsStats (org.olat.admin.sysinfo.model.SessionsStats)2 UserRequest (org.olat.core.gui.UserRequest)2 UserRequestImpl (org.olat.core.gui.UserRequestImpl)2 Roles (org.olat.core.id.Roles)2 AssessmentMode (org.olat.course.assessment.AssessmentMode)2 AssessmentModeManager (org.olat.course.assessment.AssessmentModeManager)2 AssessmentModule (org.olat.course.assessment.AssessmentModule)2 TransientAssessmentMode (org.olat.course.assessment.model.TransientAssessmentMode)2 Property (org.olat.properties.Property)2 PropertyManager (org.olat.properties.PropertyManager)2