Package org.olat.core.util

Examples of org.olat.core.util.UserSession


   * sure you call remove18nInfoFromThread() when the thread is finished!
   *
   * @param hreq The http servlet request
   */
  public static void attachI18nInfoToThread(HttpServletRequest hreq) {
    UserSession usess = UserSession.getUserSession(hreq);
    if (threadLocalLocale == null) {
      I18nManager.getInstance().logError("can't attach i18n info to thread: threadLocalLocale is null", null);
    } else {
      if (threadLocalLocale.getThreadLocale() != null) {
        I18nManager.getInstance().logWarn(
            "try to attach i18n info to thread, but threadLocalLocale is not null - a thread forgot to remove it!", new Exception("attachI18nInfoToThread"));
      }
      threadLocalLocale.setThredLocale(usess.getLocale());
    }
    if (threadLocalIsMarkLocalizedStringsEnabled == null) {
      I18nManager.getInstance().logError("can't attach i18n info to thread: threadLocalIsMarkLocalizedStringsEnabled is null", null);
    } else {
      if (threadLocalIsMarkLocalizedStringsEnabled.isMarkLocalizedStringsEnabled() != null) {
        I18nManager.getInstance().logWarn(
            "try to attach i18n info to thread, but threadLocalIsMarkLocalizedStringsEnabled is not null - a thread forgot to remove it!",
            null);
      }
      Boolean isMarkLocalizedStringsEnabled = (Boolean) usess.getEntry(USESS_KEY_I18N_MARK_LOCALIZED_STRINGS);
      if (isMarkLocalizedStringsEnabled != null) {
        threadLocalIsMarkLocalizedStringsEnabled.setMarkLocalizedStringsEnabled(isMarkLocalizedStringsEnabled);
      }
    }
  }
View Full Code Here


  /**
   * @return the usersession
   */
  public UserSession getUserSession() {
    //FIXME:fj:b cache usersession here
    UserSession result = UserSession.getUserSession(getHttpReq());
    if (result==null) {
      Tracing.logWarn("getUserSession: null, this="+this, new RuntimeException("getUserSession"), UserSession.class);
    }
    return result;
  }
View Full Code Here

      //thread local data is not initialized so far if Tracing is called from
      //e.g. a worker thread like in Search or UpdateEfficiency worker
      //TODO:pb:check if this was also a problem with IM threads.
      ureq = tld.getHttpServletRequest();
    }
    UserSession usess = null;
    Identity identity = null;
    String remoteIp = null;
    String userAgent = null;
    String referer = null;
    if (ureq != null) {
      usess = UserSession.getUserSessionIfAlreadySet(ureq);
      if (usess != null) {
        identity = usess.getIdentity();
        remoteIp = ureq.getRemoteAddr();
        userAgent = ureq.getHeader("User-Agent");
        referer = ureq.getHeader("Referer");
      }
    }
View Full Code Here

      //thread local data is not initialized so far if Tracing is called from
      //e.g. a worker thread like in Search or UpdateEfficiency worker
      //TODO:pb:check if this was also a problem with IM threads.
      ureq = tld.getHttpServletRequest();
    }
    UserSession usess = null;
    Identity identity = null;
    String remoteIp = null;
    String userAgent = null;
    String referer = null;
    if (ureq != null) {
      usess = UserSession.getUserSession(ureq);
      identity = usess.getIdentity();
      remoteIp = ureq.getRemoteAddr();
      userAgent = ureq.getHeader("User-Agent");
      referer = ureq.getHeader("Referer");
    }
View Full Code Here

  /**
   * @param ureq
   * @return the Windows for this user
   */
  public static Windows getWindows(UserRequest ureq) {
    UserSession us = ureq.getUserSession();
    return getWindows(us);
  }
View Full Code Here

      // try to get cached dir context
      if (webDAVManager == null) {
        // not initialized properly
        return null;
      }
      UserSession usess = webDAVManager.getUserSession(hreq);
      if (usess == null) return null;
      try{
        usess.getSessionInfo().setLastClickTime();
      }catch(Throwable th){
          Tracing.logError("getResource failure: ", th, SecureWebdavServlet.class);
      }
      VFSDirContext fdc = (VFSDirContext)usess.getEntry("_DIRCTX");
      if (fdc != null) {
        fdc.setUserSession(usess);
        return fdc;
      }
     
      Identity identity = usess.getIdentity();
      // we need an identity...
      if (identity == null) return null;


      fdc = new VFSDirContext();
      fdc.setIdentity(identity);
      fdc.setUserSession(usess);
      fdc.setVirtualDocBase(WebDAVProviderFactory.getInstance().getMountableRoot(identity));
      fdc.setBuffer(super.input); // take inBuffer from DefaultServlet (configured via web.xml)
      // do not cache while debugging
      if (!Settings.isDebuging()) {
        usess.putEntry("_DIRCTX", fdc);
      }
     
      // OLAT-5243 related: sending back the reply can take arbitrary long,
      // considering slow end-user connections for example - or a sudden death of the connection
      // on the client-side which remains unnoticed (network partitioning)
View Full Code Here

    Map<String, Long> lastActivity = new HashMap<String, Long>();
    Set<String> usernames = InstantMessagingModule.getAdapter().getUsernamesFromConnectedUsers();
    List<UserSession> authSessions = new ArrayList(UserSession.getAuthenticatedUserSessions());
   
    for (Iterator<UserSession> iter = authSessions.iterator(); iter.hasNext();) {
      UserSession userSession = iter.next();
      long lastAccTime = 0;
      try {
        lastAccTime = userSession.getSessionInfo().getSession().getLastAccessedTime();
        lastActivity.put(userSession.getIdentity().getName(), Long.valueOf(lastAccTime));
      } catch (RuntimeException e) {
        //getAuthenticatedUserSessions delivers sessions that are sometimes already invalid.
        log.warn("Tried to get LastAccessTime from session that became in the meantime invalid", null);
      }
View Full Code Here

    Long timeNow = System.currentTimeMillis();

    List<UserSession> authUserSessions = new ArrayList<UserSession>(UserSession.getAuthenticatedUserSessions());

    for (Iterator<UserSession> iter = authUserSessions.iterator(); iter.hasNext();) {
      UserSession session = iter.next();
      long lastAccessTime = 0;
      String username = null;
      InstantMessagingClient client = null;
      boolean isWebDav = false;
      try {
        lastAccessTime = session.getSessionInfo().getLastClickTime();
        username = session.getIdentity().getName();
        isWebDav = session.getSessionInfo().isWebDAV();
      } catch (Exception e) {
        log.info("Tried to get LastAccessTime from session that became in the meantime invalid", e.toString());
      }
      if (!isWebDav) { // leave webdav sessions untouched

        if (InstantMessagingModule.isEnabled()) {
          // avoid reconnection of dead or duplicate sessions
          ClientManager mgr = InstantMessagingModule.getAdapter().getClientManager();
          if (username != null && mgr.hasActiveInstantMessagingClient(username)) client = mgr.getInstantMessagingClient(username);
          if (log.isDebug()) {
            if (client != null) log.debug("Fetched im client via mangager. Connections status is - connected=" + client.isConnected()
                + " for user: " + client.getUsername());
            else log.debug("Could not fetch IM client for user: " + username);
          }
        }
       
        if (session != null) {
          if ((timeNow - lastAccessTime) > autoLogOutCutTime) {
            try {
              // brasato:::: since tomcat doesn't do this in its normal
                // session invalidation process,
                // (since polling), we must do it manually.
                // But: it does not belong here (must work also without IM, but
                // with polling)
                // brasato:: alternative: instead of a job, generate a timer
                // which rechecks if clicked within 5 mins ??

                // TODO: that presence change stuff should also be moved to the
                // IMManager...
                // invalidation triggers dispose of controller chain and closes
                // IM
                // and removes IM client
              try {
                SessionInfo sessionInfo = session.getSessionInfo();
                if (sessionInfo!=null) {
                  HttpSession session2 = sessionInfo.getSession();
                  if (session2!=null) {
                    session2.invalidate();
                  }
View Full Code Here

    Set usesss = UserSession.getAuthenticatedUserSessions();
    int contcnt = DefaultController.getControllerCount();
    sb.append("total usersessions (auth and non auth): "+ucCnt+"<br />auth usersessions: "+usesss.size()+"<br />Total Controllers (active, not disposed) of all users:"+contcnt+"<br /><br />");
    Formatter f = Formatter.getInstance(ureq.getLocale());
    for (Iterator iter = usesss.iterator(); iter.hasNext();) {
      UserSession usess = (UserSession) iter.next();
      Identity iden = usess.getIdentity();
      sb.append("authusersession (").append(usess.hashCode()).append(") of ");
      if (iden != null) {
        sb.append(iden.getName()).append(" ").append(iden.getKey());
      }
      else {
        sb.append(" - ");
View Full Code Here

   * @param request
   * @param response
   * @param uriPrefix
   */
  public void execute(HttpServletRequest request, HttpServletResponse response, String uriPrefix) {
    UserSession usess = UserSession.getUserSession(request);
    UserRequest ureq = null;
    try{
      //upon creation URL is checked for
      ureq = new UserRequest(uriPrefix, request, response);
    } catch(NumberFormatException nfe) {
      //MODE could not be decoded
      //typically if robots with wrong urls hit the system
      //or user have bookmarks
      //or authors copy-pasted links to the content.
      //showing redscreens for non valid URL is wrong instead
      //a 404 message must be shown -> e.g. robots correct their links.
      if(Tracing.isDebugEnabled(AuthenticatedDispatcher.class)){
        Tracing.logDebug("Bad Request "+request.getPathInfo(), this.getClass());
      }
      DispatcherAction.sendBadRequest(request.getPathInfo(), response);
      return;
    }
    GUIInterna.setLoadPerformanceMode(ureq);   
   
    boolean auth = usess.isAuthenticated();

    if (!auth) {
      if (!ureq.isValidDispatchURI()) {
        // might be a direct jump request -> remember it if not logged in yet
        String reqUri = request.getRequestURI();
        String query = request.getQueryString();
        String allGet = reqUri + QUESTIONMARK + query;
        usess.putEntryInNonClearedStore(AUTHDISPATCHER_ENTRYURL, allGet);
      }
      String guestAccess = ureq.getParameter(GUEST);
      if (guestAccess == null || !LoginModule.isGuestLoginLinksEnabled()) {
        DispatcherAction.redirectToDefaultDispatcher(response);
        return;
      } else if (guestAccess.equals(TRUE)) {
        // try to log in as anonymous
        // use the language from the lang paramter if available, otherwhise use the system default locale
        String guestLang = ureq.getParameter("lang");
        Locale guestLoc;
        if (guestLang == null) {
          guestLoc = I18nModule.getDefaultLocale();
        } else {
          guestLoc = I18nManager.getInstance().getLocaleOrDefault(guestLang);
        }
        int loginStatus = AuthHelper.doAnonymousLogin(ureq, guestLoc);
        if ( loginStatus != AuthHelper.LOGIN_OK) {
          if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
            DispatcherAction.redirectToServiceNotAvailable(response);
          }
          DispatcherAction.redirectToDefaultDispatcher(response); // error, redirect to login screen
          return;
        }
        // else now logged in as anonymous user, continue
      }
    }

    // authenticated!
    try {
     
      //kill session if not secured via SSL
      if (forceSecureAccessOnly && !request.isSecure()) {
        SessionInfo sessionInfo = usess.getSessionInfo();
        if (sessionInfo!=null) {
          HttpSession session = sessionInfo.getSession();
          if (session!=null) {
            try{
              session.invalidate();
            } catch(IllegalStateException ise) {
              // thrown when session already invalidated. fine. ignore.
            }
          }
        }
        DispatcherAction.redirectToDefaultDispatcher(response);
        return;
      }
     
      SessionInfo sessionInfo = usess.getSessionInfo();
      if (sessionInfo==null) {
        DispatcherAction.redirectToDefaultDispatcher(response);
        return;
      }
     
      UserBasedLogLevelManager.activateUsernameBasedLogLevel(sessionInfo.getLogin());
     
      sessionInfo.setLastClickTime();
      String origUrl = (String) usess.removeEntryFromNonClearedStore(AUTHDISPATCHER_ENTRYURL);
      if (origUrl != null) {
        // we had a direct jump request
        // to avoid a endless redirect, remove the guest parameter if any
        // this can happen if a guest has cookies disabled
        String url = new URIHelper(origUrl).removeParameter(GUEST).toString();
        DispatcherAction.redirectTo(response, url);
        return;
      }
      String businessPath = (String) usess.removeEntryFromNonClearedStore(AUTHDISPATCHER_BUSINESSPATH);
      if (businessPath != null) {
        BusinessControl bc = BusinessControlFactory.getInstance().createFromString(businessPath);
        ChiefController cc = (ChiefController) Windows.getWindows(usess).getAttribute("AUTHCHIEFCONTROLLER");

        WindowControl wControl = cc.getWindowControl();
View Full Code Here

TOP

Related Classes of org.olat.core.util.UserSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.