Refactoring x509 provisioning, fix tests
This commit is contained in:
parent
b0d35372aa
commit
e71f6bcc26
@ -275,9 +275,8 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService {
|
||||
|
||||
private void fetchAndApplyDeviceNameForX509ProvisionRequestWithRegEx(ProvisionRequest provisionRequest) {
|
||||
DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileByProvisionDeviceKey(provisionRequest.getCredentials().getProvisionDeviceKey());
|
||||
X509CertificateChainProvisionConfiguration configuration;
|
||||
if (deviceProfile.getProfileData().getProvisionConfiguration() instanceof X509CertificateChainProvisionConfiguration) {
|
||||
configuration = (X509CertificateChainProvisionConfiguration) deviceProfile.getProfileData().getProvisionConfiguration();
|
||||
if (deviceProfile != null && deviceProfile.getProfileData() != null && deviceProfile.getProfileData().getProvisionConfiguration() instanceof X509CertificateChainProvisionConfiguration) {
|
||||
X509CertificateChainProvisionConfiguration configuration = (X509CertificateChainProvisionConfiguration) deviceProfile.getProfileData().getProvisionConfiguration();
|
||||
String certificateValue = provisionRequest.getCredentialsData().getX509CertHash();
|
||||
String certificateRegEx = configuration.getCertificateRegExPattern();
|
||||
String deviceName = extractDeviceNameFromCertificateCNByRegEx(certificateValue, certificateRegEx);
|
||||
@ -298,7 +297,6 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService {
|
||||
if (matcher.find()) {
|
||||
return matcher.group(0);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -712,11 +712,12 @@ public class DefaultTransportApiService implements TransportApiService {
|
||||
}
|
||||
|
||||
private ProvisionResponse provisionDeviceRequestAndGetResponse(ProvisionRequest provisionRequest) {
|
||||
ProvisionResponse provisionResponse = null;
|
||||
try {
|
||||
provisionResponse = deviceProvisionService.provisionDevice(provisionRequest);
|
||||
} catch (ProvisionFailedException ignored) {}
|
||||
return provisionResponse;
|
||||
return deviceProvisionService.provisionDevice(provisionRequest);
|
||||
} catch (ProvisionFailedException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> convertX509CertificateChainToList(String certificateChain) {
|
||||
|
||||
@ -221,7 +221,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
||||
|
||||
@Override
|
||||
public DeviceProfile findDeviceProfileByProvisionDeviceKey(String provisionDeviceKey) {
|
||||
log.trace("Executing findDeviceProfileIdByCredentialsId credentialId [{}]", provisionDeviceKey);
|
||||
log.trace("Executing findDeviceProfileByProvisionDeviceKey provisionKey [{}]", provisionDeviceKey);
|
||||
validateString(provisionDeviceKey, INCORRECT_PROVISION_DEVICE_KEY + provisionDeviceKey);
|
||||
return cache.getAndPutInTransaction(DeviceProfileCacheKey.fromProvisionDeviceKey(provisionDeviceKey),
|
||||
() -> deviceProfileDao.findByProvisionDeviceKey(provisionDeviceKey), true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user