@Override public JsonPointer append(final JsonPointer pointer) { return jsonPointer.append(pointer); }
@Override public JsonPointer append(final JsonPointer pointer) { return jsonPointer.append(pointer); }
private static JsonPointer transformerPointer(@Nullable final String serviceName, @Nullable final Integer instance) { JsonPointer newPointer = JsonPointer.empty(); if (serviceName != null) { newPointer = newPointer.append(JsonPointer.of(serviceName)); } if (instance != null) { newPointer = newPointer.append(JsonPointer.of(instance.toString())); } return newPointer; }
private Certificate getClientCertificate(final String certificatePem) { final byte[] asciiBytes = certificatePem.getBytes(StandardCharsets.US_ASCII); try { return X509_CERTIFICATE_FACTORY.generateCertificate(new ByteArrayInputStream(asciiBytes)); } catch (final CertificateException e) { final JsonPointer errorLocation = Connection.JsonFields.CREDENTIALS.getPointer() .append(ClientCertificateCredentials.JsonFields.CLIENT_CERTIFICATE.getPointer()); throw badFormat(errorLocation, "CERTIFICATE", "DER") .build(); } }
private Certificate getClientCertificate(final String certificatePem) { final byte[] asciiBytes = certificatePem.getBytes(StandardCharsets.US_ASCII); try { return X509_CERTIFICATE_FACTORY.generateCertificate(new ByteArrayInputStream(asciiBytes)); } catch (final CertificateException e) { final JsonPointer errorLocation = Connection.JsonFields.CREDENTIALS.getPointer() .append(ClientCertificateCredentials.JsonFields.CLIENT_CERTIFICATE.getPointer()); throw badFormat(errorLocation, "CERTIFICATE", "DER") .build(); } }
private PrivateKey getClientPrivateKey(final String privateKeyPem) { final Matcher matcher = PRIVATE_KEY_REGEX.matcher(privateKeyPem); final Supplier<DittoRuntimeExceptionBuilder> errorSupplier = () -> { final JsonPointer errorLocation = Connection.JsonFields.CREDENTIALS.getPointer() .append(ClientCertificateCredentials.JsonFields.CLIENT_KEY.getPointer()); return badFormat(errorLocation, PRIVATE_KEY_LABEL, "PKCS #8") .description("Please format your client key as PEM-encoded unencrypted PKCS #8."); }; if (!matcher.matches()) { throw errorSupplier.get().build(); } else { final String content = matcher.group(1).replaceAll("\\s", ""); final byte[] bytes = decodeBase64(content); final KeySpec keySpec = new PKCS8EncodedKeySpec(bytes); try { return RSA_KEY_FACTORY.generatePrivate(keySpec); } catch (final InvalidKeySpecException e) { throw errorSupplier.get().cause(e).build(); } } }
private static JsonPointer createAbsoluteResourcePointer(final ResourceKey resourceKey) { return JsonFactory.newPointer(resourceKey.getResourceType()).append(resourceKey.getResourcePath()); }
private PrivateKey getClientPrivateKey(final String privateKeyPem) { final Matcher matcher = PRIVATE_KEY_REGEX.matcher(privateKeyPem); final Supplier<DittoRuntimeExceptionBuilder> errorSupplier = () -> { final JsonPointer errorLocation = Connection.JsonFields.CREDENTIALS.getPointer() .append(ClientCertificateCredentials.JsonFields.CLIENT_KEY.getPointer()); return badFormat(errorLocation, PRIVATE_KEY_LABEL, "PKCS #8") .description("Please format your client key as PEM-encoded unencrypted PKCS #8."); }; if (!matcher.matches()) { throw errorSupplier.get().build(); } else { final String content = matcher.group(1).replaceAll("\\s", ""); final byte[] bytes = decodeBase64(content); final KeySpec keySpec = new PKCS8EncodedKeySpec(bytes); try { return RSA_KEY_FACTORY.generatePrivate(keySpec); } catch (final InvalidKeySpecException e) { throw errorSupplier.get().cause(e).build(); } } }
return new NullPointerException(MessageFormat.format(msgPattern, levelCount)); }); builder.set(resourcePath.append(subPointer), pointerAndValue.value); });
/** * Converts a {@link ResourceKey} to an iterator of JSON keys by prepending the resource type to the resource path. * * @param resourceKey The resource key to convert. * @return The converted JSON key iterator. * @throws NullPointerException if {@code resourceKey} is {@code null}. */ static Iterator<JsonKey> getJsonKeyIterator(final ResourceKey resourceKey) { checkNotNull(resourceKey, "resource key to convert"); return JsonFactory.newPointer(resourceKey.getResourceType()).append(resourceKey.getResourcePath()).iterator(); }
public ThingQueryCommandResponseAssert withResourcePath(final CharSequence resourcePath, final JsonPointer furtherResourcePathSegments) { isNotNull(); final JsonPointer expectedResourcePath = JsonFactory.newPointer(resourcePath) .append(furtherResourcePathSegments); final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((Object) actualResourcePath) .overridingErrorMessage("Expected ThingQueryCommandResponse to have resource path \n<%s> but it" + " had\n<%s>", expectedResourcePath, actualResourcePath) .isEqualTo(expectedResourcePath); return myself; }
public ThingModifyCommandResponseAssert withResourcePath(final CharSequence resourcePath, final JsonPointer furtherResourcePathSegments) { isNotNull(); final JsonPointer expectedResourcePath = JsonFactory.newPointer(resourcePath) .append(furtherResourcePathSegments); final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((Object) actualResourcePath) .overridingErrorMessage("Expected ThingModifyCommandResponse to have resource path \n<%s> but it" + " had\n<%s>", expectedResourcePath, actualResourcePath) .isEqualTo(expectedResourcePath); return myself; }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? MessageCommand.INBOX_PREFIX : MessageCommand.OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonFactory.newPointer(JsonKey.of(box), JsonKey.of(MessageCommand.MESSAGES_PREFIX), JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId() .map(fId -> JsonFactory.newPointer(JsonKey.of(MessageCommand.FEATURES_PREFIX), JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? MessageCommand.INBOX_PREFIX : MessageCommand.OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonFactory.newPointer(JsonKey.of(box), JsonKey.of(MessageCommand.MESSAGES_PREFIX), JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId() .map(fId -> JsonFactory.newPointer(JsonKey.of(MessageCommand.FEATURES_PREFIX), JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
public ThingModifiedEventAssert withResourcePath(final CharSequence resourcePath, final JsonPointer furtherResourcePathSegments) { isNotNull(); final JsonPointer expectedResourcePath; if (null != furtherResourcePathSegments) { expectedResourcePath = JsonFactory.newPointer(resourcePath).append(furtherResourcePathSegments); } else { expectedResourcePath = JsonFactory.newPointer(resourcePath); } final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((CharSequence) actualResourcePath) .overridingErrorMessage("Expected ThingModifiedEvent to have resource path \n<%s> but it had\n<%s>", expectedResourcePath, actualResourcePath) .isEqualTo(expectedResourcePath); return myself; }
@Override public JsonObject buildJsonView( final ResourceKey resourceKey, final Iterable<JsonField> jsonFields, final AuthorizationContext authorizationContext, final Permissions permissions) { checkResourceKey(resourceKey); checkNotNull(jsonFields, "JSON fields"); checkPermissions(permissions); final Collection<String> authorizationSubjectIds = getAuthorizationSubjectIds(authorizationContext); final EffectedResources effectedResources = getGrantedAndRevokedSubResource( JsonFactory.newPointer(ROOT_RESOURCE), resourceKey.getResourceType(), authorizationSubjectIds, permissions); if (jsonFields instanceof JsonObject && ((JsonObject) jsonFields).isNull()) { return JsonFactory.nullObject(); } final List<PointerAndValue> flatPointers = new ArrayList<>(); jsonFields.forEach(jsonField -> collectFlatPointers(jsonField.getKey().asPointer(), jsonField, flatPointers)); final Set<JsonPointer> grantedResources = extractJsonPointers(effectedResources.getGrantedResources()); final Set<JsonPointer> revokedResources = extractJsonPointers(effectedResources.getRevokedResources()); final JsonPointer resourcePath = resourceKey.getResourcePath(); final List<PointerAndValue> prefixedPointers = flatPointers.stream() .map(pv -> new PointerAndValue(resourcePath.append(pv.pointer), pv.value)) .collect(Collectors.toList()); return filterEntries(prefixedPointers, grantedResources, revokedResources, resourcePath); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? INBOX_PREFIX : OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonPointer.empty() .addLeaf(JsonKey.of(box)) .addLeaf(JsonKey.of(MESSAGES_PREFIX)) .addLeaf(JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId().map(fId -> JsonPointer.empty() .addLeaf(JsonKey.of(FEATURES_PREFIX)) .addLeaf(JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? INBOX_PREFIX : OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonPointer.empty() .addLeaf(JsonKey.of(box)) .addLeaf(JsonKey.of(MESSAGES_PREFIX)) .addLeaf(JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId().map(fId -> JsonPointer.empty() .addLeaf(JsonKey.of(FEATURES_PREFIX)) .addLeaf(JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
messageCommandJson.getValue(messagePointer.append(MessageCommand.JsonFields.JSON_MESSAGE_PAYLOAD.getPointer())) .ifPresent(payloadBuilder::withValue);
messageCommandJson.getValue(messagePointer.append(MessageCommand.JsonFields.JSON_MESSAGE_PAYLOAD.getPointer())) .ifPresent(payloadBuilder::withValue);