增加推流鉴权。保护服务安全

This commit is contained in:
648540858
2022-07-11 16:21:01 +08:00
parent 44b06e1b6e
commit afbec28906
32 changed files with 784 additions and 189 deletions

View File

@@ -3,9 +3,7 @@ package com.genersoft.iot.vmp.storager;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
@@ -213,4 +211,26 @@ public interface IRedisCatchStorage {
*/
public boolean deviceIsOnline(String deviceId);
/**
* 存储推流的鉴权信息
* @param app 应用名
* @param stream 流
* @param streamAuthorityInfo 鉴权信息
*/
void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo);
/**
* 移除推流的鉴权信息
* @param app 应用名
* @param streamId 流
*/
void removeStreamAuthorityInfo(String app, String streamId);
/**
* 获取推流的鉴权信息
* @param app 应用名
* @param stream 流
* @return
*/
StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream);
}

View File

@@ -372,14 +372,16 @@ public interface IVideoManagerStorage {
/**
* 设置流离线
* @param app
* @param streamId
*/
int mediaOutline(String app, String streamId);
int mediaOffline(String app, String streamId);
/**
* 设置流上线
*/
int mediaOnline(String app, String streamId);
/**
* 设置平台在线/离线
* @param online
*/
void updateParentPlatformStatus(String platformGbID, boolean online);

View File

@@ -68,7 +68,7 @@ public interface GbStreamMapper {
List<GbStream> selectAll(String platformId, String catalogId, String query, Boolean pushing, String mediaServerId);
@Select("SELECT * FROM gb_stream WHERE app=#{app} AND stream=#{stream}")
StreamProxyItem selectOne(String app, String stream);
GbStream selectOne(String app, String stream);
@Select("SELECT * FROM gb_stream WHERE gbId=#{gbId}")
List<GbStream> selectByGBId(String gbId);
@@ -88,16 +88,6 @@ public interface GbStreamMapper {
"ON gs.gbStreamId = pgs.gbStreamId WHERE pgs.gbStreamId is NULL")
List<GbStream> queryStreamNotInPlatform();
@Update("UPDATE gb_stream " +
"SET status=${status} " +
"WHERE app=#{app} AND stream=#{stream}")
int setStatus(String app, String stream, boolean status);
@Update("UPDATE gb_stream " +
"SET status=${status} " +
"WHERE mediaServerId=#{mediaServerId} ")
void updateStatusByMediaServerId(String mediaServerId, boolean status);
@Delete("DELETE FROM gb_stream WHERE streamType=#{type} AND gbId=NULL AND mediaServerId=#{mediaServerId}")
void deleteWithoutGBId(String type, String mediaServerId);

View File

@@ -62,12 +62,12 @@ public interface StreamProxyMapper {
@Update("UPDATE stream_proxy " +
"SET status=#{status} " +
"WHERE mediaServerId=#{mediaServerId}")
void updateStatusByMediaServerId(boolean status, String mediaServerId);
void updateStatusByMediaServerId(String mediaServerId, boolean status);
@Update("UPDATE stream_proxy " +
"SET status=${status} " +
"WHERE app=#{app} AND stream=#{stream}")
int updateStatus(boolean status, String app, String stream);
int updateStatus(String app, String stream, boolean status);
@Delete("DELETE FROM stream_proxy WHERE enable_remove_none_reader=true AND mediaServerId=#{mediaServerId}")
void deleteAutoRemoveItemByMediaServerId(String mediaServerId);

View File

@@ -14,21 +14,23 @@ import java.util.List;
public interface StreamPushMapper {
@Insert("INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
"createStamp, aliveSecond, mediaServerId, serverId) VALUES" +
"pushTime, aliveSecond, mediaServerId, serverId, updateTime, createTime) VALUES" +
"('${app}', '${stream}', '${totalReaderCount}', '${originType}', '${originTypeStr}', " +
"'${createStamp}', '${aliveSecond}', '${mediaServerId}' , '${serverId}' )")
"'${pushTime}', '${aliveSecond}', '${mediaServerId}' , '${serverId}' , '${updateTime}' , '${createTime}' )")
int add(StreamPushItem streamPushItem);
@Update("UPDATE stream_push " +
"SET app=#{app}," +
"stream=#{stream}," +
"mediaServerId=#{mediaServerId}," +
"totalReaderCount=#{totalReaderCount}, " +
"originType=#{originType}," +
"originTypeStr=#{originTypeStr}, " +
"createStamp=#{createStamp}, " +
"aliveSecond=#{aliveSecond} " +
"WHERE app=#{app} AND stream=#{stream}")
@Update(value = {" <script>" +
"UPDATE stream_push " +
"SET updateTime='${updateTime}'" +
"<if test=\"mediaServerId != null\">, mediaServerId='${mediaServerId}'</if>" +
"<if test=\"totalReaderCount != null\">, totalReaderCount='${totalReaderCount}'</if>" +
"<if test=\"originType != null\">, originType=${originType}</if>" +
"<if test=\"originTypeStr != null\">, originTypeStr='${originTypeStr}'</if>" +
"<if test=\"pushTime != null\">, pushTime='${pushTime}'</if>" +
"<if test=\"aliveSecond != null\">, aliveSecond='${aliveSecond}'</if>" +
"WHERE app=#{app} AND stream=#{stream}"+
" </script>"})
int update(StreamPushItem streamPushItem);
@Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}")
@@ -62,7 +64,7 @@ public interface StreamPushMapper {
@Select(value = {" <script>" +
"SELECT " +
"st.*, " +
"gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude, gs.gbStreamId " +
"gs.gbId, gs.name, gs.longitude, gs.latitude, gs.gbStreamId " +
"from " +
"stream_push st " +
"LEFT JOIN gb_stream gs " +
@@ -70,25 +72,25 @@ public interface StreamPushMapper {
"WHERE " +
"1=1 " +
" <if test='query != null'> AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " +
" <if test='pushing == true' > AND (gs.gbId is null OR gs.status=1)</if>" +
" <if test='pushing == false' > AND gs.status=0</if>" +
" <if test='pushing == true' > AND (gs.gbId is null OR st.status=1)</if>" +
" <if test='pushing == false' > AND st.status=0</if>" +
" <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" +
"order by st.createStamp desc" +
"order by st.createTime desc" +
" </script>"})
List<StreamPushItem> selectAllForList(String query, Boolean pushing, String mediaServerId);
@Select("SELECT st.*, gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream order by st.createStamp desc")
@Select("SELECT st.*, gs.gbId, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream order by st.createTime desc")
List<StreamPushItem> selectAll();
@Select("SELECT st.*, gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream WHERE st.app=#{app} AND st.stream=#{stream}")
@Select("SELECT st.*, gs.gbId, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream WHERE st.app=#{app} AND st.stream=#{stream}")
StreamPushItem selectOne(String app, String stream);
@Insert("<script>" +
"Insert IGNORE INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
"createStamp, aliveSecond, mediaServerId) " +
"createTime, aliveSecond, mediaServerId) " +
"VALUES <foreach collection='streamPushItems' item='item' index='index' separator=','>" +
"( '${item.app}', '${item.stream}', '${item.totalReaderCount}', #{item.originType}, " +
"'${item.originTypeStr}',#{item.createStamp}, #{item.aliveSecond}, '${item.mediaServerId}' )" +
"'${item.originTypeStr}',#{item.createTime}, #{item.aliveSecond}, '${item.mediaServerId}' )" +
" </foreach>" +
"</script>")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@@ -106,4 +108,13 @@ public interface StreamPushMapper {
@Select("SELECT sp.* FROM stream_push sp left join gb_stream gs on gs.app = sp.app and gs.stream= sp.stream WHERE sp.mediaServerId=#{mediaServerId} and gs.gbId is null")
List<StreamPushItem> selectAllByMediaServerIdWithOutGbID(String mediaServerId);
@Update("UPDATE stream_push " +
"SET status=${status} " +
"WHERE app=#{app} AND stream=#{stream}")
int updateStatus(String app, String stream, boolean status);
@Update("UPDATE stream_push " +
"SET status=#{status} " +
"WHERE mediaServerId=#{mediaServerId}")
void updateStatusByMediaServerId(String mediaServerId, boolean status);
}

View File

@@ -49,4 +49,10 @@ public interface UserMapper {
@Select("select u.*, r.id as roleID, r.name as roleName, r.authority as roleAuthority , r.createTime as roleCreateTime , r.updateTime as roleUpdateTime FROM user u, user_role r WHERE u.roleId=r.id")
@ResultMap(value="roleMap")
List<User> selectAll();
@Select("select * from (select user.*, concat('${callId}_', pushKey) as str1 from user) as u where md5(u.str1) = '${sign}'")
List<User> checkPushAuthorityByCallIdAndSign(String callId, String sign);
@Select("select * from user where md5(pushKey) = '${sign}'")
List<User> checkPushAuthorityByCallId(String sign);
}

View File

@@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam;
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
@@ -20,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
@@ -598,6 +601,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
return result;
}
@Override
public void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream;
redis.set(key, streamAuthorityInfo);
}
@Override
public void removeStreamAuthorityInfo(String app, String stream) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
redis.del(key);
}
@Override
public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
return (StreamAuthorityInfo) redis.get(key);
}
@Override
public MediaItem getStreamInfo(String app, String streamId, String mediaServerId) {
String scanKey = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_*_" + app + "_" + streamId + "_" + mediaServerId;
@@ -682,4 +705,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public boolean deviceIsOnline(String deviceId) {
return getDevice(deviceId).getOnline() == 1;
}
}

View File

@@ -848,7 +848,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
streamPushMapper.addAll(streamPushItems);
// TODO 待优化
for (int i = 0; i < streamPushItems.size(); i++) {
int onlineResult = gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true);
int onlineResult = mediaOnline(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream());
if (onlineResult > 0) {
// 发送上线通知
eventPublisher.catalogEventPublishForStream(null, streamPushItems.get(i), CatalogEvent.ON);
@@ -856,11 +856,13 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
}
@Override
public void updateMedia(StreamPushItem streamPushItem) {
streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream());
streamPushMapper.add(streamPushItem);
gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true);
mediaOffline(streamPushItem.getApp(), streamPushItem.getStream());
if(!StringUtils.isEmpty(streamPushItem.getGbId() )){
// 查找开启了全部直播流共享的上级平台
@@ -897,8 +899,26 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
@Override
public int mediaOutline(String app, String streamId) {
return gbStreamMapper.setStatus(app, streamId, false);
public int mediaOffline(String app, String stream) {
GbStream gbStream = gbStreamMapper.selectOne(app, stream);
int result;
if ("proxy".equals(gbStream.getStreamType())) {
result = streamProxyMapper.updateStatus(app, stream, false);
}else {
result = streamPushMapper.updateStatus(app, stream, false);
}
return result;
}
public int mediaOnline(String app, String stream) {
GbStream gbStream = gbStreamMapper.selectOne(app, stream);
int result;
if ("proxy".equals(gbStream.getStreamType())) {
result = streamProxyMapper.updateStatus(app, stream, true);
}else {
result = streamPushMapper.updateStatus(app, stream, true);
}
return result;
}
@Override