Browse Source

规范配置文件,添加接口鉴权的例外接口配置

pull/129/head
64850858 3 years ago
parent
commit
0faa593658
  1. 5
      pom.xml
  2. 28
      src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
  3. 6
      src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
  4. 118
      src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java
  5. 7
      src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java
  6. 15
      src/main/java/com/genersoft/iot/vmp/service/IMediaService.java
  7. 37
      src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
  8. 33
      src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java
  9. 53
      src/main/resources/all-application.yml
  10. 26
      src/main/resources/application-dev.yml
  11. 18713
      web_src/package-lock.json

5
pom.xml

@ -65,6 +65,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>

28
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java

@ -10,55 +10,55 @@ public class MediaConfig {
@Value("${media.ip}")
private String ip;
@Value("${media.hookIp:${sip.ip}}")
@Value("${media.hook-ip:${sip.ip}}")
private String hookIp;
@Value("${sip.ip}")
private String sipIp;
@Value("${media.sdpIp:${media.ip}}")
@Value("${media.sdp-ip:${media.ip}}")
private String sdpIp;
@Value("${media.streamIp:${media.ip}}")
@Value("${media.stream-ip:${media.ip}}")
private String streamIp;
@Value("${media.httpPort}")
@Value("${media.http-port}")
private Integer httpPort;
@Value("${media.httpSSlPort:}")
@Value("${media.http-ssl-port:}")
private Integer httpSSlPort;
@Value("${media.rtmpPort:}")
@Value("${media.rtmp-port:}")
private Integer rtmpPort;
@Value("${media.rtmpSSlPort:}")
@Value("${media.rtmp-ssl-port:}")
private Integer rtmpSSlPort;
@Value("${media.rtpProxyPort:}")
@Value("${media.rtp-proxy-port:}")
private Integer rtpProxyPort;
@Value("${media.rtspPort:}")
@Value("${media.rtsp-port:}")
private Integer rtspPort;
@Value("${media.rtspSSLPort:}")
@Value("${media.rtsp-ssl-port:}")
private Integer rtspSSLPort;
@Value("${media.autoConfig:true}")
@Value("${media.auto-config:true}")
private boolean autoConfig;
@Value("${media.secret}")
private String secret;
@Value("${media.streamNoneReaderDelayMS:18000}")
@Value("${media.stream-none-reader-delay-ms:18000}")
private String streamNoneReaderDelayMS;
@Value("${media.rtp.enable}")
private boolean rtpEnable;
@Value("${media.rtp.portRange}")
@Value("${media.rtp.port-range}")
private String rtpPortRange;
@Value("${media.recordAssistPort}")
@Value("${media.record-assist-port}")
private Integer recordAssistPort;
public String getIp() {

6
src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java

@ -13,7 +13,7 @@ public class SipConfig {
/**
* 默认使用sip.ip
*/
@Value("${sip.monitorIp:0.0.0.0}")
@Value("${sip.monitor-ip:0.0.0.0}")
private String monitorIp;
@Value("${sip.port}")
@ -31,10 +31,10 @@ public class SipConfig {
@Value("${sip.ptz.speed:50}")
Integer speed;
@Value("${sip.keepaliveTimeOut:180}")
@Value("${sip.keepalive-timeout:180}")
Integer keepaliveTimeOut;
@Value("${sip.registerTimeInterval:60}")
@Value("${sip.register-time-interval:60}")
Integer registerTimeInterval;
public String getMonitorIp() {

118
src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java

@ -1,60 +1,130 @@
package com.genersoft.iot.vmp.conf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration("userSetup")
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
//@Configuration("userSetup")
//public class UserSetup {
// @Value("${userSettings.savePositionHistory:false}")
// boolean savePositionHistory;
//
// @Value("${userSettings.autoApplyPlay}")
// private boolean autoApplyPlay;
//
// @Value("${userSettings.seniorSdp:false}")
// private boolean seniorSdp;
//
// @Value("${userSettings.playTimeout:18000}")
// private long playTimeout;
//
// @Value("${userSettings.waitTrack:false}")
// private boolean waitTrack;
//
// @Value("${userSettings.interfaceAuthentication}")
// private boolean interfaceAuthentication;
//
// @Value("${userSettings.recordPushLive}")
// private boolean recordPushLive;
//
// @Value("${userSettings.interfaceAuthenticationExcludes:}")
// private String interfaceAuthenticationExcludes;
//
// public boolean getSavePositionHistory() {
// return savePositionHistory;
// }
//
// public boolean isSavePositionHistory() {
// return savePositionHistory;
// }
//
// public boolean isAutoApplyPlay() {
// return autoApplyPlay;
// }
//
// public boolean isSeniorSdp() {
// return seniorSdp;
// }
//
// public long getPlayTimeout() {
// return playTimeout;
// }
//
// public boolean isWaitTrack() {
// return waitTrack;
// }
//
// public boolean isInterfaceAuthentication() {
// return interfaceAuthentication;
// }
//
// public boolean isRecordPushLive() {
// return recordPushLive;
// }
//
// public String getInterfaceAuthenticationExcludes() {
// return interfaceAuthenticationExcludes;
// }
//}
@Component
@ConfigurationProperties(prefix = "user-settings", ignoreInvalidFields = true)
public class UserSetup {
@Value("${userSettings.savePositionHistory:false}")
boolean savePositionHistory;
@Value("${userSettings.autoApplyPlay}")
private boolean autoApplyPlay;
private Boolean savePositionHistory = Boolean.FALSE;
private Boolean autoApplyPlay = Boolean.FALSE;
private Boolean seniorSdp = Boolean.FALSE;
@Value("${userSettings.seniorSdp:false}")
private boolean seniorSdp;
private Long playTimeout = 18000L;
@Value("${userSettings.playTimeout:18000}")
private long playTimeout;
private Boolean waitTrack = Boolean.FALSE;
@Value("${userSettings.waitTrack:false}")
private boolean waitTrack;
private Boolean interfaceAuthentication = Boolean.TRUE;
@Value("${userSettings.interfaceAuthentication}")
private boolean interfaceAuthentication;
private Boolean recordPushLive = Boolean.FALSE;
@Value("${userSettings.recordPushLive}")
private boolean recordPushLive;
private List<String> interfaceAuthenticationExcludes = new ArrayList<>();
public boolean getSavePositionHistory() {
public Boolean getSavePositionHistory() {
return savePositionHistory;
}
public boolean isSavePositionHistory() {
public Boolean isSavePositionHistory() {
return savePositionHistory;
}
public boolean isAutoApplyPlay() {
public Boolean isAutoApplyPlay() {
return autoApplyPlay;
}
public boolean isSeniorSdp() {
public Boolean isSeniorSdp() {
return seniorSdp;
}
public long getPlayTimeout() {
public Long getPlayTimeout() {
return playTimeout;
}
public boolean isWaitTrack() {
public Boolean isWaitTrack() {
return waitTrack;
}
public boolean isInterfaceAuthentication() {
public Boolean isInterfaceAuthentication() {
return interfaceAuthentication;
}
public boolean isRecordPushLive() {
public Boolean isRecordPushLive() {
return recordPushLive;
}
public List<String> getInterfaceAuthenticationExcludes() {
return interfaceAuthenticationExcludes;
}
}

7
src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java

@ -14,6 +14,8 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.List;
/**
* 配置Spring Security
*/
@ -85,6 +87,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/swagger-resources/**")
.antMatchers("/v3/api-docs/**")
.antMatchers("/js/**");
List<String> interfaceAuthenticationExcludes = userSetup.getInterfaceAuthenticationExcludes();
System.out.println(interfaceAuthenticationExcludes.size());
for (String interfaceAuthenticationExclude : interfaceAuthenticationExcludes) {
web.ignoring().antMatchers(interfaceAuthenticationExclude);
}
}
}

15
src/main/java/com/genersoft/iot/vmp/service/IMediaService.java

@ -24,4 +24,19 @@ public interface IMediaService {
*/
StreamInfo getStreamInfoByAppAndStream(String app, String stream, JSONArray tracks);
/**
* 根据应用名和流ID获取播放地址, 只是地址拼接返回的ip使用远程访问ip适用与zlm与wvp在一台主机的情况
* @param app
* @param stream
* @return
*/
StreamInfo getStreamInfoByAppAndStream(String app, String stream, JSONArray tracks, String addr);
/**
* 根据应用名和流ID获取播放地址, 通过zlm接口检查是否存在, 返回的ip使用远程访问ip适用与zlm与wvp在一台主机的情况
* @param app
* @param stream
* @return
*/
StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String addr);
}

37
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java

@ -28,27 +28,40 @@ public class MediaServiceImpl implements IMediaService {
@Override
public StreamInfo getStreamInfoByAppAndStream(String app, String stream, JSONArray tracks) {
return getStreamInfoByAppAndStream(app, stream, tracks, null);
}
@Override
public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream) {
return getStreamInfoByAppAndStreamWithCheck(app, stream, null);
}
@Override
public StreamInfo getStreamInfoByAppAndStream(String app, String stream, JSONArray tracks, String addr) {
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
StreamInfo streamInfoResult = new StreamInfo();
streamInfoResult.setStreamId(stream);
streamInfoResult.setApp(app);
streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", mediaInfo.getStreamIp(), mediaInfo.getRtmpPort(), app, stream));
streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", mediaInfo.getStreamIp(), mediaInfo.getRtspPort(), app, stream));
streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.flv", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.flv", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
if (addr == null) {
addr = mediaInfo.getStreamIp();
}
streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", addr, mediaInfo.getRtmpPort(), app, stream));
streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", addr, mediaInfo.getRtspPort(), app, stream));
streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.flv", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.flv", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setRtc(String.format("http://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream));
streamInfoResult.setTracks(tracks);
return streamInfoResult;
}
@Override
public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream) {
public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String addr) {
StreamInfo streamInfo = null;
JSONObject mediaList = zlmresTfulUtils.getMediaList(app, stream);
if (mediaList != null) {
@ -57,7 +70,7 @@ public class MediaServiceImpl implements IMediaService {
if (data == null) return null;
JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class);
JSONArray tracks = mediaJSON.getJSONArray("tracks");
streamInfo = getStreamInfoByAppAndStream(app, stream, tracks);
streamInfo = getStreamInfoByAppAndStream(app, stream, tracks, addr);
}
}
return streamInfo;

33
src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java

@ -0,0 +1,33 @@
package com.genersoft.iot.vmp.web;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@CrossOrigin
@RestController
public class ApiCompatibleController {
private final static Logger logger = LoggerFactory.getLogger(ApiCompatibleController.class);
@Autowired
private IMediaService mediaService;
@GetMapping(value = "/api/v1/stream_info_by_app_and_stream")
@ResponseBody
public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, @RequestParam String stream){
String localAddr = request.getLocalAddr();
StreamInfo streamINfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, localAddr);
WVPResult<StreamInfo> wvpResult = new WVPResult<>();
wvpResult.setCode(0);
wvpResult.setMsg("success");
wvpResult.setData(streamINfo);
return wvpResult;
}
}

53
src/main/resources/all-application.yml

@ -52,7 +52,7 @@ server:
# 作为28181服务器的配置
sip:
# [必须修改] 本机的IP, 必须是网卡上的IP,用于sip下协议栈监听ip,如果监听所有设置为0.0.0.0
monitorIp: 0.0.0.0
monitor-ip: 0.0.0.0
# [必须修改] 本机的IP
ip: 192.168.0.100
# [可选] 28181服务监听的端口
@ -67,48 +67,48 @@ sip:
# [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验
password: admin123
# [可选] 心跳超时时间, 建议设置为心跳周期的三倍
keepaliveTimeOut: 180
keepalive-timeout: 180
# [可选] 国标级联注册失败,再次发起注册的时间间隔。 默认60秒
registerTimeInterval: 60
register-time-interval: 60
#zlm 默认服务器配置
media:
# [必须修改] zlm服务器的内网IP
ip: 192.168.0.100
# [可选] 返回流地址时的ip,置空使用 media.ip
streamIp:
stream-ip:
# [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip
sdpIp:
sdp-ip:
# [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip
hookIp:
hook-ip:
# [必须修改] zlm服务器的http.port
httpPort: 80
http-port: 80
# [可选] zlm服务器的http.sslport, 置空使用zlm配置文件配置
httpSSlPort:
http-ssl-port:
# [可选] zlm服务器的rtmp.port, 置空使用zlm配置文件配置
rtmpPort:
rtmp-port:
# [可选] zlm服务器的rtmp.sslport, 置空使用zlm配置文件配置
rtmpSSlPort:
rtmp-ssl-port:
# [可选] zlm服务器的 rtp_proxy.port, 置空使用zlm配置文件配置
rtpProxyPort:
rtp-proxy-port:
# [可选] zlm服务器的 rtsp.port, 置空使用zlm配置文件配置
rtspPort:
rtsp-port:
# [可选] zlm服务器的 rtsp.sslport, 置空使用zlm配置文件配置
rtspSSLPort:
rtsp-ssl-port:
# [可选] 是否自动配置ZLM, 如果希望手动配置ZLM, 可以设为false, 不建议新接触的用户修改
autoConfig: true
auto-config: true
# [可选] zlm服务器的hook.admin_params=secret
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
# [可选] zlm服务器的general.streamNoneReaderDelayMS
streamNoneReaderDelayMS: 18000 # 无人观看多久自动关闭流, -1表示永不自动关闭,即 关闭按需拉流
stream-none-reader-delay-ms: 18000 # 无人观看多久自动关闭流, -1表示永不自动关闭,即 关闭按需拉流
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
rtp:
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
enable: true
# [可选] 在此范围内选择端口用于媒体流传输,
portRange: 30000,30500 # 端口范围
port-range: 30000,30500 # 端口范围
# 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载, 0 表示不使用
recordAssistPort: 0
record-assist-port: 0
# [可选] 日志配置, 一般不需要改
logging:
@ -122,21 +122,24 @@ logging:
genersoft:
iot: info
# [根据业务需求配置]
userSettings:
user-settings:
# [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true
autoApplyPlay: false
auto-apply-play: false
# [可选] 部分设备需要扩展SDP,需要打开此设置
seniorSdp: false
senior-sdp: false
# 保存移动位置历史轨迹:true:保留历史数据,false:仅保留最后的位置(默认)
savePositionHistory: false
save-position-history: false
# 点播等待超时时间,单位:毫秒
playTimeout: 3000
play-timeout: 3000
# 等待音视频编码信息再返回, true: 可以根据编码选择合适的播放器,false: 可以更快点播
waitTrack: false
wait-track: false
# 是否开启接口鉴权
interfaceAuthentication: true
interface-authentication: true
# 接口鉴权例外的接口, 即不进行接口鉴权的接口
interface-authentication-excludes:
-"/"
# 推流直播是否录制
recordPushLive: true
record-push-live: true
# 在线文档: swagger-ui(生产环境建议关闭)
springfox:

26
src/main/resources/application-dev.yml

@ -13,10 +13,15 @@ spring:
timeout: 10000
# [可选] jdbc数据库配置, 项目使用sqlite作为数据库,一般不需要配置
datasource:
# 使用mysql 打开23-28行注释, 删除29-36行
# name: wvp
# url: jdbc:mysql://127.0.0.1:3306/wvp?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true
# username:
# password:
# type: com.alibaba.druid.pool.DruidDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
name: eiot
url: jdbc:sqlite::resource:wvp.sqlite
# 打包为jar运行时把wvp.sqlite发到jar同级文件夹,同时url改为:
# url: jdbc:sqlite:wvp.sqlite
username:
password:
type: com.alibaba.druid.pool.DruidDataSource
@ -49,7 +54,7 @@ media:
# [必须修改] zlm服务器的内网IP
ip: 192.168.0.100
# [必须修改] zlm服务器的http.port
httpPort: 80
http-port: 80
# [可选] zlm服务器的hook.admin_params=secret
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
@ -57,10 +62,9 @@ media:
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
enable: true
# [可选] 在此范围内选择端口用于媒体流传输,
portRange: 30000,30500 # 端口范围
port-range: 30000,30500 # 端口范围
# 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载, 0 表示不使用
recordAssistPort: 0
record-assist-port: 0
# [可选] 日志配置, 一般不需要改
logging:
@ -74,16 +78,12 @@ logging:
genersoft:
iot: info
# [根据业务需求配置]
userSettings:
# [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true
autoApplyPlay: false
# 是否开启接口鉴权
interfaceAuthentication: true
user-settings:
# 推流直播是否录制
recordPushLive: true
record-push-live: true
# 在线文档: swagger-ui(生产环境建议关闭)
springfox:
documentation:
swagger-ui:
enabled: true
enabled: true

18713
web_src/package-lock.json

File diff suppressed because it is too large
Loading…
Cancel
Save