Search in sources :

Example 11 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class Tracing method assembleMsg.

private static String assembleMsg(String category, char prefix, long refNum, Class<?> callingClass, String userObj, String logMsg) {
    HttpServletRequest ureq = null;
    if (tld != null) {
        // 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 = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(ureq);
        if (usess != null) {
            identity = usess.getIdentity();
            remoteIp = ureq.getRemoteAddr();
            userAgent = ureq.getHeader("User-Agent");
            referer = ureq.getHeader("Referer");
        }
    }
    StringBuilder sb = new StringBuilder(256);
    if (Settings.isDebuging()) {
        // Short version for console output during debugging
        if (userObj != null) {
            sb.append(userObj).append(" ");
        }
    } else {
        sb.append(PREFIX);
        sb.append(category);
        sb.append(SEPARATOR);
        try {
            // Node-Id + Error number e.g. N1-E17
            sb.append("N");
            sb.append(WebappHelper.getNodeId());
            sb.append("-");
        } catch (Throwable th) {
            // ok
            sb.append(N_A);
        }
        sb.append(prefix);
        sb.append(refNum);
        sb.append(SEPARATOR);
        sb.append(callingClass == null ? N_A : callingClass.getPackage().getName());
        sb.append(SEPARATOR);
        sb.append(identity == null ? N_A : identity.getName());
        sb.append(SEPARATOR);
        sb.append(remoteIp == null ? N_A : remoteIp);
        sb.append(SEPARATOR);
        sb.append(referer == null ? N_A : referer);
        sb.append(SEPARATOR);
        sb.append(userAgent == null ? N_A : userAgent);
        sb.append(SEPARATOR);
        sb.append(userObj == null ? N_A : userObj);
        sb.append(SEPARATOR);
    }
    sb.append(logMsg == null ? N_A : logMsg.replaceAll("[\\r\\f]", "").replaceAll("[/^]M", "").replaceAll("[\\r\\n]", ""));
    return sb.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity)

Example 12 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class ContactList method getEmailsAsStrings.

/**
 * the returned ArrayList contains String Objects representing the e-mail
 * addresses added. The address of user which login is denied are excluded.
 *
 * @return
 */
public List<String> getEmailsAsStrings() {
    List<String> ret = new ArrayList<>(stringEmails.values());
    /*
		 * if priority is on institutional email get all the institutional emails
		 * first, if they are present, remove the identity from the hashtable. If
		 * they were not present, the user email is used in the next loop.
		 */
    List<Identity> copy = new ArrayList<>(identiEmails.values());
    if (emailPrioInstitutional) {
        for (Iterator<Identity> it = copy.iterator(); it.hasNext(); ) {
            Identity tmp = it.next();
            if (tmp.getStatus() == Identity.STATUS_LOGIN_DENIED) {
                continue;
            }
            String addEmail = tmp.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
            if (addEmail != null) {
                ret.add(addEmail);
                it.remove();
            }
        }
    }
    /*
		 * loops over the (remaining) identities, fetches the user email.
		 */
    for (Identity tmp : copy) {
        if (tmp.getStatus() == Identity.STATUS_LOGIN_DENIED) {
            continue;
        }
        String email = tmp.getUser().getProperty(UserConstants.EMAIL, null);
        if (StringHelper.containsNonWhitespace(email)) {
            ret.add(email);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 13 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class EMailCalloutCtrl method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (emailEl != null) {
        String mail = emailEl.getValue();
        if (MailHelper.isValidEmailAddress(mail)) {
            Identity identity = userManager.findUniqueIdentityByEmail(mail);
            if (identity == null) {
                identity = new EMailIdentity(mail, getLocale());
            }
            fireEvent(ureq, new SingleIdentityChosenEvent(identity));
        }
    }
}
Also used : SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) Identity(org.olat.core.id.Identity)

Example 14 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class DBPersistentLockManager method aquirePersistentLock.

/**
 * @see org.olat.core.util.locks.PersistentLockManager#aquirePersistentLock(org.olat.core.id.OLATResourceable,
 *      org.olat.core.id.Identity, java.lang.String)
 */
@Override
public LockResult aquirePersistentLock(OLATResourceable ores, Identity ident, String locksubkey) {
    // synchronisation is solved in the LockManager
    LockResult lres;
    PropertyManager pm = PropertyManager.getInstance();
    String derivedLockString = OresHelper.createStringRepresenting(ores, locksubkey);
    long aqTime;
    Identity lockOwner;
    boolean success;
    Property p;
    p = pm.findProperty(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString);
    if (p == null) {
        // no persistent lock acquired yet
        // save a property: cat = o_lock, key = derivedLockString, Longvalue = key
        // of identity acquiring the lock
        Property newp = pm.createPropertyInstance(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString, null, ident.getKey(), null, null);
        pm.saveProperty(newp);
        aqTime = System.currentTimeMillis();
        lockOwner = ident;
        success = true;
    } else {
        // already acquired, but check on reaquiring
        aqTime = p.getLastModified().getTime();
        Long lockOwnerKey = p.getLongValue();
        if (ident.getKey().equals(lockOwnerKey)) {
            // reaquire ok
            success = true;
        } else {
            // already locked by an other person
            success = false;
        }
        // FIXME:fj:c find a better way to retrieve information about the
        // lock-holder
        lockOwner = BaseSecurityManager.getInstance().loadIdentityByKey(lockOwnerKey);
    }
    LockEntry le = new LockEntry(derivedLockString, aqTime, lockOwner);
    lres = new LockResultImpl(success, le);
    return lres;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property)

Example 15 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MailController method getFrom.

private String getFrom() {
    StringBuilder sb = new StringBuilder();
    DBMailRecipient from = mail.getFrom();
    sb.append("<ul class='list-inline'><li>");
    if (from != null) {
        sb.append(getFullName(from));
        if (showMailAdresses()) {
            Identity fromIdentity = from.getRecipient();
            if (fromIdentity != null) {
                sb.append(" &lt;");
                sb.append(UserManager.getInstance().getUserDisplayEmail(fromIdentity, getLocale()));
                sb.append("&gt; ");
            }
        }
    }
    sb.append("</li></ul>");
    return sb.toString();
}
Also used : Identity(org.olat.core.id.Identity) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130