调整国标设备密码逻辑,未设置公共密码则需要提前添加设备后才允许注册
This commit is contained in:
@@ -14,7 +14,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.SessionCookieConfig;
|
||||
import jakarta.servlet.SessionTrackingMode;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -88,39 +88,55 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
|
||||
AddressImpl address = (AddressImpl) fromHeader.getAddress();
|
||||
SipUri uri = (SipUri) address.getURI();
|
||||
String deviceId = uri.getUser();
|
||||
|
||||
// 调整逻辑,如果为设置公共密码,那么就必须要预设用户信息,否则无法注册。
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
|
||||
userSetting.getSipUseSourceIpAsRemoteAddress());
|
||||
String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort();
|
||||
String title = registerFlag ? "[注册请求]" : "[注销请求]";
|
||||
log.info(title + "设备:{}, 开始处理: {}", deviceId, requestAddress);
|
||||
if (device != null &&
|
||||
device.getSipTransactionInfo() != null &&
|
||||
request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
|
||||
log.info(title + "设备:{}, 注册续订: {}", device.getDeviceId(), device.getDeviceId());
|
||||
if (registerFlag) {
|
||||
device.setExpires(request.getExpires().getExpires());
|
||||
device.setIp(remoteAddressInfo.getIp());
|
||||
device.setPort(remoteAddressInfo.getPort());
|
||||
device.setHostAddress(IpPortUtil.concatenateIpAndPort(remoteAddressInfo.getIp(), String.valueOf(remoteAddressInfo.getPort())));
|
||||
log.info("{} 设备:{}, 开始处理: {}", title, deviceId, requestAddress);
|
||||
String password = null;
|
||||
if (device != null) {
|
||||
if (device.getSipTransactionInfo() != null &&
|
||||
request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
|
||||
log.info("{} 设备:{}, 注册续订: {}", title, device.getDeviceId(), device.getDeviceId());
|
||||
if (registerFlag) {
|
||||
device.setExpires(request.getExpires().getExpires());
|
||||
device.setIp(remoteAddressInfo.getIp());
|
||||
device.setPort(remoteAddressInfo.getPort());
|
||||
device.setHostAddress(IpPortUtil.concatenateIpAndPort(remoteAddressInfo.getIp(), String.valueOf(remoteAddressInfo.getPort())));
|
||||
|
||||
device.setLocalIp(request.getLocalAddress().getHostAddress());
|
||||
Response registerOkResponse = getRegisterOkResponse(request);
|
||||
// 判断TCP还是UDP
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String transport = reqViaHeader.getTransport();
|
||||
device.setTransport("TCP".equalsIgnoreCase(transport) ? "TCP" : "UDP");
|
||||
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), registerOkResponse);
|
||||
device.setRegisterTime(DateUtil.getNow());
|
||||
deviceService.online(device, null);
|
||||
} else {
|
||||
deviceService.offline(deviceId, "主动注销");
|
||||
device.setLocalIp(request.getLocalAddress().getHostAddress());
|
||||
Response registerOkResponse = getRegisterOkResponse(request);
|
||||
// 判断TCP还是UDP
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String transport = reqViaHeader.getTransport();
|
||||
device.setTransport("TCP".equalsIgnoreCase(transport) ? "TCP" : "UDP");
|
||||
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), registerOkResponse);
|
||||
device.setRegisterTime(DateUtil.getNow());
|
||||
deviceService.online(device, null);
|
||||
} else {
|
||||
deviceService.offline(deviceId, "主动注销");
|
||||
}
|
||||
return;
|
||||
}else {
|
||||
// 正常注册, 用户信息未设置密码,并且公共密码也未设置,则关闭鉴权
|
||||
if (!ObjectUtils.isEmpty(device.getPassword()) || !ObjectUtils.isEmpty(sipConfig.getPassword())) {
|
||||
password = (!ObjectUtils.isEmpty(device.getPassword())) ? device.getPassword() : sipConfig.getPassword();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (ObjectUtils.isEmpty(sipConfig.getPassword())) {
|
||||
log.info("{} 设备:{}, 地址: {}, 公共密码已经禁用,请添加用户信息后注册", title, deviceId, requestAddress);
|
||||
response = getMessageFactory().createResponse(Response.FORBIDDEN, request);
|
||||
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
|
||||
return;
|
||||
}else {
|
||||
password = sipConfig.getPassword();
|
||||
}
|
||||
return;
|
||||
}
|
||||
String password = (device != null && !ObjectUtils.isEmpty(device.getPassword())) ? device.getPassword() : sipConfig.getPassword();
|
||||
|
||||
AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
|
||||
if (authHead == null && !ObjectUtils.isEmpty(password)) {
|
||||
log.info(title + " 设备:{}, 回复401: {}", deviceId, requestAddress);
|
||||
|
||||
@@ -73,7 +73,7 @@ sip:
|
||||
domain: 4101050000
|
||||
# [可选]
|
||||
id: 41010500002000000001
|
||||
# [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验
|
||||
# [可选] 公共认证密码 移除密码将必须提前添加设备才能通过认证
|
||||
password: 12345678
|
||||
# 是否存储alarm信息
|
||||
alarm: false
|
||||
|
||||
@@ -46,7 +46,7 @@ sip:
|
||||
domain: ${WVP_DOMAIN:4401020049}
|
||||
# [可选]
|
||||
id: ${WVP_ID:44010200492000000001}
|
||||
# [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验
|
||||
# [可选] 公共认证密码 移除密码将必须提前添加设备才能通过认证
|
||||
password: ${WVP_PWD:admin123}
|
||||
|
||||
#zlm 默认服务器配置
|
||||
|
||||
@@ -95,7 +95,7 @@ server:
|
||||
|
||||
# 作为28181服务器的配置
|
||||
sip:
|
||||
# [必须修改] 本机的IP,对应你的网卡,监听什么ip就是使用什么网卡,
|
||||
# [可选] 监听网卡IP,监听什么ip就是使用什么网卡,不配置则自动获取本机所有网卡,推荐不配置,系统自动获取
|
||||
# 如果要监听多张网卡,可以使用逗号分隔多个IP, 例如: 192.168.1.4,10.0.0.4
|
||||
# 如果不明白,就使用0.0.0.0,大部分情况都是可以的
|
||||
# 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。
|
||||
@@ -111,7 +111,7 @@ sip:
|
||||
domain: 4401020049
|
||||
# [可选]
|
||||
id: 44010200492000000001
|
||||
# [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验
|
||||
# [可选] 公共认证密码 移除密码将必须提前添加设备才能通过认证
|
||||
password: admin123
|
||||
# [可选] 国标级联注册失败,再次发起注册的时间间隔。 默认60秒
|
||||
register-time-interval: 60
|
||||
|
||||
Reference in New Issue
Block a user