diff --git a/src/main/java/com/genersoft/iot/vmp/media/abl/bean/AblServerConfig.java b/src/main/java/com/genersoft/iot/vmp/media/abl/bean/AblServerConfig.java index 5b6f0fb0..dc0edecd 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/abl/bean/AblServerConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/media/abl/bean/AblServerConfig.java @@ -126,6 +126,9 @@ public class AblServerConfig { @ConfigKeyId("on_stream_disconnect") private String onStreamDisconnect; + @ConfigKeyId("on_stream_not_found") + private String onStreamNotFound; + @ConfigKeyId("on_record_mp4") private String onRecordMp4; @@ -798,4 +801,12 @@ public class AblServerConfig { public void setPictureMaxCount(Integer pictureMaxCount) { this.pictureMaxCount = pictureMaxCount; } + + public String getOnStreamNotFound() { + return onStreamNotFound; + } + + public void setOnStreamNotFound(String onStreamNotFound) { + this.onStreamNotFound = onStreamNotFound; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index a247a78b..b8f6f2f1 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -139,7 +139,6 @@ public class ZLMHttpHookListener { * 服务器定时上报时间,上报间隔可配置,默认10s上报一次 */ @ResponseBody - @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { try { @@ -164,25 +163,11 @@ public class ZLMHttpHookListener { if (logger.isDebugEnabled()) { logger.debug("[ZLM HOOK] 播放鉴权:{}->{}", param.getMediaServerId(), param); } - String mediaServerId = param.getMediaServerId(); - - taskExecutor.execute(() -> { - JSONObject json = (JSONObject) JSON.toJSON(param); - ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_play, json); - if (subscribe != null) { - MediaServer mediaInfo = mediaServerService.getOne(mediaServerId); - if (mediaInfo != null) { - subscribe.response(mediaInfo, param); - } - } - }); - // TODO 此处逻辑适合迁移到MediaService中 - if (!"rtp".equals(param.getApp())) { - Map paramMap = urlParamToMap(param.getParams()); - StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream()); - if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) { - return new HookResult(401, "Unauthorized"); - } + Map paramMap = urlParamToMap(param.getParams()); + // 对于播放流进行鉴权 + boolean authenticateResult = mediaService.authenticatePlay(param.getApp(), param.getStream(), paramMap.get("callId")); + if (!authenticateResult) { + return new HookResult(401, "Unauthorized"); } return HookResult.SUCCESS(); @@ -215,12 +200,14 @@ public class ZLMHttpHookListener { return result; } if (userSetting.getPushAuthority()) { + // 对于推流进行鉴权 + Map paramMap = urlParamToMap(param.getParams()); // 推流鉴权 if (param.getParams() == null) { logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)"); return new HookResultForOnPublish(401, "Unauthorized"); } - Map paramMap = urlParamToMap(param.getParams()); + String sign = paramMap.get("sign"); if (sign == null) { logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)"); @@ -648,12 +635,6 @@ public class ZLMHttpHookListener { } return ret; } - // TODO 推流具有主动性,暂时不做处理 -// StreamPushItem streamPushItem = streamPushService.getPush(app, streamId); -// if (streamPushItem != null) { -// // TODO 发送停止 -// -// } } return ret; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java index 338814c5..9230b353 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java @@ -41,4 +41,11 @@ public interface IMediaService { * @return */ StreamInfo getStreamInfoByAppAndStream(MediaServer mediaServerItem, String app, String stream, MediaInfo mediaInfo, String addr, String callId, boolean isPlay); + + /** + * 播放鉴权 + */ + boolean authenticatePlay(String app, String stream, String callId); + + boolean authenticatePublish(String app, String stream, String callId, String sign); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 07a28a3b..9c54068f 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -4,10 +4,14 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.MediaConfig; import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.service.IMediaServerService; +import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookListener; import com.genersoft.iot.vmp.media.zlm.dto.MediaServer; import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo; +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookResultForOnPublish; import com.genersoft.iot.vmp.service.IMediaService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; @@ -17,6 +21,8 @@ import java.util.List; @Service public class MediaServiceImpl implements IMediaService { + private final static Logger logger = LoggerFactory.getLogger(MediaServiceImpl.class); + @Autowired private IRedisCatchStorage redisCatchStorage; @@ -85,4 +91,16 @@ public class MediaServiceImpl implements IMediaService { streamInfoResult.setMediaInfo(mediaInfo); return streamInfoResult; } + + @Override + public boolean authenticatePlay(String app, String stream, String callId) { + if (app == null || stream == null) { + return false; + } + if ("rtp".equals(app)) { + return true; + } + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + return (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(callId)); + } }