* The code consumes data until it receives any input on its console (which finishes it and closes vertx).
*/
+@SuppressFBWarnings(
+ value = { "HARD_CODE_PASSWORD", "PREDICTABLE_RANDOM" },
+ justification = """
+ We use the default passwords of the Hono Sandbox installation throughout this class
+ for ease of use. The passwords are publicly documented and do not affect any
+ private installations of Hono.
+ The values returned by the Random are only used as arbitrary values in example message
+ payload.
+ """)
public class HonoExampleApplicationBase {
public static final String HONO_CLIENT_USER = System.getProperty("username", "consumer@HONO");
@@ -346,9 +357,6 @@ private void handlePermanentlyConnectedCommandReadinessNotification(
*/
private void sendCommand(final TimeUntilDisconnectNotification notification) {
- final long commandTimeout = calculateCommandTimeout(notification);
- // TODO set request timeout
-
if (SEND_ONE_WAY_COMMANDS) {
sendOneWayCommandToAdapter(notification.getTenantId(), notification.getDeviceId(), notification);
} else {
@@ -363,14 +371,14 @@ private void sendCommand(final TimeUntilDisconnectNotification notification) {
* @param notification The notification that was received for the device.
* @return The timeout (milliseconds) to be set for the command.
*/
- private long calculateCommandTimeout(final TimeUntilDisconnectNotification notification) {
+ private Duration calculateCommandTimeout(final TimeUntilDisconnectNotification notification) {
if (notification.getTtd() == -1) {
// let the command expire directly before the next periodic timer is started
- return HonoExampleConstants.COMMAND_INTERVAL_FOR_DEVICES_CONNECTED_WITH_UNLIMITED_EXPIRY * 1000L;
+ return Duration.ofMillis(HonoExampleConstants.COMMAND_INTERVAL_FOR_DEVICES_CONNECTED_WITH_UNLIMITED_EXPIRY * 1000L);
} else {
// let the command expire when the notification expires
- return notification.getMillisecondsUntilExpiry();
+ return Duration.ofMillis(notification.getMillisecondsUntilExpiry());
}
}
@@ -393,7 +401,7 @@ private void cancelPeriodicCommandSender(final TimeUntilDisconnectNotification n
}
private boolean isPeriodicCommandSenderActiveForDevice(final TimeUntilDisconnectNotification notification) {
- return (periodicCommandSenderTimerCancelerMap.containsKey(notification.getTenantAndDeviceId()));
+ return periodicCommandSenderTimerCancelerMap.containsKey(notification.getTenantAndDeviceId());
}
/**
@@ -404,15 +412,19 @@ private boolean isPeriodicCommandSenderActiveForDevice(final TimeUntilDisconnect
* If the contained ttd is set to -1, the commandClient will remain open for further commands to be sent.
* @param ttdNotification The ttd notification that was received for the device.
*/
- private void sendCommandToAdapter(final String tenantId, final String deviceId,
+ private void sendCommandToAdapter(
+ final String tenantId,
+ final String deviceId,
final TimeUntilDisconnectNotification ttdNotification) {
+
+ final Duration commandTimeout = calculateCommandTimeout(ttdNotification);
final Buffer commandBuffer = buildCommandPayload();
final String command = "setBrightness";
if (LOG.isDebugEnabled()) {
LOG.debug("Sending command [{}] to [{}].", command, ttdNotification.getTenantAndDeviceId());
}
- client.sendCommand(tenantId, deviceId, command, commandBuffer, "application/json")
+ client.sendCommand(tenantId, deviceId, command, commandBuffer, "application/json", null, commandTimeout, null)
.onSuccess(result -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Successfully sent command payload: [{}].", commandBuffer.toString());
diff --git a/examples/protocol-gateway-example/scripts/create_hono_device.sh b/examples/protocol-gateway-example/scripts/create_hono_device.sh
index 111a4a2dcf..54d233fcaf 100755
--- a/examples/protocol-gateway-example/scripts/create_hono_device.sh
+++ b/examples/protocol-gateway-example/scripts/create_hono_device.sh
@@ -15,12 +15,15 @@
# A simple shell script to get IP addresses for hono-service-device-registry-ext, hono-dispatch-router-ext and hono-adapter-amqp and creates a device id and password
# prior: setup hono in kubernetes namespace "hono"
-export REGISTRY_IP=$(kubectl -n hono get service hono-service-device-registry-ext --output='jsonpath={.status.loadBalancer.ingress[0].ip}')
+REGISTRY_IP=$(kubectl -n hono get service hono-service-device-registry-ext --output='jsonpath={.status.loadBalancer.ingress[0].ip}')
echo "REGISTRY_IP=${REGISTRY_IP}"
-export AMQP_NETWORK_IP=$(kubectl -n hono get service hono-dispatch-router-ext --output='jsonpath={.status.loadBalancer.ingress[0].ip}')
+export REGISTRY_IP
+AMQP_NETWORK_IP=$(kubectl -n hono get service hono-dispatch-router-ext --output='jsonpath={.status.loadBalancer.ingress[0].ip}')
echo "AMQP_NETWORK_IP=${AMQP_NETWORK_IP}"
-export AMQP_ADAPTER_PORT=$(kubectl -n hono get service hono-adapter-amqp --output='jsonpath={.status.loadBalancer.ingress[0].port}')
+export AMQP_NETWORK_IP
+AMQP_ADAPTER_PORT=$(kubectl -n hono get service hono-adapter-amqp --output='jsonpath={.status.loadBalancer.ingress[0].port}')
echo "AMQP_ADAPTER_IP=${AMQP_ADAPTER_IP}"
+export AMQP_ADAPTER_PORT
# Get example tenant or
export MY_TENANT="DEFAULT_TENANT"
@@ -30,14 +33,15 @@ export MY_TENANT="DEFAULT_TENANT"
echo "MY_TENANT=\"${MY_TENANT}\""
# register new device
-export MY_DEVICE=$(curl -X POST http://$REGISTRY_IP:28080/v1/devices/$MY_TENANT 2>/dev/null | jq -r .id)
+MY_DEVICE=$(curl -X POST "http://${REGISTRY_IP}:28080/v1/devices/${MY_TENANT}" 2>/dev/null | jq -r .id)
echo "MY_DEVICE=\"${MY_DEVICE}\""
+export MY_DEVICE
# set credential secret for device
export MY_PWD="dummyDevicePassword"
echo "MY_PWD=\"${MY_PWD}\""
-curl -i -X PUT -H "content-type: application/json" --data-binary '[{
- "type": "hashed-password",
- "auth-id": "'$MY_DEVICE'",
- "secrets": [{ "pwd-plain": "'$MY_PWD'" }]
-}]' http://$REGISTRY_IP:28080/v1/credentials/$MY_TENANT/$MY_DEVICE
+curl -i -X PUT -H "content-type: application/json" --data-binary "[{
+ \"type\": \"hashed-password\",
+ \"auth-id\": \"${MY_DEVICE}\",
+ \"secrets\": [{ \"pwd-plain\": \"${MY_PWD}\" }]
+}]" "http://${REGISTRY_IP}:28080/v1/credentials/${MY_TENANT}/${MY_DEVICE}"
diff --git a/examples/quickstart-python/quickstart.py b/examples/quickstart-python/quickstart.py
index 5cf0508b5d..3767d8f6bc 100644
--- a/examples/quickstart-python/quickstart.py
+++ b/examples/quickstart-python/quickstart.py
@@ -109,6 +109,7 @@ def on_message(self, event):
# Send HTTP Message
print("Send Telemetry Message via HTTP")
+# nosemgrep: no-auth-over-http
response = requests.post(f'http://{httpAdapterIp}:8080/telemetry', headers={"content-type": "application/json"},
data=json.dumps({"temp": 5, "transport": "http"}),
auth=HTTPBasicAuth(f'{deviceId}@{tenantId}', f'{devicePassword}'))
diff --git a/legal/src/main/resources/legal/DEPENDENCIES b/legal/src/main/resources/legal/DEPENDENCIES
index 8a1ea6dce5..b36fccd6da 100644
--- a/legal/src/main/resources/legal/DEPENDENCIES
+++ b/legal/src/main/resources/legal/DEPENDENCIES
@@ -16,6 +16,7 @@ maven/mavencentral/com.github.luben/zstd-jni/1.5.2-1, BSD-2-Clause, approved, cl
maven/mavencentral/com.github.mifmif/generex/1.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.api.grpc/proto-google-common-protos/2.9.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.code.gson/gson/2.9.0, Apache-2.0, approved, CQ24148
+maven/mavencentral/com.google.errorprone/error_prone_annotations/2.14.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.guava/failureaccess/1.0.1, Apache-2.0, approved, CQ22654
maven/mavencentral/com.google.guava/guava/31.1-jre, Apache-2.0 AND CC0-1.0 AND LicenseRef-Public-Domain, approved, CQ24046
maven/mavencentral/com.google.protobuf/protobuf-java/3.19.3, BSD-3-Clause, approved, clearlydefined
diff --git a/legal/src/main/resources/legal/hono-maven.deps b/legal/src/main/resources/legal/hono-maven.deps
index aacb529734..9c0a5a3c7e 100644
--- a/legal/src/main/resources/legal/hono-maven.deps
+++ b/legal/src/main/resources/legal/hono-maven.deps
@@ -16,6 +16,7 @@ com.github.luben:zstd-jni:jar:1.5.2-1
com.github.mifmif:generex:jar:1.0.2
com.google.api.grpc:proto-google-common-protos:jar:2.9.1
com.google.code.gson:gson:jar:2.9.0
+com.google.errorprone:error_prone_annotations:jar:2.14.0
com.google.guava:failureaccess:jar:1.0.1
com.google.guava:guava:jar:31.1-jre
com.google.protobuf:protobuf-java:jar:3.19.3
diff --git a/service-base/pom.xml b/service-base/pom.xml
index b6e4feac2c..aadd793702 100644
--- a/service-base/pom.xml
+++ b/service-base/pom.xml
@@ -135,6 +135,11 @@