Package org.olat.core.id

Examples of org.olat.core.id.Identity


  private ContactList cleanEMailList(ContactList emailList) {
    Hashtable identityEmails = emailList.getIdentiEmails();
    Enumeration enumeration = identityEmails.elements();
    String value = "";
    while (enumeration.hasMoreElements()) {
      Identity identity = (Identity) enumeration.nextElement();
      List<Identity> singleIdentityList = new ArrayList<Identity>();
      singleIdentityList.add(identity);
      MailerResult result = new MailerResult();
      if(MailHelper.removeDisabledMailAddress(singleIdentityList, result).getFailedIdentites().size() > 0) {
        emailList.remove(identity);
View Full Code Here


     */
    Enumeration enumeration = identiEmails.elements();
    String addEmail = null;
    if (emailPrioInstitutional) {
      while (enumeration.hasMoreElements()) {
        Identity tmp = (Identity) enumeration.nextElement();
        addEmail = tmp.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
        if (addEmail != null) {
          ret.add(addEmail);
          identiEmails.remove(tmp);
        }
      }
    }
    /*
     * loops over the (remaining) identities, fetches the user email.
     */
    while (enumeration.hasMoreElements()) {
      Identity tmp = (Identity) enumeration.nextElement();
      ret.add(tmp.getUser().getProperty(UserConstants.EMAIL, null));
    }
    return ret;
  }
View Full Code Here

          convertLoggingResourceableListToString(resourceInfos), new Exception());
      return;
    }
    final String sessionId = session_.getSessionInfo().getSession().getId();

    Identity identity = session_.getIdentity();
    if (identity==null) {
      // no identity available - odd
      log_.error("No identity available to UserActivityLogger. Cannot write log entry: "+
          crudAction.name()+":"+actionVerb.name()+", "+actionObject+", "+
          convertLoggingResourceableListToString(resourceInfos), new Exception());
      return;
    }
   
    Long identityKey = identity.getKey();
   
    if (actionType!=ActionType.admin) {
      final String identityKeyStr = String.valueOf(identityKey);
      for (Iterator it = resourceInfos.iterator(); it.hasNext();) {
        ILoggingResourceable lr = (ILoggingResourceable) it.next();
        if (lr.getResourceableType()==StringResourceableType.targetIdentity) {
          if (!lr.getId().equals(identityKeyStr)) {
            // complain
            log_.error("OLAT-4955: Not storing targetIdentity for non-admin logging actions. A non-admin logging action wanted to store a user other than the one from the session: action="+loggingAction+", fieldId="+loggingAction.getJavaFieldIdForDebug(), new Exception("OLAT-4955 debug stacktrac"));
          }
          // OLAT-4955: remove targetIdentity
          it.remove();
        }
      }
    }
   
    String identityName;
    if(isLogAnonymous_ && (actionType != ActionType.admin)) {
      identityName = "";
    } else {
      identityName = identity.getName();
    }
   
    // start creating the LoggingObject
    final LoggingObject logObj = new LoggingObject(sessionId, identityKey, identityName, crudAction.name().substring(0,1), actionVerb.name(), actionObject);
   
    // do simpleDuration calculation & storing
    LoggingObject lastLogObj = (LoggingObject) session_.getEntry(USESS_KEY_USER_ACTIVITY_LOGGING_LAST_LOG);
    if (lastLogObj!=null) {
      //lastLogObj = (LoggingObject) DBFactory.getInstance().loadObject(lastLogObj);
      //      DBFactory.getInstance().updateObject(lastLogObj);
      // Implementation Note:
      //   we used to do loadObject(), updateObject() here - which is the preferred best practice hibernate way
      //   for changing an existing object in the database.
      //   in the setup @UZH we'll use BLACKHOLE as the storage engine for the o_loggingtable (this is to have
      //   minimal work load on the Main OLAT DB and not have duplicate data on the Main OLAT DB and the Logging DB).
      //   Using BLACKHOLE results in the 'lastLogObj' here, not to exist in the database anymore.
      //   Hence we can't do a loadObject() nor an updateObject(). The latter does not work due to the fact
      //   that Hibernate checks the number of updated rows and expect that to equal 1 - which is not the case
      //   when using BLACKHOLE.
     
      // Workaround: - also compare with LoggingObject.hbm.xml docu
      //
      //   We use the sql-update's feature check="none", which disables the above mentioned check.
      //   Using this in combination with manual SQL code below seems to be the only feasible way
      //   to have Hibernate not do any row-number-checks.
     
      // Implications of the workaround:
      //
      //  * Manual SQL: It shouldn't be a big deal to have this manual SQL code as it is very standard.
      //  * CANT USE updateObject(LoggingObject) EVER:
      //@TODO    We might have to add a check which verifies that no one calls updateObject(LoggingObject)
      //         if that would be called it would simply fail in the BLACKHOLE@UZH setup
     
      // calculate the duration - take the simple diff of the two creationDate fields
      Date currentTime = logObj.getCreationDate();
      Date lastTime = lastLogObj.getCreationDate();
      long duration;
      if (lastTime==null) {
        duration = -1;
      } else if (currentTime==null) {
        duration = System.currentTimeMillis() - lastTime.getTime();
      } else {
        duration = currentTime.getTime() - lastTime.getTime();
      }
     
      DB db = DBFactory.getInstanceForClosing();
      if (db!=null && db.isError()) {
        // then we would run into an ERROR when we'd do more with this DB
        // hence we just issue a log.info here with the details
        //@TODO: lower to log_.info once we checked that it doesn't occur very often (best for 6.4)
        log_.warn("log: DB is in Error state therefore the UserActivityLoggerImpl cannot update the simpleDuration of log_id "+lastLogObj.getKey()+" with value "+duration+", loggingObject: "+lastLogObj);
      } else {
        DBQuery update = DBFactory.getInstance().createQuery(
            "update org.olat.core.logging.activity.LoggingObject set simpleDuration = :duration where log_id = :logid");
        update.setLong("duration", duration);
        update.setLong("logid", lastLogObj.getKey());
        // we have to do FlushMode.AUTO (which is the default anyway)
        update.executeUpdate(FlushMode.AUTO);
      }
    }
   
    // store the current logging object in the session - for duration calculation at next log
    session_.putEntry(USESS_KEY_USER_ACTIVITY_LOGGING_LAST_LOG, logObj);

    if (resourceInfos!=null && resourceInfos.size()!=0) {
      // this should be the normal case - we do have LoggingResourceables which we can log
      // alongside the log message
     
      // check if we have more than 4 - if we do, issue a log and remove the middle ones
      if (resourceInfos.size()>4) {
        log_.warn("More than 4 resource infos set on a user activity log. Can only have 4. Having: "+resourceInfos.size());
        int diff = resourceInfos.size()-4;
        for(int i=0; i<diff; i++) {
          resourceInfos.remove(3);
        }
      }
     
      // get the target resourceable
      ILoggingResourceable ri = resourceInfos.get(resourceInfos.size()-1);
      logObj.setTargetResourceInfo(ri);
     
      // now set parent - if applicable
      if (resourceInfos.size()>1) {
        ri = resourceInfos.get(resourceInfos.size()-2);
        logObj.setParentResourceInfo(ri);
      }
     
      // and set the grand parent - if applicable
      if (resourceInfos.size()>2) {
        ri = resourceInfos.get(resourceInfos.size()-3);
        logObj.setGrandParentResourceInfo(ri);
      }
     
      // and set the great grand parent - if applicable
      if (resourceInfos.size()>3) {
        ri = resourceInfos.get(resourceInfos.size()-4);
        logObj.setGreatGrandParentResourceInfo(ri);
      }
    }
   
    // fill the remaining fields
    logObj.setBusinessPath(businessPath_);
    logObj.setSourceClass(callingClass.getCanonicalName());
    logObj.setSimpleDuration(-1);
    logObj.setResourceAdminAction(actionType.equals(ActionType.admin)?true:false);
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
   
    //prepate the user properties, set them at once
    List<String> tmpUserProperties = new ArrayList<String>(12);
    for(Iterator<String> iterator = userProperties_.iterator(); iterator.hasNext();) {
      tmpUserProperties.add(identity.getUser().getPropertyOrIdentityEnvAttribute(iterator.next(), locale));
    }
    logObj.setUserProperties(tmpUserProperties);
   
    // and store it
    DB db = DBFactory.getInstanceForClosing();
View Full Code Here

        locked.setEnabled(!MetaInfoHelper.isLocked(item, ureq));
       
        //locked by
        String lockedDetails = "";
        if(lockedById != null) {
          Identity lockedIdentity = meta.getLockedByIdentity();
          String user = lockedIdentity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()) + " " +
            lockedIdentity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale());
          String date = "";
          if (meta.getLockedDate() != null) {
            date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ureq.getLocale()).format(meta.getLockedDate());
          }
          lockedDetails = getTranslator().translate("mf.locked.description", new String[]{user, date});
View Full Code Here

   */
  public void valueUnbound(HttpSessionBindingEvent be) {
    try {
      // the identity can be null if an loginscreen only session gets invalidated
      // (no user was authenticated yet but a tomcat session was created)
      Identity ident = identityEnvironment.getIdentity();
      signOffAndClear();
      if (Tracing.isDebugEnabled(UserSession.class)) {
        Tracing.logDebug("Closed UserSession: identity = " + (ident == null ? "n/a":ident.getName()), UserSession.class);
      }
      //we do not have a request in the null case (app. server triggered) and user not yet logged in
      //-> in this case we use the special empty activity logger
      if (ident == null) {
        ThreadLocalUserActivityLoggerInstaller.initEmptyUserActivityLogger();
      }
    } catch (Exception e) {
      // safely retrieve
      Identity ident = identityEnvironment.getIdentity();
      Tracing.logError("exception while session was unbound!", e, UserSession.class);
    }
    // called by tomcat's timer thread -> we need to close!! since the next unbound will be called from the same tomcat-thread
    finally {
      //o_clusterNOK: put into managed transaction wrapper
View Full Code Here

   * node2 catches the sign on event and invalidates the user on node2 "silently", e.g.
   * without firing an event.
   */
  private void signOffAndClearWithout(){
    Tracing.logDebug("signOffAndClearWithout() START", getClass());
    final Identity ident = identityEnvironment.getIdentity();
    //System.out.println("signOffAndClearWithout, ident="+ident+", hash="+this.hashCode()+", identityenv "+identityEnvironment.hashCode());
    // handle safely
    boolean isDebug = Tracing.isDebugEnabled(UserSession.class);
    if (isDebug) {
      Tracing.logDebug("UserSession:::logging off: " + sessionInfo, this.getClass());
    }

    /**
     * use not RunnableWithException, as exceptionHandlng is inside the run
     */
    Runnable run = new Runnable() {
      public void run() {
        Object obj = null;
        try {
         
          // do logging
          if (ident != null) {
            ThreadLocalUserActivityLogger.log(OlatLoggingAction.OLAT_LOGOUT, UserSession.class, CoreLoggingResourceable.wrap(ident));
          } else {
            //System.out.println("identity is null!!!!!!!!!!!!!!!!!!!!!");
          }
          // notify all variables in the store (the values) about the disposal
          // if
          // Disposable

          for (Iterator it_storevals = new ArrayList(store.values()).iterator(); it_storevals.hasNext();) {
            obj = it_storevals.next();
            if (obj instanceof Disposable) {
              // synchronous, since triggered by tomcat session timeout or user
              // click and
              // asynchronous, if kicked out by administrator.
              // we assume synchronous
              // !!!!
              // As a reminder, this .dispose() calls dispose on
              // DefaultController which is synchronized.
              // (Windows/WindowManagerImpl/WindowBackOfficeImpl/BaseChiefController/../
              // dispose()
              // !!!! was important for bug OLAT-3390

              ((Disposable) obj).dispose();
            }
          }
        } catch (Exception e) {

          String objtostr = "n/a";
          try {
            objtostr = obj.toString();
          } catch (Exception ee) {
            // ignore
          }
          Tracing.logError("exception in signOffAndClear: while disposing object:" + objtostr, e, UserSession.class);
        }
      }
    };

    ThreadLocalUserActivityLoggerInstaller.runWithUserActivityLogger(run, UserActivityLoggerImpl.newLoggerForValueUnbound(this));

    synchronized (authUserSessions) {  //o_clusterOK by:fj
      if(authUserSessions.remove(this)){
        //remove only from identityEnvironment if found in sessions.
        //see also SIDEEFFECT!! line in signOn(..)
        Identity previousSignedOn = identityEnvironment.getIdentity();
        if (previousSignedOn != null) {
          Tracing.logDebug("signOffAndClearWithout() removing from userNameToIdentity: "+previousSignedOn.getName().toLowerCase(), getClass());
          userNameToIdentity.remove(previousSignedOn.getName().toLowerCase());
        }
      }else{
        if (isDebug) {
          Tracing.logInfo("UserSession already removed! for ["+ident+"]", UserSession.class);
        }     
View Full Code Here

    //
    signOffAndClearWithout();
    // handle safely
    try {
      if (isAuthenticated()) {
        Identity identity = identityEnvironment.getIdentity();
        Tracing.logAudit("Logged off: " + sessionInfo, this.getClass());
        CoordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, false), ORES_USERSESSION);
        Tracing.logDebug("signOffAndClear() deregistering usersession from eventbus, id="+sessionInfo, getClass());
        CoordinatorManager.getCoordinator().getEventBus().deregisterFor(this, ORES_USERSESSION);
        registeredWithBus = false;
View Full Code Here

  public synchronized void signOn() {
    //   ^^^^^^^^^^^^ Added synchronized to be symmetric with sign off and to
    //                fix a possible dead-lock see also OLAT-3390
    Tracing.logDebug("signOn() START", getClass());
    if (isAuthenticated()) throw new AssertException("sign on: already signed on!");
    Identity identity = identityEnvironment.getIdentity();
    if (identity == null) throw new AssertException("identity is null in identityEnvironment!");
    if (sessionInfo == null) throw new AssertException("sessionInfo was null for identity " + identity);
    //String login = identity.getName();
    authenticated = true;

    if (sessionInfo.isWebDAV()) {
      // load user prefs
      guiPreferences = PreferencesFactory.getInstance().getPreferencesFor(identity, identityEnvironment.getRoles().isGuestOnly());

      synchronized (authUserSessions) {  //o_clusterOK by:se
        // we're only adding this webdav session to the authUserSessions - not to the userNameToIdentity.
        // userNameToIdentity is only needed for IM which can't do anything with a webdav session
        authUserSessions.add(this);
      }
      Tracing.logAudit("Logged on [via webdav]: " + sessionInfo.toString(), this.getClass());
      return;
    }
   
    Tracing.logDebug("signOn() authUsersNamesOtherNodes.contains "+identity.getName()+": "+authUsersNamesOtherNodes.contains(identity.getName()), getClass());
   
    UserSession invalidatedSession = null;
    synchronized (authUserSessions) {  //o_clusterOK by:fj
        // check if allready a session exist for this user
        if ( (userNameToIdentity.containsKey(identity.getName().toLowerCase()) || authUsersNamesOtherNodes.contains(identity.getName()) )
             && !sessionInfo.isWebDAV() && !this.getRoles().isGuestOnly()) {
            Tracing.logInfo("Loggin-process II: User has already a session => signOffAndClear existing session", this.getClass());
           
            invalidatedSession = getUserSessionFor(identity.getName().toLowerCase());
            //remove session to be invalidated
            //SIDEEFFECT!! to signOffAndClear
            //if invalidatedSession is removed from authUserSessions
            //signOffAndClear does not remove the identity.getName().toLowerCase() from the userNameToIdentity
            //
            authUserSessions.remove(invalidatedSession);
        }
        authUserSessions.add(this);
      // user can choose upercase letters in identity name, but this has no effect on the
      // database queries, the login form or the IM account. IM works only with lowercase
      // characters -> map stores values as such
      Tracing.logDebug("signOn() adding to userNameToIdentity: "+identity.getName().toLowerCase(), getClass());
      userNameToIdentity.put(identity.getName().toLowerCase(), identity);
    }
    // load user prefs
    guiPreferences = PreferencesFactory.getInstance().getPreferencesFor(identity, identityEnvironment.getRoles().isGuestOnly());

    if (!registeredWithBus) {
      // OLAT-3706
      CoordinatorManager.getCoordinator().getEventBus().registerFor(this, null, ORES_USERSESSION);
    }

    Tracing.logAudit("Logged on: " + sessionInfo.toString(), this.getClass());
    CoordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, true), ORES_USERSESSION);
   
   
    // THE FOLLOWING CHECK MUST BE PLACED HERE NOT TO PRODUCE A DEAD-LOCK WITH SIGNOFFANDCLEAR
    // check if a session from any browser was invalidated (IE has a cookie set per Browserinstance!!)
    if (invalidatedSession != null || authUsersNamesOtherNodes.contains(identity.getName())) {
      // put flag killed-existing-session into session-store to show info-message 'only one session for each user' on user-home screen
      this.putEntry(STORE_KEY_KILLED_EXISTING_SESSION, Boolean.TRUE);
      Tracing.logDebug("signOn() removing from authUsersNamesOtherNodes: "+identity.getName(), getClass());
      authUsersNamesOtherNodes.remove(identity.getName());
      //OLAT-3381 & OLAT-3382
      if(invalidatedSession != null) invalidatedSession.signOffAndClear();
    }
   
    Tracing.logDebug("signOn() END", getClass());
View Full Code Here

    sb.append("</td><td>");
   
    //locked
    if(metaInfo != null) {
      if(metaInfo.isLocked()) {
        Identity lockedBy = identityMap.get(metaInfo.getLockedBy());
        if(lockedBy == null) {
          lockedBy = metaInfo.getLockedByIdentity();
          if(lockedBy != null) {
            identityMap.put(lockedBy.getKey(), lockedBy);
          }
        }
       
        sb.append("<span class=\"b_small_icon b_briefcase_locked_file_icon\" ext:qtip=\"");
        if(lockedBy != null) {
          String firstName = lockedBy.getUser().getProperty(UserConstants.FIRSTNAME, translator.getLocale());
          String lastName = lockedBy.getUser().getProperty(UserConstants.LASTNAME, translator.getLocale());
          String date = "";
          if(metaInfo.getLockedDate() != null) {
            date = fc.getDateTimeFormat().format(metaInfo.getLockedDate());
          }
          sb.append(translator.translate("Locked", new String[]{firstName, lastName, date}));
View Full Code Here

      msg.contextPut("debug", Boolean.FALSE);     
    }
    msg.contextPut("listenerInfo", Formatter.escWithBR(componentListenerInfo).toString());     
    msg.contextPut("stacktrace", OLATRuntimeException.throwableToHtml(th));     
   
    Identity curIdent = ureq.getIdentity();
    msg.contextPut("username", curIdent == null? "n/a" : curIdent.getName());
    msg.contextPut("allowBackButton", Boolean.valueOf(allowBackButton));
    msg.contextPut("detailedmessage", detailedmessage);
    // Cluster NodeId + E-Nr
    msg.contextPut("errnum", "N" + CoordinatorManager.getCoordinator().getNodeId() + "-E"+ refNum);
    msg.contextPut("supportaddress", WebappHelper.getMailConfig("mailSupport"));
View Full Code Here

TOP

Related Classes of org.olat.core.id.Identity

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.