private BufferResult(final int status, final String contentType, final Buffer payload) { super(status, payload, CacheDirective.noCacheDirective()); this.contentType = contentType; }
private BufferResult(final int status, final String contentType, final Buffer payload) { super(status, payload, CacheDirective.noCacheDirective()); this.contentType = contentType; }
/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Creates a new result for a status code and payload. * <p> * This method simply invokes {@link #from(int, Object, CacheDirective)} * with {@link CacheDirective#noCacheDirective()}. * * @param status The status code indicating the outcome of the request. * @param payload The payload to convey to the sender of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status, final T payload) { return new CredentialsResult<>(status, payload, CacheDirective.noCacheDirective()); }
/** * Creates a new result for a status code and payload. * <p> * This method simply invokes {@link #from(int, Object, CacheDirective)} * with {@link CacheDirective#noCacheDirective()}. * * @param status The status code indicating the outcome of the request. * @param payload The payload to convey to the sender of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status, final T payload) { return new CredentialsResult<>(status, payload, CacheDirective.noCacheDirective()); }
/** * Parses a cache directive. * * @param directive The directive to parse. * @return The cache directive or {@code null} if the directive cannot be parsed. */ public static CacheDirective from(final String directive) { if (directive == null) { return null; } else { Matcher matcher = PATTERN_MAX_AGE.matcher(directive); if (matcher.matches()) { return maxAgeDirective(Long.parseLong(matcher.group(1))); } else { matcher = PATTERN_NO_CACHE.matcher(directive); if (matcher.matches()) { return noCacheDirective(); } else { return null; } } } }
/** * Parses a cache directive. * * @param directive The directive to parse. * @return The cache directive or {@code null} if the directive cannot be parsed. */ public static CacheDirective from(final String directive) { if (directive == null) { return null; } else { Matcher matcher = PATTERN_MAX_AGE.matcher(directive); if (matcher.matches()) { return maxAgeDirective(Long.parseLong(matcher.group(1))); } else { matcher = PATTERN_NO_CACHE.matcher(directive); if (matcher.matches()) { return noCacheDirective(); } else { return null; } } } }
/** * {@inheritDoc} * <p> * The result object will include a <em>no-cache</em> directive. */ @Override public void get( final String tenantId, final String type, final String authId, final JsonObject clientContext, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(type); Objects.requireNonNull(authId); Objects.requireNonNull(resultHandler); final JsonObject data = getSingleCredentials(tenantId, authId, type, clientContext); if (data == null) { resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, data.copy(), CacheDirective.noCacheDirective()))); } }
@Override public void get(final String tenantId, final String type, final String authId, final JsonObject clientContext, final Span span, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { final JsonObject result = JsonObject.mapFrom(CredentialsObject.fromHashedPassword( authId, authId, PWD_HASH, CredentialsConstants.HASH_FUNCTION_SHA256, null, null, null)); resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(result), CacheDirective.noCacheDirective()))); }
/** * {@inheritDoc} * <p> * The result object will include a <em>no-cache</em> directive. */ @Override public void get( final String tenantId, final String type, final String authId, final JsonObject clientContext, final Span span, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(type); Objects.requireNonNull(authId); Objects.requireNonNull(resultHandler); final JsonObject data = getSingleCredentials(tenantId, authId, type, clientContext, span); if (data == null) { resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, data.copy(), CacheDirective.noCacheDirective()))); } }
/** * {@inheritDoc} * <p> * The result object will include a <em>no-cache</em> directive. */ @Override public void getAll(final String tenantId, final String deviceId, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(deviceId); Objects.requireNonNull(resultHandler); final Map<String, JsonArray> credentialsForTenant = credentials.get(tenantId); if (credentialsForTenant == null) { resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { final JsonArray matchingCredentials = new JsonArray(); // iterate over all credentials per auth-id in order to find credentials matching the given device for (final JsonArray credentialsForAuthId : credentialsForTenant.values()) { findCredentialsForDevice(credentialsForAuthId, deviceId, matchingCredentials); } if (matchingCredentials.isEmpty()) { resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { final JsonObject result = new JsonObject() .put(CredentialsConstants.FIELD_CREDENTIALS_TOTAL, matchingCredentials.size()) .put(CredentialsConstants.CREDENTIALS_ENDPOINT, matchingCredentials); resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, result, CacheDirective.noCacheDirective()))); } } }
@Override public void get(final String tenantId, final String type, final String authId, final JsonObject clientContext, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { final JsonObject result = JsonObject.mapFrom(CredentialsObject.fromHashedPassword( authId, authId, ClearTextPassword.encode(CredentialsConstants.HASH_FUNCTION_SHA256, null, "hono-secret"), CredentialsConstants.HASH_FUNCTION_SHA256, null, null, null)); resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(result), CacheDirective.noCacheDirective()))); }
.put(CredentialsConstants.CREDENTIALS_ENDPOINT, matchingCredentials); resultHandler.handle(Future.succeededFuture( CredentialsResult.from(HttpURLConnection.HTTP_OK, result, CacheDirective.noCacheDirective())));
return CacheDirective.maxAgeDirective(getResponseCacheDefaultTimeout()); } else { return CacheDirective.noCacheDirective();