Commit 4462455c0aa640681e87fd36ef35f1f2fba880c2

Authored by VoBa
Committed by GitHub
2 parents 5b413a4b 79c94735

Merge pull request #15 from BohdanSmetanyuk/bug/device_credentials_from_edge

bug fixed by DeviceCredentials creation
... ... @@ -28,6 +28,7 @@ import com.google.gson.JsonObject;
28 28 import io.grpc.stub.StreamObserver;
29 29 import lombok.Data;
30 30 import lombok.extern.slf4j.Slf4j;
  31 +import org.apache.commons.lang.RandomStringUtils;
31 32 import org.checkerframework.checker.nullness.qual.Nullable;
32 33 import org.thingsboard.server.common.data.Dashboard;
33 34 import org.thingsboard.server.common.data.DataConstants;
... ... @@ -866,6 +867,7 @@ public final class EdgeGrpcSession implements Closeable {
866 867 device.setType(deviceUpdateMsg.getType());
867 868 device.setLabel(deviceUpdateMsg.getLabel());
868 869 device = ctx.getDeviceService().saveDevice(device);
  870 + createDeviceCredentials(device);
869 871 device = ctx.getDeviceService().assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId());
870 872 createRelationFromEdge(device.getId());
871 873 ctx.getRelationService().saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(edge.getId(), device.getId(), "Created"));
... ... @@ -878,6 +880,14 @@ public final class EdgeGrpcSession implements Closeable {
878 880 return device;
879 881 }
880 882
  883 + private void createDeviceCredentials(Device device) {
  884 + DeviceCredentials deviceCredentials = new DeviceCredentials();
  885 + deviceCredentials.setDeviceId(device.getId());
  886 + deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
  887 + deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
  888 + ctx.getDeviceCredentialsService().createDeviceCredentials(device.getTenantId(), deviceCredentials);
  889 + }
  890 +
881 891 private EntityId getAlarmOriginator(String entityName, org.thingsboard.server.common.data.EntityType entityType) {
882 892 switch (entityType) {
883 893 case DEVICE:
... ...