Просмотр исходного кода

支持配置是否开去推流鉴权

648540858 3 лет назад
Родитель
Сommit
cc4c4ac144

+ 10 - 0
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java

@@ -35,6 +35,8 @@ public class UserSetting {
 
     private Boolean streamOnDemand = Boolean.TRUE;
 
+    private Boolean pushAuthority = Boolean.TRUE;
+
     private String serverId = "000000";
 
     private String thirdPartyGBIdReg = "[\\s\\S]*";
@@ -156,4 +158,12 @@ public class UserSetting {
     public void setStreamOnDemand(Boolean streamOnDemand) {
         this.streamOnDemand = streamOnDemand;
     }
+
+    public Boolean getPushAuthority() {
+        return pushAuthority;
+    }
+
+    public void setPushAuthority(Boolean pushAuthority) {
+        this.pushAuthority = pushAuthority;
+    }
 }

+ 38 - 36
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java

@@ -183,42 +183,45 @@ public class ZLMHttpHookListener {
 		JSONObject ret = new JSONObject();
 		String mediaServerId = json.getString("mediaServerId");
 		MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
+
 		if (!"rtp".equals(param.getApp())) {
-			// 推流鉴权
-			if (param.getParams() == null) {
-				logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
-				ret.put("code", 401);
-				ret.put("msg", "Unauthorized");
-				return ret;
-			}
-			Map<String, String> paramMap = urlParamToMap(param.getParams());
-			String sign = paramMap.get("sign");
-			if (sign == null) {
-				logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
-				ret.put("code", 401);
-				ret.put("msg", "Unauthorized");
-				return ret;
-			}
-			// 推流自定义播放鉴权码
-			String callId = paramMap.get("callId");
-			// 鉴权配置
-			boolean hasAuthority = userService.checkPushAuthority(callId, sign);
-			if (!hasAuthority) {
-				logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign);
-				ret.put("code", 401);
-				ret.put("msg", "Unauthorized");
-				return ret;
-			}
-			StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
-			streamAuthorityInfo.setCallId(callId);
-			streamAuthorityInfo.setSign(sign);
-			// 鉴权通过
-			redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
-			// 通知assist新的callId
-			if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) {
-				taskExecutor.execute(()->{
-					assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null);
-				});
+			if (userSetting.getPushAuthority()) {
+// 推流鉴权
+				if (param.getParams() == null) {
+					logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
+					ret.put("code", 401);
+					ret.put("msg", "Unauthorized");
+					return ret;
+				}
+				Map<String, String> paramMap = urlParamToMap(param.getParams());
+				String sign = paramMap.get("sign");
+				if (sign == null) {
+					logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
+					ret.put("code", 401);
+					ret.put("msg", "Unauthorized");
+					return ret;
+				}
+				// 推流自定义播放鉴权码
+				String callId = paramMap.get("callId");
+				// 鉴权配置
+				boolean hasAuthority = userService.checkPushAuthority(callId, sign);
+				if (!hasAuthority) {
+					logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign);
+					ret.put("code", 401);
+					ret.put("msg", "Unauthorized");
+					return ret;
+				}
+				StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
+				streamAuthorityInfo.setCallId(callId);
+				streamAuthorityInfo.setSign(sign);
+				// 鉴权通过
+				redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
+				// 通知assist新的callId
+				if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) {
+					taskExecutor.execute(()->{
+						assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null);
+					});
+				}
 			}
 		}else {
 			zlmMediaListManager.sendStreamEvent(param.getApp(),param.getStream(), param.getMediaServerId());
@@ -226,7 +229,6 @@ public class ZLMHttpHookListener {
 
 		ret.put("code", 0);
 		ret.put("msg", "success");
-		ret.put("enable_hls", false);
 
 		if (!"rtp".equals(param.getApp())) {
 			ret.put("enable_audio", true);

+ 2 - 0
src/main/resources/all-application.yml

@@ -190,6 +190,8 @@ user-settings:
     use-pushing-as-status: true
     # 按需拉流, true:有人观看拉流,无人观看释放, false:拉起后不自动释放
     stream-on-demand: true
+    # 推流鉴权, 默认开启
+    push-authority: true
 
 # 关闭在线文档(生产环境建议关闭)
 springdoc: