Commit 8046f7ef45365a5bf0703dcc62d11f3687e614bd
Committed by
Andrew Shvayka
1 parent
6b55f330
Changed device provisioning response and added ability to provision devices without deviceName
Showing
6 changed files
with
57 additions
and
72 deletions
... | ... | @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.Futures; |
22 | 22 | import com.google.common.util.concurrent.ListenableFuture; |
23 | 23 | import com.google.common.util.concurrent.MoreExecutors; |
24 | 24 | import lombok.extern.slf4j.Slf4j; |
25 | +import org.apache.commons.lang.RandomStringUtils; | |
25 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
26 | 27 | import org.springframework.stereotype.Service; |
27 | 28 | import org.springframework.util.StringUtils; |
... | ... | @@ -188,6 +189,11 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { |
188 | 189 | Device device = deviceService.findDeviceByTenantIdAndName(profile.getTenantId(), provisionRequest.getDeviceName()); |
189 | 190 | try { |
190 | 191 | if (device == null) { |
192 | + if (StringUtils.isEmpty(provisionRequest.getDeviceName())) { | |
193 | + String newDeviceName = RandomStringUtils.randomAlphanumeric(20); | |
194 | + log.info("Device name not found in provision request. Generated name is: {}", newDeviceName); | |
195 | + provisionRequest.setDeviceName(newDeviceName); | |
196 | + } | |
191 | 197 | Device savedDevice = deviceService.saveDevice(provisionRequest, profile); |
192 | 198 | |
193 | 199 | deviceStateService.onDeviceAdded(savedDevice); | ... | ... |
... | ... | @@ -54,12 +54,15 @@ import org.thingsboard.server.dao.device.provision.ProvisionResponse; |
54 | 54 | import org.thingsboard.server.dao.relation.RelationService; |
55 | 55 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
56 | 56 | import org.thingsboard.server.gen.transport.TransportProtos; |
57 | +import org.thingsboard.server.gen.transport.TransportProtos.DeviceCredentialsProto; | |
57 | 58 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceInfoProto; |
58 | 59 | import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg; |
59 | 60 | import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayResponseMsg; |
60 | 61 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg; |
61 | 62 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg; |
62 | 63 | import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceRequestMsg; |
64 | +import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsg; | |
65 | +import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsgOrBuilder; | |
63 | 66 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
64 | 67 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
65 | 68 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg; |
... | ... | @@ -292,30 +295,29 @@ public class DefaultTransportApiService implements TransportApiService { |
292 | 295 | requestMsg.getProvisionDeviceCredentialsMsg().getProvisionDeviceSecret())))); |
293 | 296 | } catch (ProvisionFailedException e) { |
294 | 297 | return Futures.immediateFuture(getTransportApiResponseMsg( |
295 | - TransportProtos.DeviceCredentialsProto.getDefaultInstance(), | |
298 | + new DeviceCredentials(), | |
296 | 299 | TransportProtos.ProvisionResponseStatus.valueOf(e.getMessage()))); |
297 | 300 | } |
298 | - return Futures.transform(provisionResponseFuture, provisionResponse -> getTransportApiResponseMsg( | |
299 | - getDeviceCredentials(provisionResponse.getDeviceCredentials()), TransportProtos.ProvisionResponseStatus.SUCCESS), | |
301 | + return Futures.transform(provisionResponseFuture, provisionResponse -> getTransportApiResponseMsg(provisionResponse.getDeviceCredentials(), TransportProtos.ProvisionResponseStatus.SUCCESS), | |
300 | 302 | dbCallbackExecutorService); |
301 | 303 | } |
302 | 304 | |
303 | - private TransportApiResponseMsg getTransportApiResponseMsg(TransportProtos.DeviceCredentialsProto deviceCredentials, TransportProtos.ProvisionResponseStatus status) { | |
304 | - return TransportApiResponseMsg.newBuilder() | |
305 | - .setProvisionDeviceResponseMsg(TransportProtos.ProvisionDeviceResponseMsg.newBuilder() | |
306 | - .setDeviceCredentials(deviceCredentials) | |
307 | - .setProvisionResponseStatus(status) | |
308 | - .build()) | |
309 | - .build(); | |
310 | - } | |
305 | + private TransportApiResponseMsg getTransportApiResponseMsg(DeviceCredentials deviceCredentials, TransportProtos.ProvisionResponseStatus status) { | |
306 | + TransportProtos.ProvisionDeviceResponseMsg.Builder provisionResponse = TransportProtos.ProvisionDeviceResponseMsg.newBuilder() | |
307 | + .setCredentialsType(TransportProtos.CredentialsType.valueOf(deviceCredentials.getCredentialsType().name())) | |
308 | + .setStatus(status); | |
309 | + switch (deviceCredentials.getCredentialsType()){ | |
310 | + case ACCESS_TOKEN: | |
311 | + provisionResponse.setCredentialsValue(deviceCredentials.getCredentialsId()); | |
312 | + break; | |
313 | + case MQTT_BASIC: | |
314 | + case X509_CERTIFICATE: | |
315 | + provisionResponse.setCredentialsValue(deviceCredentials.getCredentialsValue()); | |
316 | + break; | |
317 | + } | |
311 | 318 | |
312 | - private TransportProtos.DeviceCredentialsProto getDeviceCredentials(DeviceCredentials deviceCredentials) { | |
313 | - return TransportProtos.DeviceCredentialsProto.newBuilder() | |
314 | - .setDeviceIdMSB(deviceCredentials.getDeviceId().getId().getMostSignificantBits()) | |
315 | - .setDeviceIdLSB(deviceCredentials.getDeviceId().getId().getLeastSignificantBits()) | |
316 | - .setCredentialsType(TransportProtos.CredentialsType.valueOf(deviceCredentials.getCredentialsType().name())) | |
317 | - .setCredentialsId(deviceCredentials.getCredentialsId()) | |
318 | - .setCredentialsValue(deviceCredentials.getCredentialsValue() != null ? deviceCredentials.getCredentialsValue() : "") | |
319 | + return TransportApiResponseMsg.newBuilder() | |
320 | + .setProvisionDeviceResponseMsg(provisionResponse.build()) | |
319 | 321 | .build(); |
320 | 322 | } |
321 | 323 | ... | ... |
... | ... | @@ -98,7 +98,7 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
98 | 98 | byte[] result = createMqttClientAndPublish().getPayloadBytes(); |
99 | 99 | JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); |
100 | 100 | Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString()); |
101 | - Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("provisionDeviceStatus").getAsString()); | |
101 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("status").getAsString()); | |
102 | 102 | } |
103 | 103 | |
104 | 104 | |
... | ... | @@ -110,13 +110,11 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
110 | 110 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
111 | 111 | |
112 | 112 | Assert.assertNotNull(createdDevice); |
113 | - Assert.assertEquals(createdDevice.getId().toString(), response.get("deviceId").getAsString()); | |
114 | 113 | |
115 | 114 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
116 | 115 | |
117 | 116 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); |
118 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
119 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("provisionDeviceStatus").getAsString()); | |
117 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | |
120 | 118 | } |
121 | 119 | |
122 | 120 | |
... | ... | @@ -129,15 +127,13 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
129 | 127 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
130 | 128 | |
131 | 129 | Assert.assertNotNull(createdDevice); |
132 | - Assert.assertEquals(createdDevice.getId().toString(), response.get("deviceId").getAsString()); | |
133 | 130 | |
134 | 131 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
135 | 132 | |
136 | 133 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); |
137 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
138 | 134 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "ACCESS_TOKEN"); |
139 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), "test_token"); | |
140 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("provisionDeviceStatus").getAsString()); | |
135 | + Assert.assertEquals(deviceCredentials.getCredentialsValue(), "test_token"); | |
136 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | |
141 | 137 | } |
142 | 138 | |
143 | 139 | |
... | ... | @@ -150,12 +146,10 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
150 | 146 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
151 | 147 | |
152 | 148 | Assert.assertNotNull(createdDevice); |
153 | - Assert.assertEquals(createdDevice.getId().toString(), response.get("deviceId").getAsString()); | |
154 | 149 | |
155 | 150 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
156 | 151 | |
157 | 152 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); |
158 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
159 | 153 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "X509_CERTIFICATE"); |
160 | 154 | |
161 | 155 | String cert = EncryptionUtil.trimNewLines(deviceCredentials.getCredentialsValue()); |
... | ... | @@ -164,7 +158,7 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
164 | 158 | Assert.assertEquals(deviceCredentials.getCredentialsId(), sha3Hash); |
165 | 159 | |
166 | 160 | Assert.assertEquals(deviceCredentials.getCredentialsValue(), "testHash"); |
167 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("provisionDeviceStatus").getAsString()); | |
161 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | |
168 | 162 | } |
169 | 163 | |
170 | 164 | |
... | ... | @@ -177,12 +171,10 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
177 | 171 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
178 | 172 | |
179 | 173 | Assert.assertNotNull(createdDevice); |
180 | - Assert.assertEquals(createdDevice.getId().toString(), response.get("deviceId").getAsString()); | |
181 | 174 | |
182 | 175 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
183 | 176 | |
184 | 177 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); |
185 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
186 | 178 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "MQTT_BASIC"); |
187 | 179 | Assert.assertEquals(deviceCredentials.getCredentialsId(), EncryptionUtil.getSha3Hash("|", "test_clientId", "test_username")); |
188 | 180 | |
... | ... | @@ -192,21 +184,18 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
192 | 184 | mqttCredentials.setPassword("test_password"); |
193 | 185 | |
194 | 186 | Assert.assertEquals(deviceCredentials.getCredentialsValue(), JacksonUtil.toString(mqttCredentials)); |
195 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
196 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("provisionDeviceStatus").getAsString()); | |
187 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | |
197 | 188 | } |
198 | 189 | |
199 | 190 | protected void processTestProvisioningCheckPreProvisionedDevice() throws Exception { |
200 | 191 | super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKey", "testProvisionSecret"); |
201 | 192 | byte[] result = createMqttClientAndPublish().getPayloadBytes(); |
202 | 193 | JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); |
203 | - Assert.assertEquals(savedDevice.getId().toString(), response.get("deviceId").getAsString()); | |
204 | 194 | |
205 | 195 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId()); |
206 | 196 | |
207 | 197 | Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); |
208 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.get("credentialsId").getAsString()); | |
209 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("provisionDeviceStatus").getAsString()); | |
198 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | |
210 | 199 | } |
211 | 200 | |
212 | 201 | protected void processTestProvisioningWithBadKeyDevice() throws Exception { |
... | ... | @@ -214,7 +203,7 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn |
214 | 203 | byte[] result = createMqttClientAndPublish().getPayloadBytes(); |
215 | 204 | JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); |
216 | 205 | Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString()); |
217 | - Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("provisionDeviceStatus").getAsString()); | |
206 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("status").getAsString()); | |
218 | 207 | } |
219 | 208 | |
220 | 209 | protected TestMqttCallback createMqttClientAndPublish() throws Exception { | ... | ... |
... | ... | @@ -105,7 +105,7 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
105 | 105 | super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, DeviceProfileProvisionType.DISABLED, null, null); |
106 | 106 | ProvisionDeviceResponseMsg result = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes()); |
107 | 107 | Assert.assertNotNull(result); |
108 | - Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), result.getProvisionResponseStatus().toString()); | |
108 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), result.getStatus().toString()); | |
109 | 109 | } |
110 | 110 | |
111 | 111 | protected void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception { |
... | ... | @@ -115,13 +115,11 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
115 | 115 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
116 | 116 | |
117 | 117 | Assert.assertNotNull(createdDevice); |
118 | - Assert.assertEquals(createdDevice.getId().getId(), new UUID(response.getDeviceCredentials().getDeviceIdMSB(), response.getDeviceCredentials().getDeviceIdLSB())); | |
119 | 118 | |
120 | 119 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
121 | 120 | |
122 | - Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getDeviceCredentials().getCredentialsType().toString()); | |
123 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
124 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getProvisionResponseStatus().toString()); | |
121 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | |
122 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | |
125 | 123 | } |
126 | 124 | |
127 | 125 | protected void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception { |
... | ... | @@ -133,15 +131,13 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
133 | 131 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
134 | 132 | |
135 | 133 | Assert.assertNotNull(createdDevice); |
136 | - Assert.assertEquals(createdDevice.getId().getId(), new UUID(response.getDeviceCredentials().getDeviceIdMSB(), response.getDeviceCredentials().getDeviceIdLSB())); | |
137 | 134 | |
138 | 135 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
139 | 136 | |
140 | - Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getDeviceCredentials().getCredentialsType().toString()); | |
141 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
137 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | |
142 | 138 | Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.ACCESS_TOKEN); |
143 | 139 | Assert.assertEquals(deviceCredentials.getCredentialsId(), "test_token"); |
144 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getProvisionResponseStatus().toString()); | |
140 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | |
145 | 141 | } |
146 | 142 | |
147 | 143 | protected void processTestProvisioningCreateNewDeviceWithCert() throws Exception { |
... | ... | @@ -153,12 +149,10 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
153 | 149 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
154 | 150 | |
155 | 151 | Assert.assertNotNull(createdDevice); |
156 | - Assert.assertEquals(createdDevice.getId().getId(), new UUID(response.getDeviceCredentials().getDeviceIdMSB(), response.getDeviceCredentials().getDeviceIdLSB())); | |
157 | 152 | |
158 | 153 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
159 | 154 | |
160 | - Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getDeviceCredentials().getCredentialsType().toString()); | |
161 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
155 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | |
162 | 156 | Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.X509_CERTIFICATE); |
163 | 157 | |
164 | 158 | String cert = EncryptionUtil.trimNewLines(deviceCredentials.getCredentialsValue()); |
... | ... | @@ -167,7 +161,7 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
167 | 161 | Assert.assertEquals(deviceCredentials.getCredentialsId(), sha3Hash); |
168 | 162 | |
169 | 163 | Assert.assertEquals(deviceCredentials.getCredentialsValue(), "testHash"); |
170 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getProvisionResponseStatus().toString()); | |
164 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | |
171 | 165 | } |
172 | 166 | |
173 | 167 | protected void processTestProvisioningCreateNewDeviceWithMqttBasic() throws Exception { |
... | ... | @@ -185,12 +179,10 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
185 | 179 | Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); |
186 | 180 | |
187 | 181 | Assert.assertNotNull(createdDevice); |
188 | - Assert.assertEquals(createdDevice.getId().getId(), new UUID(response.getDeviceCredentials().getDeviceIdMSB(), response.getDeviceCredentials().getDeviceIdLSB())); | |
189 | 182 | |
190 | 183 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); |
191 | 184 | |
192 | - Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getDeviceCredentials().getCredentialsType().toString()); | |
193 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
185 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | |
194 | 186 | Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.MQTT_BASIC); |
195 | 187 | Assert.assertEquals(deviceCredentials.getCredentialsId(), EncryptionUtil.getSha3Hash("|", "test_clientId", "test_username")); |
196 | 188 | |
... | ... | @@ -200,26 +192,23 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI |
200 | 192 | mqttCredentials.setPassword("test_password"); |
201 | 193 | |
202 | 194 | Assert.assertEquals(deviceCredentials.getCredentialsValue(), JacksonUtil.toString(mqttCredentials)); |
203 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
204 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getProvisionResponseStatus().toString()); | |
195 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | |
205 | 196 | } |
206 | 197 | |
207 | 198 | protected void processTestProvisioningCheckPreProvisionedDevice() throws Exception { |
208 | 199 | super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKey", "testProvisionSecret"); |
209 | 200 | ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes()); |
210 | - Assert.assertEquals(savedDevice.getId().getId(), new UUID(response.getDeviceCredentials().getDeviceIdMSB(), response.getDeviceCredentials().getDeviceIdLSB())); | |
211 | 201 | |
212 | 202 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId()); |
213 | 203 | |
214 | - Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getDeviceCredentials().getCredentialsType().toString()); | |
215 | - Assert.assertEquals(deviceCredentials.getCredentialsId(), response.getDeviceCredentials().getCredentialsId()); | |
216 | - Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getProvisionResponseStatus().toString()); | |
204 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | |
205 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | |
217 | 206 | } |
218 | 207 | |
219 | 208 | protected void processTestProvisioningWithBadKeyDevice() throws Exception { |
220 | 209 | super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKeyOrig", "testProvisionSecret"); |
221 | 210 | ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes()); |
222 | - Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.getProvisionResponseStatus().toString()); | |
211 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.getStatus().toString()); | |
223 | 212 | } |
224 | 213 | |
225 | 214 | protected TestMqttCallback createMqttClientAndPublish() throws Exception { | ... | ... |
... | ... | @@ -269,8 +269,9 @@ message ProvisionDeviceCredentialsMsg { |
269 | 269 | } |
270 | 270 | |
271 | 271 | message ProvisionDeviceResponseMsg { |
272 | - DeviceCredentialsProto deviceCredentials = 1; | |
273 | - ProvisionResponseStatus provisionResponseStatus = 2; | |
272 | + ProvisionResponseStatus status = 1; | |
273 | + CredentialsType credentialsType = 2; | |
274 | + string credentialsValue = 3; | |
274 | 275 | } |
275 | 276 | |
276 | 277 | enum ProvisionResponseStatus { | ... | ... |
... | ... | @@ -408,22 +408,20 @@ public class JsonConverter { |
408 | 408 | |
409 | 409 | private static JsonObject toJson(ProvisionDeviceResponseMsg payload, boolean toGateway, int requestId) { |
410 | 410 | JsonObject result = new JsonObject(); |
411 | - if (payload.getProvisionResponseStatus() == TransportProtos.ProvisionResponseStatus.NOT_FOUND) { | |
411 | + if (payload.getStatus() == TransportProtos.ProvisionResponseStatus.NOT_FOUND) { | |
412 | 412 | result.addProperty("errorMsg", "Provision data was not found!"); |
413 | - result.addProperty("provisionDeviceStatus", ProvisionResponseStatus.NOT_FOUND.name()); | |
414 | - } else if (payload.getProvisionResponseStatus() == TransportProtos.ProvisionResponseStatus.FAILURE) { | |
413 | + result.addProperty("status", ProvisionResponseStatus.NOT_FOUND.name()); | |
414 | + } else if (payload.getStatus() == TransportProtos.ProvisionResponseStatus.FAILURE) { | |
415 | 415 | result.addProperty("errorMsg", "Failed to provision device!"); |
416 | - result.addProperty("provisionDeviceStatus", ProvisionResponseStatus.FAILURE.name()); | |
416 | + result.addProperty("status", ProvisionResponseStatus.FAILURE.name()); | |
417 | 417 | } else { |
418 | 418 | if (toGateway) { |
419 | 419 | result.addProperty("id", requestId); |
420 | 420 | } |
421 | - result.addProperty("deviceId", new UUID(payload.getDeviceCredentials().getDeviceIdMSB(), payload.getDeviceCredentials().getDeviceIdLSB()).toString()); | |
422 | - result.addProperty("credentialsType", payload.getDeviceCredentials().getCredentialsType().name()); | |
423 | - result.addProperty("credentialsId", payload.getDeviceCredentials().getCredentialsId()); | |
421 | + result.addProperty("credentialsType", payload.getCredentialsType().name()); | |
424 | 422 | result.addProperty("credentialsValue", |
425 | - StringUtils.isEmpty(payload.getDeviceCredentials().getCredentialsValue()) ? null : payload.getDeviceCredentials().getCredentialsValue()); | |
426 | - result.addProperty("provisionDeviceStatus", ProvisionResponseStatus.SUCCESS.name()); | |
423 | + StringUtils.isEmpty(payload.getCredentialsValue()) ? null : payload.getCredentialsValue()); | |
424 | + result.addProperty("status", ProvisionResponseStatus.SUCCESS.name()); | |
427 | 425 | } |
428 | 426 | return result; |
429 | 427 | } |
... | ... | @@ -551,7 +549,7 @@ public class JsonConverter { |
551 | 549 | |
552 | 550 | private static TransportProtos.ProvisionDeviceRequestMsg buildProvisionRequestMsg(JsonObject jo) { |
553 | 551 | return TransportProtos.ProvisionDeviceRequestMsg.newBuilder() |
554 | - .setDeviceName(getStrValue(jo, DataConstants.DEVICE_NAME, true)) | |
552 | + .setDeviceName(getStrValue(jo, DataConstants.DEVICE_NAME, false)) | |
555 | 553 | .setCredentialsType(jo.get(DataConstants.CREDENTIALS_TYPE) != null ? TransportProtos.CredentialsType.valueOf(getStrValue(jo, DataConstants.CREDENTIALS_TYPE, false)) : CredentialsType.ACCESS_TOKEN) |
556 | 554 | .setCredentialsDataProto(TransportProtos.CredentialsDataProto.newBuilder() |
557 | 555 | .setValidateDeviceTokenRequestMsg(ValidateDeviceTokenRequestMsg.newBuilder().setToken(getStrValue(jo, DataConstants.TOKEN, false)).build()) | ... | ... |