Showing
1 changed file
with
10 additions
and
2 deletions
@@ -28,9 +28,8 @@ import com.google.gson.JsonObject; | @@ -28,9 +28,8 @@ import com.google.gson.JsonObject; | ||
28 | import io.grpc.stub.StreamObserver; | 28 | import io.grpc.stub.StreamObserver; |
29 | import lombok.Data; | 29 | import lombok.Data; |
30 | import lombok.extern.slf4j.Slf4j; | 30 | import lombok.extern.slf4j.Slf4j; |
31 | -import org.apache.commons.lang3.RandomStringUtils; | 31 | +import org.apache.commons.lang.RandomStringUtils; |
32 | import org.checkerframework.checker.nullness.qual.Nullable; | 32 | import org.checkerframework.checker.nullness.qual.Nullable; |
33 | -import org.springframework.util.StringUtils; | ||
34 | import org.thingsboard.server.common.data.Dashboard; | 33 | import org.thingsboard.server.common.data.Dashboard; |
35 | import org.thingsboard.server.common.data.DataConstants; | 34 | import org.thingsboard.server.common.data.DataConstants; |
36 | import org.thingsboard.server.common.data.Device; | 35 | import org.thingsboard.server.common.data.Device; |
@@ -871,6 +870,7 @@ public final class EdgeGrpcSession implements Closeable { | @@ -871,6 +870,7 @@ public final class EdgeGrpcSession implements Closeable { | ||
871 | device.setType(deviceUpdateMsg.getType()); | 870 | device.setType(deviceUpdateMsg.getType()); |
872 | device.setLabel(deviceUpdateMsg.getLabel()); | 871 | device.setLabel(deviceUpdateMsg.getLabel()); |
873 | device = ctx.getDeviceService().saveDevice(device); | 872 | device = ctx.getDeviceService().saveDevice(device); |
873 | + createDeviceCredentials(device); | ||
874 | device = ctx.getDeviceService().assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId()); | 874 | device = ctx.getDeviceService().assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId()); |
875 | createRelationFromEdge(device.getId()); | 875 | createRelationFromEdge(device.getId()); |
876 | ctx.getRelationService().saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(edge.getId(), device.getId(), "Created")); | 876 | ctx.getRelationService().saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(edge.getId(), device.getId(), "Created")); |
@@ -883,6 +883,14 @@ public final class EdgeGrpcSession implements Closeable { | @@ -883,6 +883,14 @@ public final class EdgeGrpcSession implements Closeable { | ||
883 | return device; | 883 | return device; |
884 | } | 884 | } |
885 | 885 | ||
886 | + private void createDeviceCredentials(Device device) { | ||
887 | + DeviceCredentials deviceCredentials = new DeviceCredentials(); | ||
888 | + deviceCredentials.setDeviceId(device.getId()); | ||
889 | + deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); | ||
890 | + deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); | ||
891 | + ctx.getDeviceCredentialsService().createDeviceCredentials(device.getTenantId(), deviceCredentials); | ||
892 | + } | ||
893 | + | ||
886 | private EntityId getAlarmOriginator(String entityName, org.thingsboard.server.common.data.EntityType entityType) { | 894 | private EntityId getAlarmOriginator(String entityName, org.thingsboard.server.common.data.EntityType entityType) { |
887 | switch (entityType) { | 895 | switch (entityType) { |
888 | case DEVICE: | 896 | case DEVICE: |