use of org.gluu.persist.exception.EntryPersistenceException 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);
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class CookieService method removeOutdatedCurrentSessions.
private void removeOutdatedCurrentSessions(Set<String> currentSessions, SessionId session) {
if (session != null) {
final String oldSessionId = session.getSessionAttributes().get(SessionId.OLD_SESSION_ID_ATTR_KEY);
if (StringUtils.isNotBlank(oldSessionId)) {
currentSessions.remove(oldSessionId);
}
}
if (currentSessions.isEmpty()) {
return;
}
// avoid cycle dependency
SessionIdService sessionIdService = CdiUtil.bean(SessionIdService.class);
Set<String> toRemove = Sets.newHashSet();
for (String sessionId : currentSessions) {
SessionId sessionIdObject = null;
try {
sessionIdObject = sessionIdService.getSessionId(sessionId, true);
} catch (EntryPersistenceException e) {
// ignore - valid case if session is outdated
}
if (sessionIdObject == null) {
toRemove.add(sessionId);
}
}
currentSessions.removeAll(toRemove);
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class UserGroupService method isUserInGroupOrMember.
public boolean isUserInGroupOrMember(String groupDn, String personDn) {
Filter ownerFilter = Filter.createEqualityFilter("owner", personDn);
Filter memberFilter = Filter.createEqualityFilter("member", personDn);
Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
boolean isMemberOrOwner = false;
try {
isMemberOrOwner = ldapEntryManager.findEntries(groupDn, UserGroup.class, searchFilter, 1).size() > 0;
} catch (EntryPersistenceException ex) {
log.error("Failed to determine if person '{}' memeber or owner of group '{}'", personDn, groupDn, ex);
}
return isMemberOrOwner;
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class StatService method setupCurrentEntry.
private void setupCurrentEntry(Date now) {
final String month = PERIOD_DATE_FORMAT.format(now);
// jansId=<id>,ou=yyyyMM,ou=stat,o=gluu
String dn = String.format("jansId=%s,%s", nodeId, monthlyDn);
if (currentEntry != null && month.equals(currentEntry.getStat().getMonth())) {
return;
}
try {
StatEntry entryFromPersistence = entryManager.find(StatEntry.class, dn);
if (entryFromPersistence != null && month.equals(entryFromPersistence.getStat().getMonth())) {
hll = HLL.fromBytes(Base64.getDecoder().decode(entryFromPersistence.getUserHllData()));
tokenCounters = new ConcurrentHashMap<>(entryFromPersistence.getStat().getTokenCountPerGrantType());
currentEntry = entryFromPersistence;
log.trace("Stat entry loaded.");
return;
}
} catch (EntryPersistenceException e) {
log.trace("Stat entry is not found in persistence.");
}
if (currentEntry == null) {
log.trace("Creating stat entry ...");
hll = newHll();
tokenCounters = new ConcurrentHashMap<>();
currentEntry = new StatEntry();
currentEntry.setId(nodeId);
currentEntry.setDn(dn);
currentEntry.setUserHllData(Base64.getEncoder().encodeToString(hll.toBytes()));
currentEntry.getStat().setMonth(PERIOD_DATE_FORMAT.format(new Date()));
entryManager.persist(currentEntry);
log.trace("Created stat entry. nodeId:" + nodeId);
}
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class StatService method createBranch.
public void createBranch(String branchDn, String ou) {
try {
SimpleBranch branch = new SimpleBranch();
branch.setOrganizationalUnitName(ou);
branch.setDn(branchDn);
entryManager.persist(branch);
} catch (EntryPersistenceException ex) {
// Check if another process added this branch already
if (!entryManager.contains(branchDn, SimpleBranch.class)) {
throw ex;
}
}
}
Aggregations