/** * Filters the currently valid secrets from the secrets on record. * <p> * A secret is considered valid if the current instant of time falls * into its validity period. * * @param <T> The type of the property that the candidate secrets are * projected on. * @param projection A function to apply to each candidate secret. This function * can be used to project the secret to one of its properties. * The function may return {@code null} in order to omit the * candidate secret from the result list. * @return The properties that the secrets have been projected on. * @throws NullPointerException if the function is {@code null}. */ @JsonIgnore public <T> List<T> getCandidateSecrets(final Function<JsonObject, T> projection) { Objects.requireNonNull(projection); return getSecrets().stream() .filter(obj -> { if (obj instanceof JsonObject) { return CredentialsObject.isInValidityPeriod((JsonObject) obj, Instant.now()); } else { return false; } }).map(obj -> (JsonObject) obj) .map(projection) .filter(obj -> obj != null) .collect(Collectors.toList()); }
/** * Filters the currently valid secrets from the secrets on record. * <p> * A secret is considered valid if the current instant of time falls * into its validity period. * * @param <T> The type of the property that the candidate secrets are * projected on. * @param projection A function to apply to each candidate secret. This function * can be used to project the secret to one of its properties. * The function may return {@code null} in order to omit the * candidate secret from the result list. * @return The properties that the secrets have been projected on. * @throws NullPointerException if the function is {@code null}. */ @JsonIgnore public <T> List<T> getCandidateSecrets(final Function<JsonObject, T> projection) { Objects.requireNonNull(projection); return getSecrets().stream() .filter(obj -> { if (obj instanceof JsonObject) { return CredentialsObject.isInValidityPeriod((JsonObject) obj, Instant.now()); } else { return false; } }).map(obj -> (JsonObject) obj) .map(projection) .filter(obj -> obj != null) .collect(Collectors.toList()); }
switch(type) { case CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD: checkSecrets(getSecrets(), secret -> { checkHashedPassword(secret); secretValidator.accept(type, secret); }); default: checkSecrets(getSecrets(), secret -> {});
switch(type) { case CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD: checkSecrets(getSecrets(), secret -> { checkHashedPassword(secret); secretValidator.accept(type, secret); }); default: checkSecrets(getSecrets(), secret -> {});
/** * Hashes clear text passwords contained in hashed-password credentials * provided by a client. * * @param credentials The credentials to hash the clear text passwords for. * @return A future containing the (updated) credentials. */ protected final Future<CredentialsObject> hashPlainPasswords(final CredentialsObject credentials) { final Future<CredentialsObject> result = Future.future(); if (CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD.equals(credentials.getType())) { getVertx().executeBlocking(blockingCodeHandler -> { log.debug("hashing password on vert.x worker thread [{}]", Thread.currentThread().getName()); credentials.getSecrets().forEach(secret -> hashPwdAndUpdateSecret((JsonObject) secret)); blockingCodeHandler.complete(credentials); }, result); } else { result.complete(credentials); } return result; }