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);
}
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);
}
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);
}
}
Aggregations