比较提交

..

没有共同的提交。1a0ef7d8861b3ba238d23dcf8ab0d009d90447e8 和 ccb976c605f166c7213f05fb606bec53829feb51 的历史完全不同。

共有 7 个文件被更改,包括 12 次插入52 次删除

查看文件

查看文件

@ -51,7 +51,7 @@ public class LicenseAdminController {
}
}
AppLicenseEntity updated = appLicenseService.update(
appKey, null, req.maxDevices(), newExpiresAt, clearExpiresAt, req.isActive(), req.remark(), null, null, null);
appKey, null, req.maxDevices(), newExpiresAt, clearExpiresAt, req.isActive(), req.remark());
return ResponseEntity.ok(ApiResponse.success(updated));
}

查看文件

@ -81,17 +81,15 @@ public class LicenseInternalController {
}
@GetMapping("/devices/{deviceId}")
public ResponseEntity<ApiResponse<List<DeviceEntity>>> getDevice(
public ResponseEntity<ApiResponse<DeviceEntity>> getDevice(
@RequestHeader(value = "X-Internal-Token", required = false) String token,
@PathVariable String deviceId) {
if (!isAllowed(token)) {
return ResponseEntity.status(403).body(ApiResponse.error(403, "Forbidden"));
}
List<DeviceEntity> devices = deviceService.findByDeviceId(deviceId);
if (devices.isEmpty()) {
return ResponseEntity.ok(ApiResponse.error(404, "Device not found"));
}
return ResponseEntity.ok(ApiResponse.success(devices));
return deviceService.findByDeviceId(deviceId)
.map(d -> ResponseEntity.ok(ApiResponse.success(d)))
.orElse(ResponseEntity.ok(ApiResponse.error(404, "Device not found")));
}
private boolean isAllowed(String token) {

查看文件

@ -4,12 +4,10 @@ import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import java.time.LocalDateTime;
@Entity
@Table(name = "devices",
uniqueConstraints = @UniqueConstraint(name = "uk_app_key_device_id", columnNames = {"app_key", "device_id"}))
@Table(name = "devices")
public class DeviceEntity {
@Id

查看文件

@ -9,8 +9,7 @@ import java.util.Optional;
@Repository
public interface DeviceRepository extends JpaRepository<DeviceEntity, String> {
Optional<DeviceEntity> findByAppKeyAndDeviceId(String appKey, String deviceId);
List<DeviceEntity> findByDeviceId(String deviceId);
Optional<DeviceEntity> findByDeviceId(String deviceId);
List<DeviceEntity> findByAppKeyOrderByRegisteredAtDesc(String appKey);
long countByAppKeyAndIsActiveTrue(String appKey);
}

查看文件

@ -34,7 +34,7 @@ public class DeviceService {
this.objectMapper = objectMapper;
}
public List<DeviceEntity> findByDeviceId(String deviceId) {
public Optional<DeviceEntity> findByDeviceId(String deviceId) {
return deviceRepository.findByDeviceId(deviceId);
}
@ -48,8 +48,8 @@ public class DeviceService {
JsonNode userInfo) {
validatePackageName(appKey, packageName);
// Check if device already registered for this app
Optional<DeviceEntity> existingOpt = deviceRepository.findByAppKeyAndDeviceId(appKey, deviceId);
// Check if device already registered
Optional<DeviceEntity> existingOpt = findByDeviceId(deviceId);
if (existingOpt.isPresent()) {
DeviceEntity existing = existingOpt.get();
if (!Boolean.TRUE.equals(existing.getIsActive())) {
@ -58,14 +58,8 @@ public class DeviceService {
// Re-issue token
String token = licenseAuthService.generateToken(appKey, deviceId, existing.getId());
String tokenHash = hashToken(token);
String oldAppKey = existing.getAppKey();
if (oldAppKey == null || oldAppKey.isBlank()) {
if (existing.getAppKey() == null || existing.getAppKey().isBlank()) {
existing.setAppKey(appKey);
} else if (!oldAppKey.equals(appKey)) {
// Device switched to a different app: update appKey and adjust counters
existing.setAppKey(appKey);
appLicenseService.decrementRegisteredDevices(oldAppKey);
appLicenseService.incrementRegisteredDevices(appKey);
}
existing.setDeviceName(firstNonBlank(deviceName, existing.getDeviceName()));
existing.setDeviceModel(firstNonBlank(deviceModel, existing.getDeviceModel()));
@ -126,7 +120,7 @@ public class DeviceService {
return new VerifyResult(false, "Token mismatch");
}
DeviceEntity device = deviceRepository.findByAppKeyAndDeviceId(appKey, deviceId).orElse(null);
DeviceEntity device = findByDeviceId(deviceId).orElse(null);
if (device == null || !Boolean.TRUE.equals(device.getIsActive())) {
return new VerifyResult(false, "Device not found or deactivated");
}

查看文件

@ -2,7 +2,6 @@ package com.xuqm.tenant.controller;
import com.xuqm.common.model.ApiResponse;
import com.xuqm.common.exception.BusinessException;
import com.xuqm.common.security.LicenseFileCrypto;
import com.xuqm.tenant.dto.CreateAppRequest;
import com.xuqm.tenant.entity.AppEntity;
import com.xuqm.tenant.entity.FeatureServiceEntity;
@ -175,34 +174,6 @@ public class AppController {
.body(encrypted.getBytes(java.nio.charset.StandardCharsets.UTF_8));
}
/**
* Parse an uploaded license file and return its decrypted contents.
* Used by the security center to verify license file information.
*/
@PostMapping("/license/parse")
public ResponseEntity<ApiResponse<Map<String, Object>>> parseLicenseFile(@RequestBody Map<String, String> body) {
String content = body.get("content");
if (content == null || content.isBlank()) {
throw new BusinessException("License file content is required");
}
try {
LicenseFileCrypto.LicensePayload payload = LicenseFileCrypto.decrypt(content.trim());
Map<String, Object> data = new java.util.LinkedHashMap<>();
data.put("appKey", payload.appKey());
data.put("appName", payload.appName());
data.put("packageName", payload.packageName());
data.put("iosBundleId", payload.iosBundleId());
data.put("harmonyBundleName", payload.harmonyBundleName());
data.put("baseUrl", payload.baseUrl());
data.put("serverUrl", payload.serverUrl());
return ResponseEntity.ok(ApiResponse.success(data));
} catch (IllegalArgumentException e) {
throw new BusinessException("Invalid license file: " + e.getMessage());
} catch (Exception e) {
throw new BusinessException("Failed to parse license file: " + e.getMessage());
}
}
private static String sanitizeFileName(String value) {
String name = value == null || value.isBlank() ? "license" : value.trim();
return name.replaceAll("[\\\\/:*?\"<>|\\s]+", "_");