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

This commit is contained in:
64850858
2021-07-06 16:38:31 +08:00
parent b24be12405
commit 0faa593658
11 changed files with 2471 additions and 16568 deletions

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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;
import org.springframework.stereotype.Component;
@Configuration("userSetup")
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;
@Value("${userSettings.seniorSdp:false}")
private boolean seniorSdp;
private Boolean autoApplyPlay = Boolean.FALSE;
@Value("${userSettings.playTimeout:18000}")
private long playTimeout;
private Boolean seniorSdp = Boolean.FALSE;
@Value("${userSettings.waitTrack:false}")
private boolean waitTrack;
private Long playTimeout = 18000L;
@Value("${userSettings.interfaceAuthentication}")
private boolean interfaceAuthentication;
private Boolean waitTrack = Boolean.FALSE;
@Value("${userSettings.recordPushLive}")
private boolean recordPushLive;
private Boolean interfaceAuthentication = Boolean.TRUE;
public boolean getSavePositionHistory() {
private Boolean recordPushLive = Boolean.FALSE;
private List<String> interfaceAuthenticationExcludes = new ArrayList<>();
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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}
}