use of org.eclipse.hono.util.RegistryManagementConstants in project hono by eclipse.
the class IdentityTemplate method checkValidity.
/**
* Checks if the template is valid.
* <p>
* The following placeholders are supported.
* <ul>
* <li>{@value RegistryManagementConstants#PLACEHOLDER_SUBJECT_DN} for <em>Subject Distinguished Name (DN)</em></li>
* <li>{@value RegistryManagementConstants#PLACEHOLDER_SUBJECT_CN} for <em>Common Name (CN)</em></li>
* <li>{@value RegistryManagementConstants#PLACEHOLDER_SUBJECT_OU} for <em>Organizational Unit Name (OU)</em></li>
* <li>{@value RegistryManagementConstants#PLACEHOLDER_SUBJECT_O} for <em>Organization Name (O)</em></li>
* </ul>
*
* @param template The identity template.
* @throws NullPointerException if template is {@code null}.
* @throws IllegalArgumentException if the template does not contain any placeholders
* or contains any unsupported placeholders.
*/
public static void checkValidity(final String template) {
Objects.requireNonNull(template, "template must not be null");
final Matcher matcher = PLACEHOLDER_PATTERN.matcher(template);
final List<String> placeholders = new ArrayList<>();
while (matcher.find()) {
placeholders.add(String.format("{{%s}}", matcher.group(1)));
}
if (placeholders.isEmpty()) {
throw new IllegalArgumentException(String.format("template [%s] must contain at least one placeholder", template));
}
final List<String> unsupportedPlaceHolders = placeholders.stream().filter(placeholder -> !SUPPORTED_PLACE_HOLDERS.contains(placeholder)).collect(Collectors.toList());
if (!unsupportedPlaceHolders.isEmpty()) {
throw new IllegalArgumentException(String.format("template [%s] contains unsupported placeholders %s", template, unsupportedPlaceHolders));
}
}
use of org.eclipse.hono.util.RegistryManagementConstants in project hono by eclipse.
the class AbstractRegistrationService method getSupportedGatewaysForDevice.
/**
* Gets the list of gateways that may act on behalf of a given device.
* <p>
* To compile this list of gateways, this default implementation gets the list of gateways from the value of the
* {@link RegistryManagementConstants#FIELD_VIA} property in the device's registration information and resolves
* the members of the groups that are in the {@link RegistryManagementConstants#FIELD_VIA_GROUPS} property of the device.
* <p>
* Subclasses may override this method to provide a different means to determine the supported gateways.
*
* @param tenantId The tenant id.
* @param deviceId The device id.
* @param registrationInfo The device's registration information.
* @param span The active OpenTracing span for this operation. It is not to be closed in this method! An
* implementation should log (error) events on this span and it may set tags and use this span as the
* parent for any spans created in this method.
* @return A future indicating the outcome of the operation.
* <p>
* The future will succeed with the list of gateways as a JSON array of Strings (never {@code null})
* or it will fail with a {@link ServiceInvocationException} indicating the cause of the failure.
*/
protected Future<JsonArray> getSupportedGatewaysForDevice(final String tenantId, final String deviceId, final JsonObject registrationInfo, final Span span) {
final JsonArray via = convertObjectToJsonArray(registrationInfo.getValue(RegistryManagementConstants.FIELD_VIA));
final JsonArray viaGroups = convertObjectToJsonArray(registrationInfo.getValue(RegistryManagementConstants.FIELD_VIA_GROUPS));
final Future<JsonArray> resultFuture;
if (viaGroups.isEmpty()) {
resultFuture = Future.succeededFuture(via);
} else {
resultFuture = resolveGroupMembers(tenantId, viaGroups, span).compose(groupMembers -> {
for (final Object gateway : groupMembers) {
if (!via.contains(gateway)) {
via.add(gateway);
}
}
return Future.succeededFuture(via);
}).recover(thr -> {
LOG.debug("failed to resolve group members", thr);
TracingHelper.logError(span, "failed to resolve group members: " + thr.getMessage());
return Future.failedFuture(thr);
});
}
return resultFuture;
}
Aggregations