去除部分警告

This commit is contained in:
lin 2025-09-24 11:40:31 +08:00
parent 842647674a
commit 602cd390e0
3 changed files with 26 additions and 40 deletions

View File

@ -48,7 +48,7 @@ import java.util.Random;
@Slf4j @Slf4j
public class DigestServerAuthenticationHelper { public class DigestServerAuthenticationHelper {
private MessageDigest messageDigest; private final MessageDigest messageDigest;
public static final String DEFAULT_ALGORITHM = "MD5"; public static final String DEFAULT_ALGORITHM = "MD5";
public static final String DEFAULT_SCHEME = "Digest"; public static final String DEFAULT_SCHEME = "Digest";
@ -59,19 +59,18 @@ public class DigestServerAuthenticationHelper {
/** /**
* Default constructor. * Default constructor.
* @throws NoSuchAlgorithmException
*/ */
public DigestServerAuthenticationHelper() public DigestServerAuthenticationHelper()
throws NoSuchAlgorithmException { throws NoSuchAlgorithmException {
messageDigest = MessageDigest.getInstance(DEFAULT_ALGORITHM); messageDigest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
} }
public static String toHexString(byte b[]) { public static String toHexString(byte[] b) {
int pos = 0; int pos = 0;
char[] c = new char[b.length * 2]; char[] c = new char[b.length * 2];
for (int i = 0; i < b.length; i++) { for (byte value : b) {
c[pos++] = toHex[(b[i] >> 4) & 0x0F]; c[pos++] = toHex[(value >> 4) & 0x0F];
c[pos++] = toHex[b[i] & 0x0f]; c[pos++] = toHex[value & 0x0f];
} }
return new String(c); return new String(c);
} }
@ -87,8 +86,8 @@ public class DigestServerAuthenticationHelper {
long pad = rand.nextLong(); long pad = rand.nextLong();
String nonceString = Long.valueOf(time).toString() String nonceString = Long.valueOf(time).toString()
+ Long.valueOf(pad).toString(); + Long.valueOf(pad).toString();
byte mdbytes[] = messageDigest.digest(nonceString.getBytes()); byte[] mdBytes = messageDigest.digest(nonceString.getBytes());
return toHexString(mdbytes); return toHexString(mdBytes);
} }
public Response generateChallenge(HeaderFactory headerFactory, Response response, String realm) { public Response generateChallenge(HeaderFactory headerFactory, Response response, String realm) {
@ -132,8 +131,6 @@ public class DigestServerAuthenticationHelper {
return false; return false;
} }
String A2 = request.getMethod().toUpperCase() + ":" + uri.toString(); String A2 = request.getMethod().toUpperCase() + ":" + uri.toString();
String HA1 = hashedPassword; String HA1 = hashedPassword;
@ -177,12 +174,11 @@ public class DigestServerAuthenticationHelper {
if ( authHeader == null || authHeader.getRealm() == null) { if ( authHeader == null || authHeader.getRealm() == null) {
return false; return false;
} }
String realm = authHeader.getRealm().trim(); if ( authHeader.getUsername() == null || authHeader.getRealm() == null ) {
String username = authHeader.getUsername().trim();
if ( username == null || realm == null ) {
return false; return false;
} }
String realm = authHeader.getRealm().trim();
String username = authHeader.getUsername().trim();
String nonce = authHeader.getNonce(); String nonce = authHeader.getNonce();
URI uri = authHeader.getURI(); URI uri = authHeader.getURI();
@ -199,26 +195,24 @@ public class DigestServerAuthenticationHelper {
// nonce计数器是一个16进制的数值表示同一nonce下客户端发送出请求的数量 // nonce计数器是一个16进制的数值表示同一nonce下客户端发送出请求的数量
int nc = authHeader.getNonceCount(); int nc = authHeader.getNonceCount();
String ncStr = String.format("%08x", nc).toUpperCase(); 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 A1 = username + ":" + realm + ":" + pass;
String A2 = request.getMethod().toUpperCase() + ":" + uri.toString(); String A2 = request.getMethod().toUpperCase() + ":" + uri.toString();
byte mdbytes[] = messageDigest.digest(A1.getBytes()); byte[] mdbytes = messageDigest.digest(A1.getBytes());
String HA1 = toHexString(mdbytes); String HA1 = toHexString(mdbytes);
log.debug("A1: " + A1); log.debug("A1: {}", A1);
log.debug("A2: " + A2); log.debug("A2: {}", A2);
mdbytes = messageDigest.digest(A2.getBytes()); mdbytes = messageDigest.digest(A2.getBytes());
String HA2 = toHexString(mdbytes); String HA2 = toHexString(mdbytes);
log.debug("HA1: " + HA1); log.debug("HA1: {}", HA1);
log.debug("HA2: " + HA2); log.debug("HA2: {}", HA2);
// String cnonce = authHeader.getCNonce(); // String cnonce = authHeader.getCNonce();
log.debug("nonce: " + nonce); log.debug("nonce: {}", nonce);
log.debug("nc: " + ncStr); log.debug("nc: {}", ncStr);
log.debug("cnonce: " + cnonce); log.debug("cnonce: {}", cnonce);
log.debug("qop: " + qop); log.debug("qop: {}", qop);
String KD = HA1 + ":" + nonce; String KD = HA1 + ":" + nonce;
if (qop != null && qop.equalsIgnoreCase("auth") ) { if (qop != null && qop.equalsIgnoreCase("auth") ) {
@ -231,12 +225,12 @@ public class DigestServerAuthenticationHelper {
KD += ":" + qop; KD += ":" + qop;
} }
KD += ":" + HA2; KD += ":" + HA2;
log.debug("KD: " + KD); log.debug("KD: {}", KD);
mdbytes = messageDigest.digest(KD.getBytes()); mdbytes = messageDigest.digest(KD.getBytes());
String mdString = toHexString(mdbytes); String mdString = toHexString(mdbytes);
log.debug("mdString: " + mdString); log.debug("mdString: {}", mdString);
String response = authHeader.getResponse(); String response = authHeader.getResponse();
log.debug("response: " + response); log.debug("response: {}", response);
return mdString.equals(response); return mdString.equals(response);
} }

View File

@ -93,9 +93,6 @@ public class PlatformController {
@ResponseBody @ResponseBody
public void add(@RequestBody Platform platform) { public void add(@RequestBody Platform platform) {
if (log.isDebugEnabled()) {
log.debug("保存上级平台信息API调用");
}
Assert.notNull(platform.getName(), "平台名称不可为空"); Assert.notNull(platform.getName(), "平台名称不可为空");
Assert.notNull(platform.getServerGBId(), "上级平台国标编号不可为空"); Assert.notNull(platform.getServerGBId(), "上级平台国标编号不可为空");
Assert.notNull(platform.getServerIp(), "上级平台IP不可为空"); Assert.notNull(platform.getServerIp(), "上级平台IP不可为空");
@ -140,9 +137,6 @@ public class PlatformController {
@ResponseBody @ResponseBody
public void updatePlatform(@RequestBody Platform parentPlatform) { public void updatePlatform(@RequestBody Platform parentPlatform) {
if (log.isDebugEnabled()) {
log.debug("保存上级平台信息API调用");
}
if (ObjectUtils.isEmpty(parentPlatform.getName()) if (ObjectUtils.isEmpty(parentPlatform.getName())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBId()) || ObjectUtils.isEmpty(parentPlatform.getServerGBId())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBDomain()) || ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
@ -163,16 +157,14 @@ public class PlatformController {
@Parameter(name = "id", description = "上级平台ID") @Parameter(name = "id", description = "上级平台ID")
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ResponseBody @ResponseBody
public DeferredResult<Object> deletePlatform(Integer id) { public DeferredResult<WVPResult<?>> deletePlatform(Integer id) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("删除上级平台API调用"); log.debug("删除上级平台API调用");
} }
DeferredResult<Object> deferredResult = new DeferredResult<>(); DeferredResult<WVPResult<?>> deferredResult = new DeferredResult<>();
platformService.delete(id, (object)->{ platformService.delete(id, (object)-> deferredResult.setResult(WVPResult.success()));
deferredResult.setResult(WVPResult.success());
});
return deferredResult; return deferredResult;
} }

View File

@ -26,7 +26,7 @@ export function exit(deviceGbId) {
export function remove(id) { export function remove(id) {
return request({ return request({
method: 'delete', method: 'delete',
url: `/api/platform/delete/`, url: `/api/platform/delete`,
params: { params: {
id: id id: id
} }