认证匹配加密认证和简单认证

This commit is contained in:
kerwincui
2022-06-05 13:07:32 +08:00
parent 4632e69def
commit ed1401ccb8
3 changed files with 20 additions and 1 deletions

View File

@@ -37,6 +37,16 @@ public class ProductAuthenticateModel {
/** 产品秘钥 */
private String mqttSecret;
private int vertificateMethod;
public int getVertificateMethod() {
return vertificateMethod;
}
public void setVertificateMethod(int vertificateMethod) {
this.vertificateMethod = vertificateMethod;
}
public Integer getIsAuthorize() {
return isAuthorize;
}

View File

@@ -200,6 +200,10 @@ public class ToolServiceImpl implements IToolService
*/
@Override
public ResponseEntity simpleMqttAuthentication(MqttAuthenticationModel mqttModel, ProductAuthenticateModel productModel) {
// 1=简单认证2=加密认证3=简单+加密认证
if(productModel.getVertificateMethod()!=1 && productModel.getVertificateMethod()!=3){
return returnUnauthorized(mqttModel, "设备简单认证,设备对应产品不支持简单认证");
}
String[] passwordArray = mqttModel.getPassword().split("&");
if (productModel.getIsAuthorize() == 1 && passwordArray.length != 2) {
return returnUnauthorized(mqttModel, "设备简单认证,产品启用授权码后,密码格式为:密码 & 授权码");
@@ -242,6 +246,10 @@ public class ToolServiceImpl implements IToolService
*/
@Override
public ResponseEntity encryptAuthentication(MqttAuthenticationModel mqttModel, ProductAuthenticateModel productModel) throws Exception {
// 1=简单认证2=加密认证3=简单+加密认证
if(productModel.getVertificateMethod()!=2 && productModel.getVertificateMethod()!=3){
return returnUnauthorized(mqttModel, "设备加密认证,设备对应产品不支持加密认证");
}
String decryptPassword = AESUtils.decrypt(mqttModel.getPassword(), productModel.getMqttSecret());
if (decryptPassword == null || decryptPassword.equals("")) {
return returnUnauthorized(mqttModel, "设备加密认证mqtt密码解密失败");

View File

@@ -80,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="mqttAccount" column="mqtt_account" />
<result property="mqttPassword" column="mqtt_password" />
<result property="mqttSecret" column="mqtt_secret" />
<result property="vertificateMethod" column="vertificate_method" />
</resultMap>
<resultMap type="com.ruoyi.iot.model.ThingsModels.ThingsModelValuesOutput" id="DeviceThingsValueResult">
@@ -171,7 +172,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectProductAuthenticate" parameterType="com.ruoyi.iot.model.AuthenticateInputModel" resultMap="DeviceAuthenticateResult">
SELECT p.mqtt_password,p.mqtt_account, p.mqtt_secret,p.is_authorize,p.product_id,p.product_name,p.STATUS as product_status,d.device_id,d.device_name,d.STATUS,d.serial_number
SELECT p.mqtt_password,p.mqtt_account, p.mqtt_secret,p.is_authorize,p.product_id,p.product_name,p.vertificate_method,p.STATUS as product_status,d.device_id,d.device_name,d.STATUS,d.serial_number
FROM iot_product p
LEFT JOIN ( SELECT device_id, device_name, STATUS, product_id, product_name, serial_number
FROM iot_device