/** {@inheritDoc} */ @Override @Nullable public SAMLArtifactMapEntry get(@Nonnull @NotEmpty final String artifact) throws IOException { log.debug("Attempting to retrieve entry for artifact: {}", artifact); if (artifact.length() > artifactStoreKeySize) { throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities"); } final StorageRecord record = getStorageService().read(STORAGE_CONTEXT, artifact); if (record == null) { log.debug("No unexpired entry found for artifact: {}", artifact); return null; } log.debug("Found valid entry for artifact: {}", artifact); return (SAMLArtifactMapEntry) record.getValue((StorageSerializer) getEntryFactory(), STORAGE_CONTEXT, artifact); }
/** {@inheritDoc} */ @Override @Nullable public Object read(@Nonnull final Object value) throws IOException { final StorageRecord record = read(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); if (record != null) { AnnotationSupport.setValue(value, record.getValue()); AnnotationSupport.setExpiration(value, record.getExpiration()); return value; } return null; }
/** {@inheritDoc} */ @Override public long incrementVersion() { return super.incrementVersion(); }
final int pos = record.getValue().indexOf(':'); if (pos <= 0) { throw new IOException("No class type found prefixed to record"); final String sessionClassName = record.getValue().substring(0, pos); record.getVersion(), getId(), key, record.getValue().substring(pos + 1), record.getExpiration());
return new Pair(); } else { Long exp = record.getExpiration(); if (exp != null && System.currentTimeMillis() >= exp) { log.debug("Read failed, key '{}' expired in context '{}'", key, context); if (version != null && record.getVersion() == version) { return new Pair(record.getVersion(), record);
/** * Get the counter for the given storage key. * * @param storageService the storage service * @param storageContext the storage context * @param storageKey the storage key * @return the counter for the given storage key * @throws IOException if a storage service error occurs * @throws NumberFormatException if the storage record value cannot be parsed as an integer */ @Nullable protected Long getStorageKeyCounter(@Nonnull final StorageService storageService, @Nonnull final String storageContext, @Nonnull final String storageKey) throws IOException { Constraint.isNotNull(storageService, "Storage service cannot be null"); Constraint.isNotNull(storageContext, "Storage context cannot be null"); Constraint.isNotNull(storageKey, "Storage key cannot be null"); final String counterStorageKey = getCounterStorageKey(storageKey); final StorageRecord storageRecord = storageService.read(storageContext, counterStorageKey); log.debug("Read storage record '{}' with context '{}' and key '{}'", storageRecord, storageContext, counterStorageKey); return (storageRecord == null) ? null : storageRecord.getVersion(); }
if (record != null) { Long exp = record.getExpiration(); if (exp == null || System.currentTimeMillis() < exp) { return false;
/** {@inheritDoc} */ @Override @Nullable public StorageRecord read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { SearchResult result = null; try { result = search(context, key).getResult(); } catch (LdapException e) { if (e.getResultCode() != ResultCode.NO_SUCH_OBJECT) { log.error("LDAP search operation failed", e); throw new IOException(e); } } StorageRecord record = null; if (result != null && result.size() > 0) { final LdapEntry entry = result.getEntry(); if (entry != null) { final LdapAttribute attr = entry.getAttribute(key); if (attr != null) { record = new StorageRecord(attr.getStringValue(), null); } } } return record; }
final StringBuilder writeBackSessionList = new StringBuilder(sessionList.getValue().length()); for (final String sessionId : sessionList.getValue().split(",")) { final IdPSession session = lookupBySessionId(sessionId); if (session != null) { final String writeBackValue = writeBackSessionList.toString(); if (writeBackValue.length() == 0) { storageService.deleteWithVersion(sessionList.getVersion(), serviceId, serviceKey); } else if (!writeBackValue.equals(sessionList.getValue())) { storageService.updateWithVersion(sessionList.getVersion(), serviceId, serviceKey, writeBackValue, sessionList.getExpiration());
/** * Get the counter for the given storage key. * * @param storageService the storage service * @param storageContext the storage context * @param storageKey the storage key * @return the counter for the given storage key * @throws IOException if a storage service error occurs * @throws NumberFormatException if the storage record value cannot be parsed as an integer */ @Nullable protected Long getStorageKeyCounter(@Nonnull final StorageService storageService, @Nonnull final String storageContext, @Nonnull final String storageKey) throws IOException { Constraint.isNotNull(storageService, "Storage service cannot be null"); Constraint.isNotNull(storageContext, "Storage context cannot be null"); Constraint.isNotNull(storageKey, "Storage key cannot be null"); final String counterStorageKey = getCounterStorageKey(storageKey); final StorageRecord storageRecord = storageService.read(storageContext, counterStorageKey); log.debug("Read storage record '{}' with context '{}' and key '{}'", storageRecord, storageContext, counterStorageKey); return (storageRecord == null) ? null : storageRecord.getVersion(); }
return true; } else { log.debug("Replay of value '{}' detected in cache, expires at {}", s, entry.getExpiration()); return false;
g.writeStringField("id", storageService.getId() + '/' + context +'/' + key); g.writeObjectFieldStart("attributes"); g.writeStringField("value", record.getValue()); g.writeNumberField("version", record.getVersion()); if (record.getExpiration() != null) { g.writeFieldName("expiration"); g.writeObject(new DateTime(record.getExpiration()));
storageService.read(sessionId, SESSION_MASTER_KEY); if (sessionRecord != null) { return sessionRecord.getValue(serializer, sessionId, SESSION_MASTER_KEY); } else { log.debug("Primary lookup failed for session ID {}", sessionId);
final int counter = Integer.parseInt(sr.getValue()); if (counter >= maxAttemptsLookupStrategy.apply(profileRequestContext)) { final long lastAttempt = sr.getExpiration() - Math.max(lockoutDuration, counterInterval); final long timeDifference = System.currentTimeMillis() - lastAttempt; if (timeDifference <= lockoutDuration) {
/** {@inheritDoc} */ @Override public Pair<Long, StorageRecord> read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Positive final long version) throws IOException { Constraint.isGreaterThan(0, version, "Version must be positive"); final StorageRecord record = read(context, key); if (record == null) { return new Pair<>(); } final Pair<Long, StorageRecord> result = new Pair<>(record.getVersion(), null); if (version != record.getVersion()) { // Only set the record if it's not the same as the version requested result.setSecond(record); } return result; }
final String recordValue = sessionList.getValue(); if (recordValue.contains(idpSession.getId() + ',')) { if (storageService.updateWithVersion(sessionList.getVersion(), serviceId, serviceKey, updated, sessionList.getExpiration()) == null) { log.debug("Secondary index record disappeared, nothing to do"); storageService.deleteWithVersion(sessionList.getVersion(), serviceId, serviceKey);
return null; final String sessionId = sessionRecord.getValue(); final StorageRecord<T> ticketRecord = storageService.read(sessionId, id); if (ticketRecord == null) { return null; ticket = ticketRecord.getValue(serializer(clazz), sessionId, id); } catch (final IOException e) { throw new RuntimeException("Error reading ticket.");
sr = storageService.read(getId(), key); if (sr != null) { counter = Integer.parseInt(sr.getValue()); lastAccess = sr.getExpiration() - Math.max(lockoutDuration, counterInterval);
if (!sessionList.getValue().contains(idpSession.getId() + ',')) { final String updated = sessionList.getValue() + idpSession.getId() + ','; if (storageService.updateWithVersion(sessionList.getVersion(), serviceId, serviceKey, updated, Math.max(sessionList.getExpiration(), spSession.getExpirationInstant() + sessionSlop)) == null) { log.debug("Secondary index record disappeared, retrying as insert");
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { final String context = getStorageContext(); final String key = getStorageKey(); try { 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("{} No storage record for context '{}' and key '{}'", getLogPrefix(), context, key); return; } final Map<String, Consent> consents = (Map<String, Consent>) storageRecord.getValue(getStorageSerializer(), context, key); getConsentContext().getPreviousConsents().putAll(consents); } catch (final IOException e) { log.error("{} Unable to read consent from storage", getLogPrefix(), e); } }