Search in sources :

Example 11 with SessionInfo

use of org.olat.core.util.SessionInfo in project openolat by klemens.

the class UserSessionDetailsController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == dialogController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            SessionInfo sessInfo = usess.getSessionInfo();
            if (usess.isAuthenticated()) {
                HttpSession session = sessInfo.getSession();
                if (session != null) {
                    try {
                        session.invalidate();
                    } catch (IllegalStateException ise) {
                    // thrown when session already invalidated. fine. ignore.
                    }
                }
                showInfo("sess.kill.done", sessInfo.getLogin());
            }
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionInfo(org.olat.core.util.SessionInfo)

Example 12 with SessionInfo

use of org.olat.core.util.SessionInfo 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)

Example 13 with SessionInfo

use of org.olat.core.util.SessionInfo 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 14 with SessionInfo

use of org.olat.core.util.SessionInfo 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 15 with SessionInfo

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

the class WebDAVManagerImpl method afterAuthorization.

private UserSession afterAuthorization(Identity identity, HttpServletRequest request) {
    UserSession usess = sessionManager.getUserSession(request);
    synchronized (usess) {
        // double check to prevent severals concurrent login
        if (usess.isAuthenticated()) {
            return usess;
        }
        sessionManager.signOffAndClear(usess);
        usess.setIdentity(identity);
        UserDeletionManager.getInstance().setIdentityAsActiv(identity);
        // set the roles (admin, author, guest)
        Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
        usess.setRoles(roles);
        // set session info
        SessionInfo sinfo = new SessionInfo(identity.getKey(), identity.getName(), request.getSession());
        User usr = identity.getUser();
        sinfo.setFirstname(usr.getProperty(UserConstants.FIRSTNAME, null));
        sinfo.setLastname(usr.getProperty(UserConstants.LASTNAME, null));
        String remoteAddr = request.getRemoteAddr();
        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(BaseSecurityModule.getDefaultAuthProviderIdentifier());
        sinfo.setUserAgent(request.getHeader("User-Agent"));
        sinfo.setSecure(request.isSecure());
        sinfo.setWebDAV(true);
        sinfo.setWebModeFromUreq(null);
        // set session info for this session
        usess.setSessionInfo(sinfo);
        // 
        sessionManager.signOn(usess);
        return usess;
    }
}
Also used : User(org.olat.core.id.User) 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)

Aggregations

SessionInfo (org.olat.core.util.SessionInfo)24 UserSession (org.olat.core.util.UserSession)18 HttpSession (javax.servlet.http.HttpSession)8 UserSessionManager (org.olat.core.util.session.UserSessionManager)8 InetAddress (java.net.InetAddress)6 UnknownHostException (java.net.UnknownHostException)6 Identity (org.olat.core.id.Identity)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)6 AssertException (org.olat.core.logging.AssertException)6 IOException (java.io.IOException)4 SessionStatsManager (org.olat.admin.sysinfo.manager.SessionStatsManager)4 UserRequest (org.olat.core.gui.UserRequest)4 UserRequestImpl (org.olat.core.gui.UserRequestImpl)4 Roles (org.olat.core.id.Roles)4 SignOnOffEvent (org.olat.core.util.SignOnOffEvent)4 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2