From 602cd390e0e0600b82df18d173c170fb2128f6d1 Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Wed, 24 Sep 2025 11:40:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E9=83=A8=E5=88=86=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DigestServerAuthenticationHelper.java | 50 ++++++++----------- .../controller/PlatformController.java | 14 ++---- web/src/api/platform.js | 2 +- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java index f4617b891..27fb7b803 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java @@ -48,7 +48,7 @@ import java.util.Random; @Slf4j public class DigestServerAuthenticationHelper { - private MessageDigest messageDigest; + private final MessageDigest messageDigest; public static final String DEFAULT_ALGORITHM = "MD5"; public static final String DEFAULT_SCHEME = "Digest"; @@ -59,19 +59,18 @@ public class DigestServerAuthenticationHelper { /** * Default constructor. - * @throws NoSuchAlgorithmException */ public DigestServerAuthenticationHelper() throws NoSuchAlgorithmException { messageDigest = MessageDigest.getInstance(DEFAULT_ALGORITHM); } - public static String toHexString(byte b[]) { + public static String toHexString(byte[] b) { int pos = 0; char[] c = new char[b.length * 2]; - for (int i = 0; i < b.length; i++) { - c[pos++] = toHex[(b[i] >> 4) & 0x0F]; - c[pos++] = toHex[b[i] & 0x0f]; + for (byte value : b) { + c[pos++] = toHex[(value >> 4) & 0x0F]; + c[pos++] = toHex[value & 0x0f]; } return new String(c); } @@ -87,8 +86,8 @@ public class DigestServerAuthenticationHelper { long pad = rand.nextLong(); String nonceString = Long.valueOf(time).toString() + Long.valueOf(pad).toString(); - byte mdbytes[] = messageDigest.digest(nonceString.getBytes()); - return toHexString(mdbytes); + byte[] mdBytes = messageDigest.digest(nonceString.getBytes()); + return toHexString(mdBytes); } public Response generateChallenge(HeaderFactory headerFactory, Response response, String realm) { @@ -132,8 +131,6 @@ public class DigestServerAuthenticationHelper { return false; } - - String A2 = request.getMethod().toUpperCase() + ":" + uri.toString(); String HA1 = hashedPassword; @@ -177,12 +174,11 @@ public class DigestServerAuthenticationHelper { if ( authHeader == null || authHeader.getRealm() == null) { return false; } - String realm = authHeader.getRealm().trim(); - String username = authHeader.getUsername().trim(); - - if ( username == null || realm == null ) { + if ( authHeader.getUsername() == null || authHeader.getRealm() == null ) { return false; } + String realm = authHeader.getRealm().trim(); + String username = authHeader.getUsername().trim(); String nonce = authHeader.getNonce(); URI uri = authHeader.getURI(); @@ -199,26 +195,24 @@ public class DigestServerAuthenticationHelper { // nonce计数器,是一个16进制的数值,表示同一nonce下客户端发送出请求的数量 int nc = authHeader.getNonceCount(); String ncStr = String.format("%08x", nc).toUpperCase(); - // String ncStr = new DecimalFormat("00000000").format(nc); - // String ncStr = new DecimalFormat("00000000").format(Integer.parseInt(nc + "", 16)); String A1 = username + ":" + realm + ":" + pass; String A2 = request.getMethod().toUpperCase() + ":" + uri.toString(); - byte mdbytes[] = messageDigest.digest(A1.getBytes()); + byte[] mdbytes = messageDigest.digest(A1.getBytes()); String HA1 = toHexString(mdbytes); - log.debug("A1: " + A1); - log.debug("A2: " + A2); + log.debug("A1: {}", A1); + log.debug("A2: {}", A2); mdbytes = messageDigest.digest(A2.getBytes()); String HA2 = toHexString(mdbytes); - log.debug("HA1: " + HA1); - log.debug("HA2: " + HA2); + log.debug("HA1: {}", HA1); + log.debug("HA2: {}", HA2); // String cnonce = authHeader.getCNonce(); - log.debug("nonce: " + nonce); - log.debug("nc: " + ncStr); - log.debug("cnonce: " + cnonce); - log.debug("qop: " + qop); + log.debug("nonce: {}", nonce); + log.debug("nc: {}", ncStr); + log.debug("cnonce: {}", cnonce); + log.debug("qop: {}", qop); String KD = HA1 + ":" + nonce; if (qop != null && qop.equalsIgnoreCase("auth") ) { @@ -231,12 +225,12 @@ public class DigestServerAuthenticationHelper { KD += ":" + qop; } KD += ":" + HA2; - log.debug("KD: " + KD); + log.debug("KD: {}", KD); mdbytes = messageDigest.digest(KD.getBytes()); String mdString = toHexString(mdbytes); - log.debug("mdString: " + mdString); + log.debug("mdString: {}", mdString); String response = authHeader.getResponse(); - log.debug("response: " + response); + log.debug("response: {}", response); return mdString.equals(response); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java index 79e6b3d07..cba750a20 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java @@ -93,9 +93,6 @@ public class PlatformController { @ResponseBody public void add(@RequestBody Platform platform) { - if (log.isDebugEnabled()) { - log.debug("保存上级平台信息API调用"); - } Assert.notNull(platform.getName(), "平台名称不可为空"); Assert.notNull(platform.getServerGBId(), "上级平台国标编号不可为空"); Assert.notNull(platform.getServerIp(), "上级平台IP不可为空"); @@ -140,9 +137,6 @@ public class PlatformController { @ResponseBody public void updatePlatform(@RequestBody Platform parentPlatform) { - if (log.isDebugEnabled()) { - log.debug("保存上级平台信息API调用"); - } if (ObjectUtils.isEmpty(parentPlatform.getName()) || ObjectUtils.isEmpty(parentPlatform.getServerGBId()) || ObjectUtils.isEmpty(parentPlatform.getServerGBDomain()) @@ -163,16 +157,14 @@ public class PlatformController { @Parameter(name = "id", description = "上级平台ID") @DeleteMapping("/delete") @ResponseBody - public DeferredResult deletePlatform(Integer id) { + public DeferredResult> deletePlatform(Integer id) { if (log.isDebugEnabled()) { log.debug("删除上级平台API调用"); } - DeferredResult deferredResult = new DeferredResult<>(); + DeferredResult> deferredResult = new DeferredResult<>(); - platformService.delete(id, (object)->{ - deferredResult.setResult(WVPResult.success()); - }); + platformService.delete(id, (object)-> deferredResult.setResult(WVPResult.success())); return deferredResult; } diff --git a/web/src/api/platform.js b/web/src/api/platform.js index 991366d22..5a684b34d 100644 --- a/web/src/api/platform.js +++ b/web/src/api/platform.js @@ -26,7 +26,7 @@ export function exit(deviceGbId) { export function remove(id) { return request({ method: 'delete', - url: `/api/platform/delete/`, + url: `/api/platform/delete`, params: { id: id }