Commit 807d0524a6e965599f9cdbfc7bbf7504c4d9b917
1 parent
06174954
修复推流鉴权
Showing
4 changed files
with
26 additions
and
15 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| @@ -191,13 +191,13 @@ public class ZLMHttpHookListener { | @@ -191,13 +191,13 @@ public class ZLMHttpHookListener { | ||
| 191 | if (userSetting.getPushAuthority()) { | 191 | if (userSetting.getPushAuthority()) { |
| 192 | // 推流鉴权 | 192 | // 推流鉴权 |
| 193 | if (param.getParams() == null) { | 193 | if (param.getParams() == null) { |
| 194 | - logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | 194 | + logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)"); |
| 195 | return new HookResultForOnPublish(401, "Unauthorized"); | 195 | return new HookResultForOnPublish(401, "Unauthorized"); |
| 196 | } | 196 | } |
| 197 | Map<String, String> paramMap = urlParamToMap(param.getParams()); | 197 | Map<String, String> paramMap = urlParamToMap(param.getParams()); |
| 198 | String sign = paramMap.get("sign"); | 198 | String sign = paramMap.get("sign"); |
| 199 | if (sign == null) { | 199 | if (sign == null) { |
| 200 | - logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); | 200 | + logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)"); |
| 201 | return new HookResultForOnPublish(401, "Unauthorized"); | 201 | return new HookResultForOnPublish(401, "Unauthorized"); |
| 202 | } | 202 | } |
| 203 | // 推流自定义播放鉴权码 | 203 | // 推流自定义播放鉴权码 |
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
| @@ -7,8 +7,7 @@ import com.github.pagehelper.PageHelper; | @@ -7,8 +7,7 @@ import com.github.pagehelper.PageHelper; | ||
| 7 | import com.github.pagehelper.PageInfo; | 7 | import com.github.pagehelper.PageInfo; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 10 | -import org.springframework.util.ObjectUtils; | ||
| 11 | -import org.springframework.util.StringUtils; | 10 | +import org.springframework.util.DigestUtils; |
| 12 | 11 | ||
| 13 | import java.util.List; | 12 | import java.util.List; |
| 14 | 13 | ||
| @@ -61,11 +60,23 @@ public class UserServiceImpl implements IUserService { | @@ -61,11 +60,23 @@ public class UserServiceImpl implements IUserService { | ||
| 61 | 60 | ||
| 62 | @Override | 61 | @Override |
| 63 | public boolean checkPushAuthority(String callId, String sign) { | 62 | public boolean checkPushAuthority(String callId, String sign) { |
| 64 | - if (ObjectUtils.isEmpty(callId)) { | ||
| 65 | - return userMapper.checkPushAuthorityByCallId(sign).size() > 0; | ||
| 66 | - }else { | ||
| 67 | - return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0; | 63 | + |
| 64 | + List<User> users = userMapper.getUsers(); | ||
| 65 | + if (users.size() == 0) { | ||
| 66 | + return false; | ||
| 67 | + } | ||
| 68 | + for (User user : users) { | ||
| 69 | + if (user.getPushKey() == null) { | ||
| 70 | + continue; | ||
| 71 | + } | ||
| 72 | + String checkStr = callId == null? user.getPushKey():(callId + "_" + user.getPushKey()) ; | ||
| 73 | + System.out.println(checkStr); | ||
| 74 | + String checkSign = DigestUtils.md5DigestAsHex(checkStr.getBytes()); | ||
| 75 | + if (checkSign.equals(sign)) { | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 68 | } | 78 | } |
| 79 | + return false; | ||
| 69 | } | 80 | } |
| 70 | 81 | ||
| 71 | @Override | 82 | @Override |
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
| @@ -13,9 +13,9 @@ import java.util.List; | @@ -13,9 +13,9 @@ import java.util.List; | ||
| 13 | public interface StreamPushMapper { | 13 | public interface StreamPushMapper { |
| 14 | 14 | ||
| 15 | @Insert("INSERT INTO wvp_stream_push (app, stream, total_reader_count, origin_type, origin_type_str, " + | 15 | @Insert("INSERT INTO wvp_stream_push (app, stream, total_reader_count, origin_type, origin_type_str, " + |
| 16 | - "push_time, alive_second, media_server_id, server_id, update_time, create_time, push_ing, self) VALUES" + | 16 | + "push_time, alive_second, media_server_id, update_time, create_time, push_ing, self) VALUES" + |
| 17 | "(#{app}, #{stream}, #{totalReaderCount}, #{originType}, #{originTypeStr}, " + | 17 | "(#{app}, #{stream}, #{totalReaderCount}, #{originType}, #{originTypeStr}, " + |
| 18 | - "#{pushTime}, #{aliveSecond}, #{mediaServerId} , #{serverId} , #{updateTime} , #{createTime}, " + | 18 | + "#{pushTime}, #{aliveSecond}, #{mediaServerId} , #{updateTime} , #{createTime}, " + |
| 19 | "#{pushIng}, #{self} )") | 19 | "#{pushIng}, #{self} )") |
| 20 | int add(StreamPushItem streamPushItem); | 20 | int add(StreamPushItem streamPushItem); |
| 21 | 21 |
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
| @@ -50,11 +50,11 @@ public interface UserMapper { | @@ -50,11 +50,11 @@ public interface UserMapper { | ||
| 50 | @ResultMap(value="roleMap") | 50 | @ResultMap(value="roleMap") |
| 51 | List<User> selectAll(); | 51 | List<User> selectAll(); |
| 52 | 52 | ||
| 53 | - @Select("select * from (select user.*, concat(concat(#{call_id}, '_'), push_key) as str1 from wvp_user) as u where md5(u.str1) = #{sign}") | ||
| 54 | - List<User> checkPushAuthorityByCallIdAndSign(String callId, String sign); | ||
| 55 | - | ||
| 56 | - @Select("select * from wvp_user where md5(push_key) = #{sign}") | ||
| 57 | - List<User> checkPushAuthorityByCallId(String sign); | 53 | +// @Select("select * from (select user.*, concat(concat(#{call_id}, '_'), push_key) as str1 from wvp_user) as u where md5(u.str1) = #{sign}") |
| 54 | +// List<User> checkPushAuthorityByCallIdAndSign(String callId, String sign); | ||
| 55 | +// | ||
| 56 | +// @Select("select * from wvp_user where md5(push_key) = #{sign}") | ||
| 57 | +// List<User> checkPushAuthorityByCallId(String sign); | ||
| 58 | 58 | ||
| 59 | @Select("select u.id, u.username,u.push_key,u.role_id, r.id as role_id, r.name as role_name, r.authority as role_authority , r.create_time as role_create_time , r.update_time as role_update_time from wvp_user u join wvp_user_role r on u.role_id=r.id") | 59 | @Select("select u.id, u.username,u.push_key,u.role_id, r.id as role_id, r.name as role_name, r.authority as role_authority , r.create_time as role_create_time , r.update_time as role_update_time from wvp_user u join wvp_user_role r on u.role_id=r.id") |
| 60 | @ResultMap(value="roleMap") | 60 | @ResultMap(value="roleMap") |