Search in sources :

Example 41 with EntryPersistenceException

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));
    }
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) UmaResource(io.jans.as.model.uma.persistence.UmaResource)

Example 42 with EntryPersistenceException

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);
    }
}
Also used : Calendar(java.util.Calendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 43 with EntryPersistenceException

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;
}
Also used : SessionEvent(io.jans.as.server.service.external.session.SessionEvent) LDAPException(com.unboundid.ldap.sdk.LDAPException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date)

Example 44 with EntryPersistenceException

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);
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SessionId(io.jans.as.server.model.common.SessionId)

Example 45 with EntryPersistenceException

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

EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)61 SearchException (io.jans.orm.exception.operation.SearchException)33 AuthenticationException (io.jans.orm.exception.AuthenticationException)31 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)30 MappingException (io.jans.orm.exception.MappingException)30 Filter (io.jans.orm.search.filter.Filter)24 AttributeData (io.jans.orm.model.AttributeData)16 DateTimeParseException (java.time.format.DateTimeParseException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)13 ParsedKey (io.jans.orm.impl.model.ParsedKey)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)10 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)9 JsonObject (com.couchbase.client.java.document.json.JsonObject)8 ConnectionException (io.jans.orm.exception.operation.ConnectionException)8 ParseException (java.text.ParseException)8 DateTimeException (java.time.DateTimeException)7 List (java.util.List)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)6 EntryData (io.jans.orm.model.EntryData)6