From c12e6daa533893f1ae84e8bcca0ccfce6629b182 Mon Sep 17 00:00:00 2001 From: Nikita Mazurenko Date: Mon, 12 Oct 2026 11:26:33 +0200 Subject: [PATCH] Proxy edge license V2 checkInstance/activateInstance to the license portal Edge 4.4.0.1 moves to license client 3.0.x, which talks /api/v2/license/*. Restores the proxy from #4306 and forwards clusterId (required by the portal's V2 activateInstance) and protocolVersion. --- .../ThingsboardSecurityConfiguration.java | 2 +- .../server/controller/EdgeController.java | 29 +++++++++++++++ .../edge/DefaultEdgeLicenseService.java | 35 +++++++++++++++++-- .../service/edge/EdgeLicenseService.java | 4 +++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/config/ThingsboardSecurityConfiguration.java b/application/src/main/java/org/thingsboard/server/config/ThingsboardSecurityConfiguration.java index 9d5f734bf4..a064a5bbaf 100644 --- a/application/src/main/java/org/thingsboard/server/config/ThingsboardSecurityConfiguration.java +++ b/application/src/main/java/org/thingsboard/server/config/ThingsboardSecurityConfiguration.java @@ -134,7 +134,7 @@ public class ThingsboardSecurityConfiguration { /** Session bootstrap, exempt for GET only: {@code POST} on the same path creates a custom menu. */ public static final String CUSTOM_MENU_ENTRY_POINT = "/api/customMenu"; public static final String ALLOWED_PERMISSIONS_ENTRY_POINT = "/api/permissions/allowedPermissions"; - protected static final String[] NON_TOKEN_BASED_AUTH_ENTRY_POINTS = new String[]{"/index.html", "/assets/**", "/static/**", "/api/noauth/**", "/webjars/**", "/api/license/**", "/api/images/public/**", "/api/v2/report/public/**", "/.well-known/**"}; + protected static final String[] NON_TOKEN_BASED_AUTH_ENTRY_POINTS = new String[]{"/index.html", "/assets/**", "/static/**", "/api/noauth/**", "/webjars/**", "/api/license/**", "/api/v2/license/**", "/api/images/public/**", "/api/v2/report/public/**", "/.well-known/**"}; /** * API entry points that stay reachable while the setup is incomplete, or while a provisioned instance is * locked again at runtime. Only {@link #SETUP_PROTECTED_ENTRY_POINTS} is locked, so the Angular diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index 26c6a9fc54..af73926527 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -671,6 +671,35 @@ public class EdgeController extends BaseController { } } + @ApiOperation(value = "Check edge license (checkInstance)", + notes = "Checks license request (V1/V2) from edge service by forwarding request to license portal.") + @PostMapping(value = "/v2/license/checkInstance") + public ResponseEntity checkInstanceV2(@RequestBody JsonNode request) throws ThingsboardException { + log.debug("Checking instance [{}]", request); + try { + return edgeLicenseService.checkInstanceV2(request); + } catch (Exception e) { + log.error("Error occurred: [{}]", e.getMessage(), e); + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); + } + } + + @ApiOperation(value = "Activate edge instance (activateInstance)", + notes = "Activates edge license (V1/V2) on license portal.") + @PostMapping(value = "/v2/license/activateInstance", params = {"licenseSecret", "releaseDate", "clusterId"}) + public ResponseEntity activateInstanceV2(@RequestParam String licenseSecret, + @RequestParam String releaseDate, + @RequestParam String clusterId, + @RequestParam(required = false) String protocolVersion) throws ThingsboardException { + log.debug("Activating instance [{}], [{}], [{}], [{}]", licenseSecret, releaseDate, clusterId, protocolVersion); + try { + return edgeLicenseService.activateInstanceV2(licenseSecret, releaseDate, clusterId, protocolVersion); + } catch (Exception e) { + log.error("Error occurred: [{}]", e.getMessage(), e); + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); + } + } + private void cleanUpLicenseKey(Edge edge) { edge.setEdgeLicenseKey(null); } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java index 9186e307dd..45263ef7fd 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java @@ -66,7 +66,7 @@ public class DefaultEdgeLicenseService implements EdgeLicenseService { new HttpEntity<>(request, headers), JsonNode.class); log.trace("checkInstance response: {}", response); // removing headers from response of the license server, because it might be a conflict with the proxy from we are accepting incoming connections - return new ResponseEntity(response.getBody(), response.getStatusCode()); + return new ResponseEntity<>(response.getBody(), response.getStatusCode()); } @Override @@ -80,7 +80,38 @@ public class DefaultEdgeLicenseService implements EdgeLicenseService { null, JsonNode.class, params); log.trace("activateInstance response: {}", response); // removing headers from response of the license server, because it might be a conflict with the proxy from we are accepting incoming connections - return new ResponseEntity(response.getBody(), response.getStatusCode()); + return new ResponseEntity<>(response.getBody(), response.getStatusCode()); + } + + @Override + public ResponseEntity checkInstanceV2(JsonNode request) { + log.trace("checkInstance V2 [{}]", request); + var headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + ResponseEntity response = this.restTemplate.postForEntity( + EDGE_LICENSE_SERVER_ENDPOINT + "/api/v2/license/checkInstance", + new HttpEntity<>(request, headers), JsonNode.class); + log.trace("checkInstance V2 response: {}", response); + // removing headers from response of the license server, because it might be a conflict with the proxy from we are accepting incoming connections + return new ResponseEntity<>(response.getBody(), response.getStatusCode()); + } + + @Override + public ResponseEntity activateInstanceV2(String edgeLicenseSecret, String releaseDate, String clusterId, String protocolVersion) { + log.trace("activateInstance V2 [{}][{}][{}]", releaseDate, clusterId, protocolVersion); + Map params = new HashMap<>(); + params.put("licenseSecret", edgeLicenseSecret); + params.put("releaseDate", releaseDate); + params.put("clusterId", clusterId); + String url = EDGE_LICENSE_SERVER_ENDPOINT + "/api/v2/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}&clusterId={clusterId}"; + if (protocolVersion != null) { + params.put("protocolVersion", protocolVersion); + url += "&protocolVersion={protocolVersion}"; + } + ResponseEntity response = this.restTemplate.postForEntity(url, null, JsonNode.class, params); + log.trace("activateInstance V2 response: {}", response); + // removing headers from response of the license server, because it might be a conflict with the proxy from we are accepting incoming connections + return new ResponseEntity<>(response.getBody(), response.getStatusCode()); } private RestTemplate initRestTemplate() { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java b/application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java index 0f2ca9dccf..bc796b02b1 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java @@ -10,4 +10,8 @@ public interface EdgeLicenseService { ResponseEntity checkInstance(JsonNode request); ResponseEntity activateInstance(String licenseSecret, String releaseDate); + + ResponseEntity checkInstanceV2(JsonNode request); + + ResponseEntity activateInstanceV2(String licenseSecret, String releaseDate, String clusterId, String protocolVersion); }