use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class UmaResourcesResource method findOrThrow.
private UmaResource findOrThrow(String id) {
try {
UmaResource existingResource = umaResourceService.getResourceById(id);
checkResourceNotNull(existingResource, UMA_RESOURCE);
return existingResource;
} catch (EntryPersistenceException e) {
throw new NotFoundException(getNotFoundError(UMA_RESOURCE));
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class NativePersistenceCacheProvider method putImpl.
private void putImpl(String key, Object object, Date creationDate, int expirationInSeconds) {
Calendar expirationDate = Calendar.getInstance();
expirationDate.setTime(creationDate);
expirationDate.add(Calendar.SECOND, expirationInSeconds);
String originalKey = key;
key = hashKey(key);
NativePersistenceCacheEntity entity = new NativePersistenceCacheEntity();
entity.setTtl(expirationInSeconds);
entity.setData(asString(object));
entity.setId(key);
entity.setDn(createDn(key));
entity.setCreationDate(creationDate);
entity.setExpirationDate(expirationDate.getTime());
entity.setDeletable(true);
try {
if (attemptUpdateBeforeInsert) {
entryManager.merge(entity);
} else {
if (!skipRemoveBeforePut) {
silentlyRemoveEntityIfExists(entity.getDn());
}
entryManager.persist(entity);
}
} catch (EntryPersistenceException e) {
if (e.getCause() instanceof DuplicateEntryException) {
// on duplicate, remove entry and try to persist again
try {
silentlyRemoveEntityIfExists(entity.getDn());
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
if (attemptUpdateBeforeInsert) {
try {
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
} catch (Exception e) {
// log as trace since it is perfectly valid that entry is removed by timer for example
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class SessionIdService method mergeWithRetry.
private void mergeWithRetry(final SessionId sessionId) {
final Pair<Date, Integer> expiration = expirationDate(sessionId.getCreationDate(), sessionId.getState());
sessionId.setExpirationDate(expiration.getFirst());
sessionId.setTtl(expiration.getSecond());
EntryPersistenceException lastException = null;
for (int i = 1; i <= MAX_MERGE_ATTEMPTS; i++) {
try {
if (isTrue(appConfiguration.getSessionIdPersistInCache())) {
cacheService.put(expiration.getSecond(), sessionId.getDn(), sessionId);
} else {
persistenceEntryManager.merge(sessionId);
}
localCacheService.put(DEFAULT_LOCAL_CACHE_EXPIRATION, sessionId.getDn(), sessionId);
externalEvent(new SessionEvent(SessionEventType.UPDATED, sessionId));
return;
} catch (EntryPersistenceException ex) {
lastException = ex;
if (ex.getCause() instanceof LDAPException) {
LDAPException parentEx = ((LDAPException) ex.getCause());
log.debug("LDAP exception resultCode: '{}'", parentEx.getResultCode().intValue());
if ((parentEx.getResultCode().intValue() == ResultCode.NO_SUCH_ATTRIBUTE_INT_VALUE) || (parentEx.getResultCode().intValue() == ResultCode.ATTRIBUTE_OR_VALUE_EXISTS_INT_VALUE)) {
log.warn("Session entry update attempt '{}' was unsuccessfull", i);
continue;
}
}
throw ex;
}
}
log.error("Session entry update attempt was unsuccessfull after '{}' attempts", MAX_MERGE_ATTEMPTS);
throw lastException;
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
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 io.jans.orm.exception.EntryPersistenceException 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