/** * Stores the given ticket in the storage service. * * @param ticket Ticket to store * @param <T> Type of ticket. */ protected <T extends Ticket> void store(final T ticket) { final String context = context(ticket.getClass()); try { final String sessionId = ticket.getSessionId(); final long expiry = ticket.getExpirationInstant().getMillis(); log.debug("Storing mapping of {} to {} in context {}", ticket, sessionId, context); if (!storageService.create(context, ticket.getId(), sessionId, expiry)) { throw new RuntimeException("Failed to store ticket " + ticket); } log.debug("Storing {} in context {}", ticket, sessionId); if (!storageService.create(sessionId, ticket.getId(), ticket, serializer(ticket.getClass()), expiry)) { throw new RuntimeException("Failed to store ticket " + ticket); } } catch (final IOException e) { throw new RuntimeException("Failed to store ticket " + ticket, e); } }
/** {@inheritDoc} */ @Override public void put(@Nonnull @NotEmpty final String artifact, @Nonnull @NotEmpty final String relyingPartyId, @Nonnull @NotEmpty final String issuerId, @Nonnull final SAMLObject samlMessage) throws IOException { if (artifact.length() > artifactStoreKeySize) { throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities"); } final SAMLArtifactMapEntry artifactEntry = getEntryFactory().newEntry(artifact, issuerId, relyingPartyId, samlMessage); if (log.isDebugEnabled()) { log.debug("Storing new artifact entry '{}' for relying party '{}', expiring after {} seconds", new Object[] {artifact, relyingPartyId, getArtifactLifetime() / 1000}); } final boolean success = getStorageService().create(STORAGE_CONTEXT, artifact, artifactEntry, (StorageSerializer) getEntryFactory(), System.currentTimeMillis() + getArtifactLifetime()); if (!success) { throw new IOException("A duplicate artifact was generated"); } }
/** {@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); } }
if (storageService.create(getId(), key, Integer.toString(counter), expiration)) { return true;
if (entry == null) { log.debug("Value '{}' was not a replay, adding to cache with expiration time {}", s, expires); storage.create(context, key, "x", expires); return true; } else {
/** * 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 (idStore.create(TransientIdParameters.CONTEXT, id, principalTokenId, expiration)) { return id; } else {
boolean success = false; do { success = sessionManager.getStorageService().create(getId(), key, builder.toString(), session.getExpirationInstant() + sessionManager.getSessionSlop()); if (!success) {
if (!storageService.create(sessionId, SESSION_MASTER_KEY, newSession, serializer, newSession.getCreationInstant() + sessionTimeout + sessionSlop)) { throw new SessionException("A duplicate session ID was generated, unable to create session");
/** * 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; } } }
/** * 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; }
/** * 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; }
serviceId, serviceKey); } else if (!storageService.create(serviceId, serviceKey, idpSession.getId() + ',', spSession.getExpirationInstant() + sessionSlop)) { log.debug("Secondary index record appeared, retrying as update");
boolean success = false; do { success = sessionManager.getStorageService().create(getId(), flowId, result, flow, result.getLastActivityInstant() + flow.getInactivityTimeout() + AuthenticationFlowDescriptor.STORAGE_EXPIRATION_OFFSET);