|
@@ -27,8 +27,9 @@ import org.springframework.util.StringUtils; |
|
@@ -27,8 +27,9 @@ import org.springframework.util.StringUtils; |
27
|
import org.thingsboard.server.common.data.DataConstants;
|
27
|
import org.thingsboard.server.common.data.DataConstants;
|
28
|
import org.thingsboard.server.common.data.Device;
|
28
|
import org.thingsboard.server.common.data.Device;
|
29
|
import org.thingsboard.server.common.data.DeviceProfile;
|
29
|
import org.thingsboard.server.common.data.DeviceProfile;
|
30
|
-import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
|
|
31
|
import org.thingsboard.server.common.data.audit.ActionType;
|
30
|
import org.thingsboard.server.common.data.audit.ActionType;
|
|
|
31
|
+import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration;
|
|
|
32
|
+import org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration;
|
32
|
import org.thingsboard.server.common.data.id.CustomerId;
|
33
|
import org.thingsboard.server.common.data.id.CustomerId;
|
33
|
import org.thingsboard.server.common.data.id.TenantId;
|
34
|
import org.thingsboard.server.common.data.id.TenantId;
|
34
|
import org.thingsboard.server.common.data.id.UserId;
|
35
|
import org.thingsboard.server.common.data.id.UserId;
|
|
@@ -115,11 +116,9 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { |
|
@@ -115,11 +116,9 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { |
115
|
return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.NOT_FOUND));
|
116
|
return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.NOT_FOUND));
|
116
|
}
|
117
|
}
|
117
|
|
118
|
|
118
|
- DeviceProfile targetProfile = deviceProfileDao.findByProvisionDeviceKeyAndProvisionDeviceSecret(provisionRequestKey, provisionRequestSecret);
|
119
|
+ DeviceProfile targetProfile = deviceProfileDao.findByProvisionDeviceKey(provisionRequestKey);
|
119
|
|
120
|
|
120
|
- if (targetProfile == null ||
|
|
|
121
|
- !(targetProfile.getProvisionType() != DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES ||
|
|
|
122
|
- targetProfile.getProvisionType() != DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)) {
|
121
|
+ if (targetProfile == null) {
|
123
|
return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.NOT_FOUND));
|
122
|
return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.NOT_FOUND));
|
124
|
}
|
123
|
}
|
125
|
|
124
|
|
|
@@ -127,23 +126,28 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { |
|
@@ -127,23 +126,28 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { |
127
|
|
126
|
|
128
|
switch(targetProfile.getProvisionType()) {
|
127
|
switch(targetProfile.getProvisionType()) {
|
129
|
case ALLOW_CREATE_NEW_DEVICES:
|
128
|
case ALLOW_CREATE_NEW_DEVICES:
|
130
|
- if (targetDevice != null) {
|
|
|
131
|
- log.warn("[{}] The device is present and could not be provisioned once more!", targetDevice.getName());
|
|
|
132
|
- notify(targetDevice, provisionRequest, DataConstants.PROVISION_FAILURE, false);
|
|
|
133
|
- return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.FAILURE));
|
|
|
134
|
- } else {
|
|
|
135
|
- return createDevice(provisionRequest, targetProfile);
|
129
|
+ if (((AllowCreateNewDevicesDeviceProfileProvisionConfiguration) targetProfile.getProfileData().getProvisionConfiguration()).getProvisionDeviceSecret().equals(provisionRequestSecret)){
|
|
|
130
|
+ if (targetDevice != null) {
|
|
|
131
|
+ log.warn("[{}] The device is present and could not be provisioned once more!", targetDevice.getName());
|
|
|
132
|
+ notify(targetDevice, provisionRequest, DataConstants.PROVISION_FAILURE, false);
|
|
|
133
|
+ return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.FAILURE));
|
|
|
134
|
+ } else {
|
|
|
135
|
+ return createDevice(provisionRequest, targetProfile);
|
|
|
136
|
+ }
|
136
|
}
|
137
|
}
|
|
|
138
|
+ break;
|
137
|
case CHECK_PRE_PROVISIONED_DEVICES:
|
139
|
case CHECK_PRE_PROVISIONED_DEVICES:
|
138
|
- if (targetDevice != null && targetDevice.getDeviceProfileId().equals(targetProfile.getId())){
|
|
|
139
|
- return processProvision(targetDevice, provisionRequest);
|
|
|
140
|
- } else {
|
|
|
141
|
- log.warn("[{}] Failed to find pre provisioned device!", provisionRequest.getDeviceName());
|
|
|
142
|
- return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.FAILURE));
|
140
|
+ if (((CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) targetProfile.getProfileData().getProvisionConfiguration()).getProvisionDeviceSecret().equals(provisionRequestSecret)) {
|
|
|
141
|
+ if (targetDevice != null && targetDevice.getDeviceProfileId().equals(targetProfile.getId())) {
|
|
|
142
|
+ return processProvision(targetDevice, provisionRequest);
|
|
|
143
|
+ } else {
|
|
|
144
|
+ log.warn("[{}] Failed to find pre provisioned device!", provisionRequest.getDeviceName());
|
|
|
145
|
+ return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.FAILURE));
|
|
|
146
|
+ }
|
143
|
}
|
147
|
}
|
144
|
- default:
|
|
|
145
|
- throw new RuntimeException("Strategy is not supported - " + targetProfile.getProvisionType().name());
|
148
|
+ break;
|
146
|
}
|
149
|
}
|
|
|
150
|
+ return Futures.immediateFuture(new ProvisionResponse(null, ProvisionResponseStatus.NOT_FOUND));
|
147
|
}
|
151
|
}
|
148
|
|
152
|
|
149
|
private ListenableFuture<ProvisionResponse> processProvision(Device device, ProvisionRequest provisionRequest) {
|
153
|
private ListenableFuture<ProvisionResponse> processProvision(Device device, ProvisionRequest provisionRequest) {
|