Search in sources :

Example 1 with CustomEntry

use of org.gluu.persist.model.base.CustomEntry in project oxAuth by GluuFederation.

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 = appConfiguration.getPersonCustomObjectClassList();
    if ((personCustomObjectClassList != null) && !personCustomObjectClassList.isEmpty()) {
        // Combine object classes from LDAP and configuration in one list
        Set<Object> customPersonCustomObjectClassList = new HashSet<Object>();
        customPersonCustomObjectClassList.add("gluuPerson");
        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("oxLastLogonTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttribute);
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastLogonTime of user '{}'", user.getUserId());
    }
}
Also used : CustomEntry(org.gluu.persist.model.base.CustomEntry) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 2 with CustomEntry

use of org.gluu.persist.model.base.CustomEntry in project oxAuth by GluuFederation.

the class ClientService method updateAccessTime.

public void updateAccessTime(Client client, boolean isUpdateLogonTime) {
    if (!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("oxLastAccessTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
    if (isUpdateLogonTime) {
        CustomAttribute customAttributeLastLogonTime = new CustomAttribute("oxLastLogonTime", nowDateString);
        customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
    }
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastAccessTime and oxLastLogonTime of client '{}'", clientDn);
    }
    removeFromCache(client);
}
Also used : CustomEntry(org.gluu.persist.model.base.CustomEntry) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Aggregations

EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)2 CustomAttribute (org.gluu.persist.model.base.CustomAttribute)2 CustomEntry (org.gluu.persist.model.base.CustomEntry)2