if (storageService.update(getId(), key, Integer.toString(counter), expiration)) { return true;
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { try { final String value = Long.toString(System.currentTimeMillis()); final String context = getStorageContext(); final String key = getStorageKey(); final StorageRecord storageRecord = getStorageService().read(context, key); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, context, key); if (storageRecord == null) { log.debug("{} Creating counter with value '{}'", getLogPrefix(), value); getStorageService().create(context, key, value, null); } else { log.debug("{} Updating counter with value '{}'", getLogPrefix(), value); getStorageService().update(context, key, value, null); } } catch (final IOException e) { log.debug("{} Unable to update counter", getLogPrefix(), e); } }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { try { final String value = Long.toString(System.currentTimeMillis()); final String context = getStorageContext(); final String key = getStorageKey(); final StorageRecord storageRecord = getStorageService().read(context, key); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, context, key); if (storageRecord == null) { log.debug("{} Creating counter with value '{}'", getLogPrefix(), value); getStorageService().create(context, key, value, null); } else { log.debug("{} Updating counter with value '{}'", getLogPrefix(), value); getStorageService().update(context, key, value, null); } } catch (final IOException e) { log.debug("{} Unable to update counter", getLogPrefix(), e); } }
/** * Store a profile interceptor result. * * @param result the profile interceptor result to be stored * @throws IOException if an error occurs */ protected void store(@Nonnull final ProfileInterceptorResult result) throws IOException { final String context = result.getStorageContext(); final String key = result.getStorageKey(); final String value = result.getStorageValue(); final Long expiration = result.getStorageExpiration(); // Create / update loop until we succeed or exhaust attempts. int attempts = 10; boolean success = false; do { success = storageService.create(context, key, value, expiration); if (!success) { // The record already exists, so we need to overwrite via an update. success = storageService.update(context, key, value, expiration); } } while (!success && attempts-- > 0); if (!success) { log.error("{} Exhausted retry attempts storing result '{}'", getLogPrefix(), result); } }
if (!success) { success = sessionManager.getStorageService().update(getId(), key, builder.toString(), session.getExpirationInstant() + sessionManager.getSessionSlop());
/** * Remove a storage key from the index storage record. * * @param keyToRemove storage key to remove from the index storage record * @return true if key removal succeeded, false otherwise * @throws IOException if an error occurs writing to the storage service */ protected boolean removeKeyFromStorageIndex(@Nonnull final String keyToRemove) throws IOException { final StorageRecord storageRecord = getStorageService().read(getStorageContext(), getStorageIndexKey()); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, getStorageContext(), getStorageIndexKey()); if (storageRecord == null) { log.debug("{} No storage record exists with context '{}' and key '{}', nothing to do", getLogPrefix(), getStorageContext(), getStorageIndexKey()); return false; } else { final LinkedHashSet<String> keys = new LinkedHashSet<>(getStorageKeysFromIndex()); if (keys.remove(keyToRemove)) { log.debug("{} Updating storage index by removing key '{}'", getLogPrefix(), keyToRemove); return getStorageService().update(getStorageContext(), storageIndexKey, keys, storageKeysSerializer, null); } else { log.debug("{} Storage key '{}' not indexed, nothing to do", getLogPrefix(), keyToRemove); return false; } } }
/** * Remove a storage key from the index storage record. * * @param keyToRemove storage key to remove from the index storage record * @return true if key removal succeeded, false otherwise * @throws IOException if an error occurs writing to the storage service */ protected boolean removeKeyFromStorageIndex(@Nonnull final String keyToRemove) throws IOException { final StorageRecord storageRecord = getStorageService().read(getStorageContext(), getStorageIndexKey()); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, getStorageContext(), getStorageIndexKey()); if (storageRecord == null) { log.debug("{} No storage record exists with context '{}' and key '{}', nothing to do", getLogPrefix(), getStorageContext(), getStorageIndexKey()); return false; } else { final LinkedHashSet<String> keys = new LinkedHashSet<>(getStorageKeysFromIndex()); if (keys.remove(keyToRemove)) { log.debug("{} Updating storage index by removing key '{}'", getLogPrefix(), keyToRemove); return getStorageService().update(getStorageContext(), storageIndexKey, keys, storageKeysSerializer, null); } else { log.debug("{} Storage key '{}' not indexed, nothing to do", getLogPrefix(), keyToRemove); return false; } } }
/** * Store a profile interceptor result. * * @param result the profile interceptor result to be stored * @throws IOException if an error occurs * @return boolean whether the record was stored successfully */ protected boolean storeResult(@Nonnull final ProfileInterceptorResult result) throws IOException { final String context = result.getStorageContext(); final String key = result.getStorageKey(); final String value = result.getStorageValue(); final Long expiration = result.getStorageExpiration(); // Create / update loop until we succeed or exhaust attempts. int attempts = 10; boolean success = false; do { success = getStorageService().create(context, key, value, expiration); if (!success) { // The record already exists, so we need to overwrite via an update. success = getStorageService().update(context, key, value, expiration); } } while (!success && attempts-- > 0); if (!success) { log.error("{} Exhausted retry attempts storing result '{}'", getLogPrefix(), result); } return success; }
/** * Add a storage key to the index storage record. * * @param keyToAdd storage key to add to the index storage record * @return true if key addition succeeded, false otherwise * @throws IOException if an error occurs writing to the storage service */ protected boolean addKeyToStorageIndex(@Nonnull final String keyToAdd) throws IOException { final StorageRecord storageRecord = getStorageService().read(getStorageContext(), getStorageIndexKey()); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, getStorageContext(), getStorageIndexKey()); if (storageRecord == null) { log.debug("{} Creating storage index with key '{}'", getLogPrefix(), keyToAdd); return getStorageService().create(getStorageContext(), getStorageIndexKey(), Collections.singletonList(keyToAdd), storageKeysSerializer, null); } else { final LinkedHashSet<String> keys = new LinkedHashSet<>(getStorageKeysFromIndex()); if (keys.add(keyToAdd)) { log.debug("{} Updating storage index by adding key '{}'", getLogPrefix(), keyToAdd); return getStorageService().update(getStorageContext(), getStorageIndexKey(), keys, storageKeysSerializer, null); } else { log.debug("{} Storage key '{}' already indexed, nothing to do", getLogPrefix(), keyToAdd); return false; } } }
/** * Store a profile interceptor result. * * @param result the profile interceptor result to be stored * @throws IOException if an error occurs * @return boolean whether the record was stored successfully */ protected boolean storeResult(@Nonnull final ProfileInterceptorResult result) throws IOException { final String context = result.getStorageContext(); final String key = result.getStorageKey(); final String value = result.getStorageValue(); final Long expiration = result.getStorageExpiration(); // Create / update loop until we succeed or exhaust attempts. int attempts = 10; boolean success = false; do { success = getStorageService().create(context, key, value, expiration); if (!success) { // The record already exists, so we need to overwrite via an update. success = getStorageService().update(context, key, value, expiration); } } while (!success && attempts-- > 0); if (!success) { log.error("{} Exhausted retry attempts storing result '{}'", getLogPrefix(), result); } return success; }
/** * Add a storage key to the index storage record. * * @param keyToAdd storage key to add to the index storage record * @return true if key addition succeeded, false otherwise * @throws IOException if an error occurs writing to the storage service */ protected boolean addKeyToStorageIndex(@Nonnull final String keyToAdd) throws IOException { final StorageRecord storageRecord = getStorageService().read(getStorageContext(), getStorageIndexKey()); log.debug("{} Read storage record '{}' with context '{}' and key '{}'", getLogPrefix(), storageRecord, getStorageContext(), getStorageIndexKey()); if (storageRecord == null) { log.debug("{} Creating storage index with key '{}'", getLogPrefix(), keyToAdd); return getStorageService().create(getStorageContext(), getStorageIndexKey(), Collections.singletonList(keyToAdd), storageKeysSerializer, null); } else { final LinkedHashSet<String> keys = new LinkedHashSet<>(getStorageKeysFromIndex()); if (keys.add(keyToAdd)) { log.debug("{} Updating storage index by adding key '{}'", getLogPrefix(), keyToAdd); return getStorageService().update(getStorageContext(), getStorageIndexKey(), keys, storageKeysSerializer, null); } else { log.debug("{} Storage key '{}' already indexed, nothing to do", getLogPrefix(), keyToAdd); return false; } } }
if (!success) { success = sessionManager.getStorageService().update(getId(), flowId, result, flow, result.getLastActivityInstant() + flow.getInactivityTimeout() + AuthenticationFlowDescriptor.STORAGE_EXPIRATION_OFFSET);