From 9e8cab609d32a5f2143a726a26437cc4d7b8c8da Mon Sep 17 00:00:00 2001 From: 648540858 <18010473990@163.com> Date: Tue, 10 Aug 2021 15:42:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=92=E8=89=B2=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0=E8=A7=92=E8=89=B2=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql.sql | 16 ++- .../com/genersoft/iot/vmp/conf/SipConfig.java | 94 ++++++++++------ .../AnonymousAuthenticationEntryPoint.java | 2 +- .../iot/vmp/conf/security/dto/LoginUser.java | 5 +- .../genersoft/iot/vmp/gb28181/SipLayer.java | 12 +-- .../cmd/SIPRequestHeaderPlarformProvider.java | 6 +- .../cmd/SIPRequestHeaderProvider.java | 46 ++++---- .../transmit/cmd/impl/SIPCommander.java | 12 +-- .../request/impl/MessageRequestProcessor.java | 2 +- .../impl/RegisterRequestProcessor.java | 6 +- .../iot/vmp/service/IRoleService.java | 18 ++++ .../service/impl/MediaServerServiceImpl.java | 14 +-- .../iot/vmp/service/impl/RoleServerImpl.java | 41 +++++++ .../iot/vmp/storager/dao/RoleMapper.java | 35 ++++++ .../iot/vmp/storager/dao/UserMapper.java | 28 +++-- .../iot/vmp/storager/dao/dto/Role.java | 50 +++++++++ .../iot/vmp/storager/dao/dto/User.java | 18 ++-- .../gb28181/platform/PlatformController.java | 8 +- .../iot/vmp/vmanager/log/LogController.java | 13 ++- .../vmp/vmanager/server/ServerController.java | 47 ++++++++ .../iot/vmp/vmanager/user/RoleController.java | 101 ++++++++++++++++++ .../iot/vmp/vmanager/user/UserController.java | 48 +++++++-- .../genersoft/iot/vmp/web/ApiController.java | 16 +-- src/main/resources/all-application.yml | 10 +- src/main/resources/application-dev.yml | 8 +- src/main/resources/banner.txt | 1 + src/main/resources/wvp.sqlite | Bin 135168 -> 139264 bytes .../vmp/service/impl/RoleServiceImplTest.java | 58 ++++++++++ .../vmp/service/impl/UserServiceImplTest.java | 17 ++- 29 files changed, 598 insertions(+), 134 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/service/IRoleService.java create mode 100644 src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java create mode 100644 src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java create mode 100644 src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java create mode 100644 src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java create mode 100644 src/test/java/com/genersoft/iot/vmp/service/impl/RoleServiceImplTest.java diff --git a/sql/mysql.sql b/sql/mysql.sql index 9a41b82e..5524e321 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -227,12 +227,22 @@ create table user username varchar(255) not null, password varchar(255) not null, roleId int not null, - create_time varchar(50) not null, - update_time varchar(50) not null + createTime varchar(50) not null, + updateTime varchar(50) not null ); create unique index user_username_uindex on user (username); -insert into user (username, password, roleId, create_time, update_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); +insert into user (username, password, roleId, createTime, updateTime) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '1', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); + +create table role ( + id int auto_increment + primary key, + name TEXT NOT NULL, + authority TEXT NOT NULL, + createTime varchar(50) not null, + updateTime varchar(50) not null +); +insert into role (id, name, authority, createTime, updateTime) values ('1', 'admin', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java index 8fc1ba82..709fe9c1 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java @@ -2,71 +2,101 @@ 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("sipConfig") +@Component +@ConfigurationProperties(prefix = "sip", ignoreInvalidFields = true) public class SipConfig { - @Value("${sip.ip}") - private String sipIp; + private String ip; /** - * 默认使用sip.ip + * 默认使用 0.0.0.0 */ - @Value("${sip.monitor-ip:0.0.0.0}") - private String monitorIp; + private String monitorIp = "0.0.0.0"; - @Value("${sip.port}") - private Integer sipPort; + private Integer port; - @Value("${sip.domain}") - private String sipDomain; + private String domain; - @Value("${sip.id}") - private String sipId; + private String id; - @Value("${sip.password}") - private String sipPassword; + private String password; - @Value("${sip.ptz.speed:50}") - Integer speed; + Integer ptzSpeed = 50; - @Value("${sip.keepalive-timeout:180}") - Integer keepaliveTimeOut; + Integer keepaliveTimeOut = 180; - @Value("${sip.register-time-interval:60}") - Integer registerTimeInterval; + Integer registerTimeInterval = 60; + + public void setIp(String ip) { + this.ip = ip; + } + + public void setMonitorIp(String monitorIp) { + this.monitorIp = monitorIp; + } + + public void setPort(Integer port) { + this.port = port; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public void setId(String id) { + this.id = id; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setPtzSpeed(Integer ptzSpeed) { + this.ptzSpeed = ptzSpeed; + } + + public void setKeepaliveTimeOut(Integer keepaliveTimeOut) { + this.keepaliveTimeOut = keepaliveTimeOut; + } + + public void setRegisterTimeInterval(Integer registerTimeInterval) { + this.registerTimeInterval = registerTimeInterval; + } public String getMonitorIp() { return monitorIp; } - public String getSipIp() { - return sipIp; + public String getIp() { + return ip; } - public Integer getSipPort() { - return sipPort; + public Integer getPort() { + return port; } - public String getSipDomain() { - return sipDomain; + public String getDomain() { + return domain; } - public String getSipId() { - return sipId; + public String getId() { + return id; } - public String getSipPassword() { - return sipPassword; + public String getPassword() { + return password; } - public Integer getSpeed() { - return speed; + public Integer getPtzSpeed() { + return ptzSpeed; } public Integer getKeepaliveTimeOut() { diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java b/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java index d4e25e33..800c4cb2 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java @@ -28,8 +28,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified"); response.setHeader("Content-type", "application/json;charset=UTF-8"); JSONObject jsonObject = new JSONObject(); - jsonObject.put("msg", e.getMessage()); jsonObject.put("code", "-1"); + jsonObject.put("msg", "请登录后重新请求"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); try { response.getWriter().print(jsonObject.toJSONString()); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java index 93680fde..45e03bc7 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.conf.security.dto; +import com.genersoft.iot.vmp.storager.dao.dto.Role; import com.genersoft.iot.vmp.storager.dao.dto.User; import org.springframework.security.core.CredentialsContainer; import org.springframework.security.core.GrantedAuthority; @@ -93,8 +94,8 @@ public class LoginUser implements UserDetails, CredentialsContainer { return user.getId(); } - public int getRoleId() { - return user.getRoleId(); + public Role getRole() { + return user.getRole(); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java index e71ac054..fb1aae24 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java @@ -93,15 +93,15 @@ public class SipLayer implements SipListener { ListeningPoint tcpListeningPoint = null; SipProviderImpl tcpSipProvider = null; try { - tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "TCP"); + tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "TCP"); tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint); tcpSipProvider.addSipListener(this); - logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "}"); + logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "}"); } catch (TransportNotSupportedException e) { e.printStackTrace(); } catch (InvalidArgumentException e) { logger.error("无法使用 [ {}:{} ]作为SIP[ TCP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用" - , sipConfig.getMonitorIp(), sipConfig.getSipPort()); + , sipConfig.getMonitorIp(), sipConfig.getPort()); } catch (TooManyListenersException e) { e.printStackTrace(); } catch (ObjectInUseException e) { @@ -116,7 +116,7 @@ public class SipLayer implements SipListener { ListeningPoint udpListeningPoint = null; SipProviderImpl udpSipProvider = null; try { - udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP"); + udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "UDP"); udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint); udpSipProvider.addSipListener(this); // udpSipProvider.setAutomaticDialogSupportEnabled(false); @@ -124,13 +124,13 @@ public class SipLayer implements SipListener { e.printStackTrace(); } catch (InvalidArgumentException e) { logger.error("无法使用 [ {}:{} ]作为SIP[ UDP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用" - , sipConfig.getMonitorIp(), sipConfig.getSipPort()); + , sipConfig.getMonitorIp(), sipConfig.getPort()); } catch (TooManyListenersException e) { e.printStackTrace(); } catch (ObjectInUseException e) { e.printStackTrace(); } - logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "]"); + logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "]"); return udpSipProvider; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java index de63fa9b..4ed942cd 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java @@ -39,13 +39,13 @@ public class SIPRequestHeaderPlarformProvider { SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort()); // via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), parentPlatform.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); // from SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), - sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); + sipConfig.getIp() + ":" + sipConfig.getPort()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to @@ -75,7 +75,7 @@ public class SIPRequestHeaderPlarformProvider { public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException { Request request = null; - String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort(); + String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); //请求行 SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP() + ":" + platform.getServerPort()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index 691bc429..160b850a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -37,16 +37,16 @@ public class SIPRequestHeaderProvider { SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); // via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), - sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), + sipConfig.getIp() + ":" + sipConfig.getPort()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getSipDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); @@ -68,16 +68,16 @@ public class SIPRequestHeaderProvider { SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); //via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); @@ -88,11 +88,11 @@ public class SIPRequestHeaderProvider { CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); - Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); - // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), device.getHost().getIp()+":"+device.getHost().getPort())); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); + // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); // Subject - SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getSipId(), 0)); + SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); request.addHeader(subjectHeader); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); request.setContent(content, contentTypeHeader); @@ -109,11 +109,11 @@ public class SIPRequestHeaderProvider { viaHeader.setRPort(); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); @@ -124,8 +124,8 @@ public class SIPRequestHeaderProvider { CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); - Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); - // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), device.getHost().getIp()+":"+device.getHost().getPort())); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); + // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); @@ -139,14 +139,14 @@ public class SIPRequestHeaderProvider { SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); // via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,toTag); @@ -158,7 +158,7 @@ public class SIPRequestHeaderProvider { CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); - Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); return request; } @@ -169,17 +169,17 @@ public class SIPRequestHeaderProvider { SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); // via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), - sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), + sipConfig.getIp() + ":" + sipConfig.getPort()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getSipDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); @@ -192,7 +192,7 @@ public class SIPRequestHeaderProvider { toHeader, viaHeaders, maxForwards); - Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); // Expires diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 7947ad9c..cec64ccb 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -105,7 +105,7 @@ public class SIPCommander implements ISIPCommander { */ @Override public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) { - return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getSpeed(), 0); + return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getPtzSpeed(), 0); } /** @@ -131,7 +131,7 @@ public class SIPCommander implements ISIPCommander { */ @Override public boolean ptzZoomCmd(Device device, String channelId, int inOut) { - return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getSpeed()); + return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getPtzSpeed()); } /** @@ -468,7 +468,7 @@ public class SIPCommander implements ISIPCommander { StringBuffer content = new StringBuffer(200); content.append("v=0\r\n"); - content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); + content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n"); content.append("s=Playback\r\n"); content.append("u="+channelId+":0\r\n"); content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n"); @@ -575,7 +575,7 @@ public class SIPCommander implements ISIPCommander { StringBuffer content = new StringBuffer(200); content.append("v=0\r\n"); - content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); + content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n"); content.append("s=Download\r\n"); content.append("u="+channelId+":0\r\n"); content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n"); @@ -749,7 +749,7 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("\r\n"); broadcastXml.append("Broadcast\r\n"); broadcastXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); - broadcastXml.append("" + sipConfig.getSipId() + "\r\n"); + broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); @@ -774,7 +774,7 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("\r\n"); broadcastXml.append("Broadcast\r\n"); broadcastXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); - broadcastXml.append("" + sipConfig.getSipId() + "\r\n"); + broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java index bd7bfd57..db5f05b2 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java @@ -550,7 +550,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { deviceChannel.setStatus(gbStream.isStatus()?1:0); // deviceChannel.setParentId(parentPlatform.getDeviceGBId()); deviceChannel.setRegisterWay(1); - deviceChannel.setCivilCode(cmder.getSipConfig().getSipDomain()); + deviceChannel.setCivilCode(cmder.getSipConfig().getDomain()); deviceChannel.setModel("live"); deviceChannel.setOwner("wvp-pro"); // deviceChannel.setAddress("test"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java index e5f76aeb..064d0234 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java @@ -79,9 +79,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { // 校验密码是否正确 if (authorhead != null) { passwordCorrect = new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, - sipConfig.getSipPassword()); + sipConfig.getPassword()); } - if (StringUtils.isEmpty(sipConfig.getSipPassword())){ + if (StringUtils.isEmpty(sipConfig.getPassword())){ passwordCorrect = true; } @@ -94,7 +94,7 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { logger.info("[{}] 密码错误 回复401", requestAddress); } response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); - new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getSipDomain()); + new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain()); }else { if (!passwordCorrect){ // 注册失败 diff --git a/src/main/java/com/genersoft/iot/vmp/service/IRoleService.java b/src/main/java/com/genersoft/iot/vmp/service/IRoleService.java new file mode 100644 index 00000000..d207c6ab --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IRoleService.java @@ -0,0 +1,18 @@ +package com.genersoft.iot.vmp.service; + +import com.genersoft.iot.vmp.storager.dao.dto.Role; + +import java.util.List; + +public interface IRoleService { + + Role getRoleById(int id); + + int add(Role role); + + int delete(int id); + + List getAll(); + + int update(Role role); +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index d928d873..3af007d9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -83,7 +83,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR for (MediaServerItem mediaServerItem : mediaServerItemList) { // 更新 if (mediaServerItem.getSsrcConfig() == null) { - SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getSipDomain()); + SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); mediaServerItem.setSsrcConfig(ssrcConfig); redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(), mediaServerItem); } @@ -145,7 +145,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR */ @Override public void clearRTPServer(MediaServerItem mediaServerItem) { - mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getSipDomain())); + mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, mediaServerItem.getId(), 0); } @@ -162,7 +162,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR new SsrcConfig( mediaServerItemInDataBase.getId(), null, - sipConfig.getSipDomain() + sipConfig.getDomain() ) ); } @@ -264,12 +264,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR if (serverItemInRedis != null) { serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig()); }else { - serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); + serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain())); } redisUtil.set(key, serverItemFromConfig); }else { String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); - serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); + serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain())); redisUtil.set(key, serverItemFromConfig); mediaServerMapper.add(serverItemFromConfig); } @@ -279,11 +279,11 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR String now = this.format.format(System.currentTimeMillis()); if (serverItem == null){ // 一个新的zlm接入wvp - serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getSipIp()); + serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getIp()); serverItem.setCreateTime(now); serverItem.setUpdateTime(now); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId(); - serverItem.setSsrcConfig(new SsrcConfig(serverItem.getId(), null, sipConfig.getSipDomain())); + serverItem.setSsrcConfig(new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain())); redisUtil.set(key, serverItem); // 存入数据库 mediaServerMapper.add(serverItem); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java new file mode 100644 index 00000000..d31bbcef --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java @@ -0,0 +1,41 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.service.IRoleService; +import com.genersoft.iot.vmp.storager.dao.RoleMapper; +import com.genersoft.iot.vmp.storager.dao.dto.Role; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class RoleServerImpl implements IRoleService { + + @Autowired + private RoleMapper roleMapper; + + @Override + public Role getRoleById(int id) { + return roleMapper.selectById(id); + } + + @Override + public int add(Role role) { + return roleMapper.add(role); + } + + @Override + public int delete(int id) { + return roleMapper.delete(id); + } + + @Override + public List getAll() { + return roleMapper.selectAll(); + } + + @Override + public int update(Role role) { + return roleMapper.update(role); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java new file mode 100644 index 00000000..be20a695 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java @@ -0,0 +1,35 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.storager.dao.dto.Role; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface RoleMapper { + + @Insert("INSERT INTO role (name, authority, createTime, updateTime) VALUES" + + "('${name}', '${authority}', '${createTime}', '${updateTime}')") + int add(Role role); + + @Update(value = {" "}) + int update(Role role); + + @Delete("DELETE FROM role WHERE id != 1 and id=#{id}") + int delete(int id); + + @Select("select * FROM role WHERE id=#{id}") + Role selectById(int id); + + @Select("select * FROM role") + List selectAll(); +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java index e2176322..7eb71e6a 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java @@ -10,32 +10,42 @@ import java.util.List; @Repository public interface UserMapper { - @Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" + - "('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')") + @Insert("INSERT INTO user (username, password, roleId, createTime, updateTime) VALUES" + + "('${username}', '${password}', '${role.id}', '${createTime}', '${updateTime}')") int add(User user); @Update(value = {" "}) int update(User user); - @Delete("DELETE FROM user WHERE id=#{id}") + @Delete("DELETE FROM user WHERE id != 1 and id=#{id}") int delete(int id); - @Select("select * FROM user WHERE username=#{username} AND password=#{password}") + @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority , role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.username=#{username} AND user.password=#{password}") + @Results(id = "roleMap", value = { + @Result(column = "roleID", property = "role.id"), + @Result(column = "roleName", property = "role.name"), + @Result(column = "roleAuthority", property = "role.authority"), + @Result(column = "roleCreateTime", property = "role.createTime"), + @Result(column = "roleUpdateTime", property = "role.updateTime") + }) User select(String username, String password); - @Select("select * FROM user WHERE id=#{id}") + @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.id=#{id}") + @ResultMap(value="roleMap") User selectById(int id); - @Select("select * FROM user WHERE username=#{username}") + @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and username=#{username}") + @ResultMap(value="roleMap") User getUserByUsername(String username); - @Select("select * FROM user") + @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id") + @ResultMap(value="roleMap") List selectAll(); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java new file mode 100644 index 00000000..44631f87 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java @@ -0,0 +1,50 @@ +package com.genersoft.iot.vmp.storager.dao.dto; + +public class Role { + + private int id; + private String name; + private String authority; + private String createTime; + private String updateTime; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthority() { + return authority; + } + + public void setAuthority(String authority) { + this.authority = authority; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java index b4a0289f..950a8cae 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java @@ -7,7 +7,7 @@ public class User { private String password; private String createTime; private String updateTime; - private int roleId; + private Role role; public int getId() { return id; @@ -41,14 +41,6 @@ public class User { this.createTime = createTime; } - public int getRoleId() { - return roleId; - } - - public void setRoleId(int roleId) { - this.roleId = roleId; - } - public String getUpdateTime() { return updateTime; } @@ -56,4 +48,12 @@ public class User { public void setUpdateTime(String updateTime) { this.updateTime = updateTime; } + + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java index 84431ddf..1a0a9b79 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java @@ -52,10 +52,10 @@ public class PlatformController { @GetMapping("/server_config") public ResponseEntity serverConfig() { JSONObject result = new JSONObject(); - result.put("deviceIp", sipConfig.getSipIp()); - result.put("devicePort", sipConfig.getSipPort()); - result.put("username", sipConfig.getSipId()); - result.put("password", sipConfig.getSipPassword()); + result.put("deviceIp", sipConfig.getIp()); + result.put("devicePort", sipConfig.getPort()); + result.put("username", sipConfig.getId()); + result.put("password", sipConfig.getPassword()); return new ResponseEntity<>(result, HttpStatus.OK); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java index 6dfb5694..650dbe03 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java @@ -1,5 +1,7 @@ package com.genersoft.iot.vmp.vmanager.log; +import com.genersoft.iot.vmp.conf.UserSetup; +import com.genersoft.iot.vmp.media.zlm.ZLMRunner; import com.genersoft.iot.vmp.service.ILogService; import com.genersoft.iot.vmp.storager.dao.dto.LogDto; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; @@ -8,6 +10,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -23,9 +27,14 @@ import java.text.SimpleDateFormat; @RequestMapping("/api/log") public class LogController { + private final static Logger logger = LoggerFactory.getLogger(LogController.class); + @Autowired private ILogService logService; + @Autowired + private UserSetup userSetup; + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** @@ -60,7 +69,9 @@ public class LogController { if (StringUtils.isEmpty(query)) query = null; if (StringUtils.isEmpty(startTime)) startTime = null; if (StringUtils.isEmpty(endTime)) endTime = null; - + if (!userSetup.getLogInDatebase()) { + logger.warn("自动记录日志功能已关闭,查询结果可能不完整。"); + } try { if (startTime != null) format.parse(startTime); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java index 4b7adc60..3bfa5957 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java @@ -1,7 +1,11 @@ package com.genersoft.iot.vmp.vmanager.server; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.VManageBootstrap; import com.genersoft.iot.vmp.common.VersionPo; +import com.genersoft.iot.vmp.conf.SipConfig; +import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.conf.VersionInfo; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; @@ -9,9 +13,13 @@ import com.genersoft.iot.vmp.utils.SpringBeanFactory; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import gov.nist.javax.sip.SipStackImpl; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.sip.ListeningPoint; @@ -36,6 +44,15 @@ public class ServerController { @Autowired VersionInfo versionInfo; + @Autowired + SipConfig sipConfig; + + @Autowired + UserSetup userSetup; + + @Value("${server.port}") + private int serverPort; + @ApiOperation("流媒体服务列表") @GetMapping(value = "/media_server/list") @@ -113,4 +130,34 @@ public class ServerController { result.setData(versionInfo.getVersion()); return result; } + + @ApiOperation("配置信息") + @GetMapping(value = "/config") + @ApiImplicitParams({ + @ApiImplicitParam(name="type", value = "配置类型(sip, base)", dataTypeClass = String.class), + }) + @ResponseBody + public WVPResult getVersion(String type){ + WVPResult result = new WVPResult<>(); + result.setCode(0); + result.setMsg("success"); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("server.port", serverPort); + if (StringUtils.isEmpty(type)) { + jsonObject.put("sip", JSON.toJSON(sipConfig)); + jsonObject.put("base", JSON.toJSON(userSetup)); + }else { + switch (type){ + case "sip": + jsonObject.put("sip", sipConfig); + break; + case "base": + jsonObject.put("base", userSetup); + break; + } + } + result.setData(jsonObject); + return result; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java new file mode 100644 index 00000000..6a75e1dd --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java @@ -0,0 +1,101 @@ +package com.genersoft.iot.vmp.vmanager.user; + +import com.genersoft.iot.vmp.conf.security.SecurityUtils; +import com.genersoft.iot.vmp.service.IRoleService; +import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.Role; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.util.DigestUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; + +import java.text.SimpleDateFormat; +import java.util.List; + +@Api(tags = "角色管理") +@CrossOrigin +@RestController +@RequestMapping("/api/role") +public class RoleController { + + @Autowired + private IRoleService roleService; + + private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @ApiOperation("添加角色") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", required = true, value = "角色名", dataTypeClass = String.class), + @ApiImplicitParam(name = "authority", required = true, value = "权限(自行定义内容,目前未使用)", dataTypeClass = String.class), + }) + @PostMapping("/add") + public ResponseEntity> add(@RequestParam String name, + @RequestParam(required = false) String authority){ + WVPResult result = new WVPResult<>(); + // 获取当前登录用户id + int currenRoleId = SecurityUtils.getUserInfo().getRole().getId(); + if (currenRoleId != 1) { + // 只用角色id为1才可以删除和添加用户 + result.setCode(-1); + result.setMsg("用户无权限"); + return new ResponseEntity<>(result, HttpStatus.FORBIDDEN); + } + + Role role = new Role(); + role.setName(name); + role.setAuthority(authority); + role.setCreateTime(format.format(System.currentTimeMillis())); + role.setUpdateTime(format.format(System.currentTimeMillis())); + + int addResult = roleService.add(role); + + result.setCode(addResult > 0 ? 0 : -1); + result.setMsg(addResult > 0 ? "success" : "fail"); + result.setData(addResult); + return new ResponseEntity<>(result, HttpStatus.OK); + } + + @ApiOperation("删除角色") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", required = true, value = "用户Id", dataTypeClass = Integer.class), + }) + @DeleteMapping("/delete") + public ResponseEntity> delete(@RequestParam Integer id){ + // 获取当前登录用户id + int currenRoleId = SecurityUtils.getUserInfo().getRole().getId(); + WVPResult result = new WVPResult<>(); + if (currenRoleId != 1) { + // 只用角色id为0才可以删除和添加用户 + result.setCode(-1); + result.setMsg("用户无权限"); + return new ResponseEntity<>(result, HttpStatus.FORBIDDEN); + } + int deleteResult = roleService.delete(id); + + result.setCode(deleteResult>0? 0 : -1); + result.setMsg(deleteResult>0? "success" : "fail"); + return new ResponseEntity<>(result, HttpStatus.OK); + } + + @ApiOperation("查询角色") + @ApiImplicitParams({}) + @GetMapping("/all") + public ResponseEntity>> all(){ + // 获取当前登录用户id + List allRoles = roleService.getAll(); + WVPResult> result = new WVPResult<>(); + result.setCode(0); + result.setMsg("success"); + result.setData(allRoles); + return new ResponseEntity<>(result, HttpStatus.OK); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java index 6e4c4169..756fecd9 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java @@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.vmanager.user; import com.genersoft.iot.vmp.conf.security.SecurityUtils; import com.genersoft.iot.vmp.conf.security.dto.LoginUser; +import com.genersoft.iot.vmp.service.IRoleService; import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.Role; import com.genersoft.iot.vmp.storager.dao.dto.User; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import io.swagger.annotations.Api; @@ -14,6 +16,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.util.DigestUtils; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.security.sasl.AuthenticationException; @@ -32,6 +35,9 @@ public class UserController { @Autowired private IUserService userService; + @Autowired + private IRoleService roleService; + private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @ApiOperation("登录") @@ -97,21 +103,38 @@ public class UserController { @PostMapping("/add") public ResponseEntity> add(@RequestParam String username, @RequestParam String password, - @RequestParam int roleId){ + @RequestParam Integer roleId){ + WVPResult result = new WVPResult<>(); + if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || roleId == null) { + result.setCode(-1); + result.setMsg("参数不可为空"); + return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); + } // 获取当前登录用户id - int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); - if (currenRoleId != 0) { - // 只用角色id为0才可以删除和添加用户 - return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); + int currenRoleId = SecurityUtils.getUserInfo().getRole().getId(); + if (currenRoleId != 1) { + // 只用角色id为1才可以删除和添加用户 + result.setCode(-1); + result.setMsg("用户无权限"); + return new ResponseEntity<>(result, HttpStatus.FORBIDDEN); } User user = new User(); user.setUsername(username); user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes())); - user.setRoleId(roleId); + + Role role = roleService.getRoleById(roleId); + + if (role == null) { + result.setCode(-1); + result.setMsg("roleId is not found"); + // 角色不存在 + return new ResponseEntity<>(result, HttpStatus.OK); + } + user.setRole(role); user.setCreateTime(format.format(System.currentTimeMillis())); user.setUpdateTime(format.format(System.currentTimeMillis())); int addResult = userService.addUser(user); - WVPResult result = new WVPResult<>(); + result.setCode(addResult > 0 ? 0 : -1); result.setMsg(addResult > 0 ? "success" : "fail"); result.setData(addResult); @@ -125,13 +148,16 @@ public class UserController { @DeleteMapping("/delete") public ResponseEntity> delete(@RequestParam Integer id){ // 获取当前登录用户id - int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); - if (currenRoleId != 0) { + int currenRoleId = SecurityUtils.getUserInfo().getRole().getId(); + WVPResult result = new WVPResult<>(); + if (currenRoleId != 1) { // 只用角色id为0才可以删除和添加用户 - return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); + result.setCode(-1); + result.setMsg("用户无权限"); + return new ResponseEntity<>(result, HttpStatus.FORBIDDEN); } int deleteResult = userService.deleteUser(id); - WVPResult result = new WVPResult<>(); + result.setCode(deleteResult>0? 0 : -1); result.setMsg(deleteResult>0? "success" : "fail"); return new ResponseEntity<>(result, HttpStatus.OK); diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiController.java b/src/main/java/com/genersoft/iot/vmp/web/ApiController.java index 8035810a..cafa40cf 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/ApiController.java @@ -38,10 +38,10 @@ public class ApiController { result.put("ServerTime","2020-09-02 17:11"); result.put("StartUpTime","2020-09-02 17:11"); result.put("Server",""); - result.put("SIPSerial", sipConfig.getSipId()); - result.put("SIPRealm", sipConfig.getSipDomain()); - result.put("SIPHost", sipConfig.getSipIp()); - result.put("SIPPort", sipConfig.getSipPort()); + result.put("SIPSerial", sipConfig.getId()); + result.put("SIPRealm", sipConfig.getDomain()); + result.put("SIPHost", sipConfig.getIp()); + result.put("SIPPort", sipConfig.getPort()); result.put("ChannelCount","1000"); result.put("VersionType",""); result.put("LogoMiniText",""); @@ -65,10 +65,10 @@ public class ApiController { // result.put("ServerTime","2020-09-02 17:11"); // result.put("StartUpTime","2020-09-02 17:11"); // result.put("Server",""); -// result.put("SIPSerial", sipConfig.getSipId()); -// result.put("SIPRealm", sipConfig.getSipDomain()); -// result.put("SIPHost", sipConfig.getSipIp()); -// result.put("SIPPort", sipConfig.getSipPort()); +// result.put("SIPSerial", sipConfig.getId()); +// result.put("SIPRealm", sipConfig.getDomain()); +// result.put("SIPHost", sipConfig.getIp()); +// result.put("SIPPort", sipConfig.getPort()); // result.put("ChannelCount","1000"); // result.put("VersionType",""); // result.put("LogoMiniText",""); diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml index 140ef0a4..856d6c5f 100644 --- a/src/main/resources/all-application.yml +++ b/src/main/resources/all-application.yml @@ -76,6 +76,8 @@ sip: keepalive-timeout: 180 # [可选] 国标级联注册失败,再次发起注册的时间间隔。 默认60秒 register-time-interval: 60 + # [可选] 云台控制速度 + ptz-speed: 50 # TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。 # keepalliveToOnline: false @@ -155,4 +157,10 @@ user-settings: # 在线文档: swagger-ui(生产环境建议关闭) swagger-ui: - enabled: true \ No newline at end of file + enabled: true + +# 版本信息, 不需修改 +version: + version: "@project.version@" + description: "@project.description@" + artifact-id: "@project.artifactId@" \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f0cb8f80..3d250989 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -85,4 +85,10 @@ user-settings: # 在线文档: swagger-ui(生产环境建议关闭) swagger-ui: - enabled: true \ No newline at end of file + enabled: true + +# 版本信息, 不需修改 +version: + version: "@project.version@" + description: "@project.description@" + artifact-id: "@project.artifactId@" \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index 5cf57a51..0c7250d4 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -6,3 +6,4 @@ \ \____________\ \__/ / \ \__\ \ \__\ \ \__\\ _\\ \_______\ \|____________|\|__|/ \|__| \|__| \|__|\|__|\|_______| +版本:${version.version} \ No newline at end of file diff --git a/src/main/resources/wvp.sqlite b/src/main/resources/wvp.sqlite index 908d5853ef7e8ccda539d1efc228da33fba0a870..228a96a3bfd3e0e2b51fd18d2195c43da8628e7d 100644 GIT binary patch delta 613 zcmZ8eKWq|l6#hLpjynW?M*uOlhU3y0tW{fZR-wHphucjXSI7NsRq$UJkLjIk zE}M}m`b!S>;+C*uZi%%rbfxn@laF7aJXF@-&B55UyD^ zaM7e#vdkCLym6g*3ti(adYZNxE>XYH3VtoiL6YIXt{h#12~fH=2*fgg6ovs(4?`bmjl+)eF$`;7&zEuAwQSR zrSnDdVhrr;-JGP2O#iDAy$Jp8$#^Ilh|ln0amK6l;RDl&iBL?P6cuBMGm0+;-K97D x58%qPjKb`|uM6d2iUz!m@V2_`Cbs&3MlS64_x?Cs`P?3CQuP`Jw$f}z{{m0?tsVdX delta 481 zcmZoTz|pXPV}i8caRvqkMJQ%uU|?pMsAJ4}oI%ff!p4-@{EYmY1XvV!nECH9@IT}K z&VP^p{ANLcL;O7A969;v@hR!?CAkHY@7YUnFf)sCmKLWLfz&T%5m4C7BJf9k(E@>O z0!*9u89AnJmS^&vCcwn9nB_o#8W-a^2L5%tYxpah^PjjE+o9%>6(ob~A6EBhHwrVF>h^Fk>YHuN03E_i3(e+-)3xxf;2A*u^-GupVN& z&(y(xoIjAygg25k9;hsgfnmCl1LNB1?;RO?_!t-%WyKX08Jp`tc5JV7WPHxds60K< zl~ILJc6*yEV>$EodI3g%#_2v@j9Js|L>VuzIg7A~hZ{nj$vs_Jlu>#+pBQ5wqeNqb z61%vlC}XoQ*u|j00%4x%-JXn-nBz+_r(g7B6qYP4NJ%V71#)v!6+%)gN)+<)fw(j$ yXS all = roleService.getAll(); + Role roleById = roleService.getRoleById(1); + System.out.println(); + + } + + + @org.junit.jupiter.api.Test + void add() { + for (int i = 0; i < 10; i++) { + Role role = new Role(); + role.setName("test+" + i); + role.setAuthority("adadadda"); + role.setCreateTime(format.format(System.currentTimeMillis())); + role.setUpdateTime(format.format(System.currentTimeMillis())); + roleService.add(role); + } + } + + @org.junit.jupiter.api.Test + void delete() { + roleService.delete(20); + } + + @org.junit.jupiter.api.Test + void update() { + Role role = new Role(); + role.setId(21); + role.setName("TTTTTT"); + role.setAuthority("adadadda"); + roleService.update(role); + } +} \ No newline at end of file diff --git a/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java b/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java index eea7f041..9e3c6724 100644 --- a/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java +++ b/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; import com.genersoft.iot.vmp.service.IDeviceAlarmService; import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.Role; import com.genersoft.iot.vmp.storager.dao.dto.User; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -11,6 +12,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; @SpringBootTest @@ -24,7 +26,11 @@ class UserServiceImplTest { @org.junit.jupiter.api.Test void getAllUser() { + List allUsers = userService.getAllUsers(); System.out.println(userService.getAllUsers().size()); + User admin = userService.getUser("admin", "21232f297a57a5a743894a0e4a801fc3"); + User admin1 = userService.getUserByUsername("admin"); + System.out.println(12); } @@ -34,7 +40,10 @@ class UserServiceImplTest { User user = new User(); user.setUsername("admin_" + i); user.setPassword("admin_password_" + i); - user.setRoleId((int)(Math.random()*4 + 1)); + + Role role = new Role(); + role.setId(1); + user.setRole(role); user.setCreateTime(format.format(System.currentTimeMillis())); user.setUpdateTime(format.format(System.currentTimeMillis())); userService.addUser(user); @@ -49,10 +58,12 @@ class UserServiceImplTest { @org.junit.jupiter.api.Test void update() { User user = new User(); - user.setId(1003); + user.setId(11); user.setUsername("update" ); user.setPassword("update"); - user.setRoleId((int)(Math.random()*4 + 1)); + Role role = new Role(); + role.setId(2); + user.setRole(role); user.setUpdateTime(format.format(System.currentTimeMillis())); userService.updateUsers(user); }