Search in sources :

Example 1 with CustomEntry

use of io.jans.orm.model.base.CustomEntry in project jans by JanssenProject.

the class ClientService method updateAccessTime.

public void updateAccessTime(Client client, boolean isUpdateLogonTime) {
    if (isFalse(appConfiguration.getUpdateClientAccessTime())) {
        return;
    }
    String clientDn = client.getDn();
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(clientDn);
    customEntry.setCustomObjectClasses(CLIENT_OBJECT_CLASSES);
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttributeLastAccessTime = new CustomAttribute("jansLastAccessTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
    if (isUpdateLogonTime) {
        CustomAttribute customAttributeLastLogonTime = new CustomAttribute("jansLastLogonTime", nowDateString);
        customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
    }
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update jansLastAccessTime and jansLastLogonTime of client '{}'", clientDn);
        log.trace("Failed to update user:", epe);
    }
    removeFromCache(client);
}
Also used : CustomEntry(io.jans.orm.model.base.CustomEntry) CustomAttribute(io.jans.orm.model.base.CustomAttribute) GregorianCalendar(java.util.GregorianCalendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date)

Example 2 with CustomEntry

use of io.jans.orm.model.base.CustomEntry in project jans by JanssenProject.

the class CouchbaseUpdateAttributeSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    String uid = "sample_user_" + System.currentTimeMillis();
    String dn = String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis());
    SimpleUser newUser = new SimpleUser();
    newUser.setDn(dn);
    newUser.setUserId(uid);
    newUser.setUserPassword("test");
    couchbaseEntryManager.persist(newUser);
    SimpleUser user = couchbaseEntryManager.find(SimpleUser.class, dn);
    LOG.info("Found user '{}'", user);
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(user.getDn());
    customEntry.setCustomObjectClasses(new String[] { "jansPerson" });
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    String nowDateString = couchbaseEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttribute = new CustomAttribute("jansLastLogonTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttribute);
    couchbaseEntryManager.merge(customEntry);
    SimpleUser userAfterUpdate = couchbaseEntryManager.find(SimpleUser.class, dn);
    LOG.info("Found user after update '{}'", userAfterUpdate);
}
Also used : SimpleUser(io.jans.orm.couchbase.model.SimpleUser) CustomEntry(io.jans.orm.model.base.CustomEntry) CustomAttribute(io.jans.orm.model.base.CustomAttribute) GregorianCalendar(java.util.GregorianCalendar) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) Date(java.util.Date)

Example 3 with CustomEntry

use of io.jans.orm.model.base.CustomEntry in project jans by JanssenProject.

the class AuthenticationService method updateLastLogonUserTime.

private void updateLastLogonUserTime(User user) {
    if (!appConfiguration.getUpdateUserLastLogonTime()) {
        return;
    }
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(user.getDn());
    List<String> personCustomObjectClassList = userService.getPersonCustomObjectClassList();
    if ((personCustomObjectClassList != null) && !personCustomObjectClassList.isEmpty()) {
        // Combine object classes from LDAP and configuration in one list
        Set<Object> customPersonCustomObjectClassList = new HashSet<Object>();
        customPersonCustomObjectClassList.add(AttributeConstants.JANS_PERSON);
        customPersonCustomObjectClassList.addAll(personCustomObjectClassList);
        if (user.getCustomObjectClasses() != null) {
            customPersonCustomObjectClassList.addAll(Arrays.asList(user.getCustomObjectClasses()));
        }
        customEntry.setCustomObjectClasses(customPersonCustomObjectClassList.toArray(new String[customPersonCustomObjectClassList.size()]));
    } else {
        customEntry.setCustomObjectClasses(UserService.USER_OBJECT_CLASSES);
    }
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttribute = new CustomAttribute("jansLastLogonTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttribute);
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update jansLastLogonTime of user '{}'", user.getUserId());
        log.trace("Failed to update user:", epe);
    }
}
Also used : CustomEntry(io.jans.orm.model.base.CustomEntry) CustomAttribute(io.jans.orm.model.base.CustomAttribute) GregorianCalendar(java.util.GregorianCalendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

CustomAttribute (io.jans.orm.model.base.CustomAttribute)3 CustomEntry (io.jans.orm.model.base.CustomEntry)3 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)1 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)1 HashSet (java.util.HashSet)1