Merge pull request #13329 from jekka001/add-validation-for-edge-rule-chain
Add validation for DefaultEdgeRuleChain in DeviceProfile
This commit is contained in:
		
						commit
						55335df256
					
				@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.Abstrac
 | 
			
		||||
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential;
 | 
			
		||||
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential;
 | 
			
		||||
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential;
 | 
			
		||||
import org.thingsboard.server.common.data.id.RuleChainId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.queue.Queue;
 | 
			
		||||
import org.thingsboard.server.common.data.rule.RuleChain;
 | 
			
		||||
@ -188,13 +189,11 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (deviceProfile.getDefaultRuleChainId() != null) {
 | 
			
		||||
            RuleChain ruleChain = ruleChainService.findRuleChainById(tenantId, deviceProfile.getDefaultRuleChainId());
 | 
			
		||||
            if (ruleChain == null) {
 | 
			
		||||
                throw new DataValidationException("Can't assign non-existent rule chain!");
 | 
			
		||||
            }
 | 
			
		||||
            if (!ruleChain.getTenantId().equals(deviceProfile.getTenantId())) {
 | 
			
		||||
                throw new DataValidationException("Can't assign rule chain from different tenant!");
 | 
			
		||||
            }
 | 
			
		||||
            validateRuleChain(tenantId, deviceProfile.getTenantId(), deviceProfile.getDefaultRuleChainId());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (deviceProfile.getDefaultEdgeRuleChainId() != null) {
 | 
			
		||||
            validateRuleChain(tenantId, deviceProfile.getTenantId(), deviceProfile.getDefaultEdgeRuleChainId());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (deviceProfile.getDefaultDashboardId() != null) {
 | 
			
		||||
@ -210,6 +209,16 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
 | 
			
		||||
        validateOtaPackage(tenantId, deviceProfile, deviceProfile.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void validateRuleChain(TenantId tenantId, TenantId deviceProfileTenantId, RuleChainId ruleChainId) {
 | 
			
		||||
        RuleChain ruleChain = ruleChainService.findRuleChainById(tenantId, ruleChainId);
 | 
			
		||||
        if (ruleChain == null) {
 | 
			
		||||
            throw new DataValidationException("Can't assign non-existent rule chain!");
 | 
			
		||||
        }
 | 
			
		||||
        if (!ruleChain.getTenantId().equals(deviceProfileTenantId)) {
 | 
			
		||||
            throw new DataValidationException("Can't assign rule chain from different tenant!");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected DeviceProfile validateUpdate(TenantId tenantId, DeviceProfile deviceProfile) {
 | 
			
		||||
        DeviceProfile old = deviceProfileDao.findById(deviceProfile.getTenantId(), deviceProfile.getId().getId());
 | 
			
		||||
@ -329,8 +338,8 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (serverConfig.getShortServerId() != null) {
 | 
			
		||||
                if (serverConfig.isBootstrapServerIs()){
 | 
			
		||||
                    if(serverConfig.getShortServerId() < 0 || serverConfig.getShortServerId() > 65535){
 | 
			
		||||
                if (serverConfig.isBootstrapServerIs()) {
 | 
			
		||||
                    if (serverConfig.getShortServerId() < 0 || serverConfig.getShortServerId() > 65535) {
 | 
			
		||||
                        throw new DeviceCredentialsValidationException("Bootstrap Server ShortServerId must be in range [0 - 65535]!");
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
@ -423,4 +432,5 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
 | 
			
		||||
    private String getCertificateString(X509Certificate cert) throws CertificateEncodingException {
 | 
			
		||||
        return EncryptionUtil.certTrimNewLines(Base64.getEncoder().encodeToString(cert.getEncoded()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user