Commit cc4c4ac144600d08d53dcbb97d24fc2186c34a50
1 parent
73c7dab4
支持配置是否开去推流鉴权
Showing
3 changed files
with
50 additions
and
36 deletions
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
| @@ -35,6 +35,8 @@ public class UserSetting { | @@ -35,6 +35,8 @@ public class UserSetting { | ||
| 35 | 35 | ||
| 36 | private Boolean streamOnDemand = Boolean.TRUE; | 36 | private Boolean streamOnDemand = Boolean.TRUE; |
| 37 | 37 | ||
| 38 | + private Boolean pushAuthority = Boolean.TRUE; | ||
| 39 | + | ||
| 38 | private String serverId = "000000"; | 40 | private String serverId = "000000"; |
| 39 | 41 | ||
| 40 | private String thirdPartyGBIdReg = "[\\s\\S]*"; | 42 | private String thirdPartyGBIdReg = "[\\s\\S]*"; |
| @@ -156,4 +158,12 @@ public class UserSetting { | @@ -156,4 +158,12 @@ public class UserSetting { | ||
| 156 | public void setStreamOnDemand(Boolean streamOnDemand) { | 158 | public void setStreamOnDemand(Boolean streamOnDemand) { |
| 157 | this.streamOnDemand = streamOnDemand; | 159 | this.streamOnDemand = streamOnDemand; |
| 158 | } | 160 | } |
| 161 | + | ||
| 162 | + public Boolean getPushAuthority() { | ||
| 163 | + return pushAuthority; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public void setPushAuthority(Boolean pushAuthority) { | ||
| 167 | + this.pushAuthority = pushAuthority; | ||
| 168 | + } | ||
| 159 | } | 169 | } |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| @@ -183,42 +183,45 @@ public class ZLMHttpHookListener { | @@ -183,42 +183,45 @@ public class ZLMHttpHookListener { | ||
| 183 | JSONObject ret = new JSONObject(); | 183 | JSONObject ret = new JSONObject(); |
| 184 | String mediaServerId = json.getString("mediaServerId"); | 184 | String mediaServerId = json.getString("mediaServerId"); |
| 185 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); | 185 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 186 | + | ||
| 186 | if (!"rtp".equals(param.getApp())) { | 187 | if (!"rtp".equals(param.getApp())) { |
| 187 | - // 推流鉴权 | ||
| 188 | - if (param.getParams() == null) { | ||
| 189 | - logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | ||
| 190 | - ret.put("code", 401); | ||
| 191 | - ret.put("msg", "Unauthorized"); | ||
| 192 | - return ret; | ||
| 193 | - } | ||
| 194 | - Map<String, String> paramMap = urlParamToMap(param.getParams()); | ||
| 195 | - String sign = paramMap.get("sign"); | ||
| 196 | - if (sign == null) { | ||
| 197 | - logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | ||
| 198 | - ret.put("code", 401); | ||
| 199 | - ret.put("msg", "Unauthorized"); | ||
| 200 | - return ret; | ||
| 201 | - } | ||
| 202 | - // 推流自定义播放鉴权码 | ||
| 203 | - String callId = paramMap.get("callId"); | ||
| 204 | - // 鉴权配置 | ||
| 205 | - boolean hasAuthority = userService.checkPushAuthority(callId, sign); | ||
| 206 | - if (!hasAuthority) { | ||
| 207 | - logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign); | ||
| 208 | - ret.put("code", 401); | ||
| 209 | - ret.put("msg", "Unauthorized"); | ||
| 210 | - return ret; | ||
| 211 | - } | ||
| 212 | - StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param); | ||
| 213 | - streamAuthorityInfo.setCallId(callId); | ||
| 214 | - streamAuthorityInfo.setSign(sign); | ||
| 215 | - // 鉴权通过 | ||
| 216 | - redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo); | ||
| 217 | - // 通知assist新的callId | ||
| 218 | - if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) { | ||
| 219 | - taskExecutor.execute(()->{ | ||
| 220 | - assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); | ||
| 221 | - }); | 188 | + if (userSetting.getPushAuthority()) { |
| 189 | +// 推流鉴权 | ||
| 190 | + if (param.getParams() == null) { | ||
| 191 | + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | ||
| 192 | + ret.put("code", 401); | ||
| 193 | + ret.put("msg", "Unauthorized"); | ||
| 194 | + return ret; | ||
| 195 | + } | ||
| 196 | + Map<String, String> paramMap = urlParamToMap(param.getParams()); | ||
| 197 | + String sign = paramMap.get("sign"); | ||
| 198 | + if (sign == null) { | ||
| 199 | + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | ||
| 200 | + ret.put("code", 401); | ||
| 201 | + ret.put("msg", "Unauthorized"); | ||
| 202 | + return ret; | ||
| 203 | + } | ||
| 204 | + // 推流自定义播放鉴权码 | ||
| 205 | + String callId = paramMap.get("callId"); | ||
| 206 | + // 鉴权配置 | ||
| 207 | + boolean hasAuthority = userService.checkPushAuthority(callId, sign); | ||
| 208 | + if (!hasAuthority) { | ||
| 209 | + logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign); | ||
| 210 | + ret.put("code", 401); | ||
| 211 | + ret.put("msg", "Unauthorized"); | ||
| 212 | + return ret; | ||
| 213 | + } | ||
| 214 | + StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param); | ||
| 215 | + streamAuthorityInfo.setCallId(callId); | ||
| 216 | + streamAuthorityInfo.setSign(sign); | ||
| 217 | + // 鉴权通过 | ||
| 218 | + redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo); | ||
| 219 | + // 通知assist新的callId | ||
| 220 | + if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) { | ||
| 221 | + taskExecutor.execute(()->{ | ||
| 222 | + assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); | ||
| 223 | + }); | ||
| 224 | + } | ||
| 222 | } | 225 | } |
| 223 | }else { | 226 | }else { |
| 224 | zlmMediaListManager.sendStreamEvent(param.getApp(),param.getStream(), param.getMediaServerId()); | 227 | zlmMediaListManager.sendStreamEvent(param.getApp(),param.getStream(), param.getMediaServerId()); |
| @@ -226,7 +229,6 @@ public class ZLMHttpHookListener { | @@ -226,7 +229,6 @@ public class ZLMHttpHookListener { | ||
| 226 | 229 | ||
| 227 | ret.put("code", 0); | 230 | ret.put("code", 0); |
| 228 | ret.put("msg", "success"); | 231 | ret.put("msg", "success"); |
| 229 | - ret.put("enable_hls", false); | ||
| 230 | 232 | ||
| 231 | if (!"rtp".equals(param.getApp())) { | 233 | if (!"rtp".equals(param.getApp())) { |
| 232 | ret.put("enable_audio", true); | 234 | ret.put("enable_audio", true); |
src/main/resources/all-application.yml
| @@ -190,6 +190,8 @@ user-settings: | @@ -190,6 +190,8 @@ user-settings: | ||
| 190 | use-pushing-as-status: true | 190 | use-pushing-as-status: true |
| 191 | # 按需拉流, true:有人观看拉流,无人观看释放, false:拉起后不自动释放 | 191 | # 按需拉流, true:有人观看拉流,无人观看释放, false:拉起后不自动释放 |
| 192 | stream-on-demand: true | 192 | stream-on-demand: true |
| 193 | + # 推流鉴权, 默认开启 | ||
| 194 | + push-authority: true | ||
| 193 | 195 | ||
| 194 | # 关闭在线文档(生产环境建议关闭) | 196 | # 关闭在线文档(生产环境建议关闭) |
| 195 | springdoc: | 197 | springdoc: |