Browse Source

Merge pull request #16288 from MazurenkoNick/feature/edge-license-v2-proxy

Add Proxy edge license V2 support
pull/16318/head
Viacheslav Klimov 2 months ago
committed by GitHub
parent
commit
2a9ab409d8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      application/src/main/java/org/thingsboard/server/config/ThingsboardSecurityConfiguration.java
  2. 29
      application/src/main/java/org/thingsboard/server/controller/EdgeController.java
  3. 35
      application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java
  4. 4
      application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java

2
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. */ /** 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 CUSTOM_MENU_ENTRY_POINT = "/api/customMenu";
public static final String ALLOWED_PERMISSIONS_ENTRY_POINT = "/api/permissions/allowedPermissions"; 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 * 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 * locked again at runtime. Only {@link #SETUP_PROTECTED_ENTRY_POINTS} is locked, so the Angular

29
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<JsonNode> 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<JsonNode> 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) { private void cleanUpLicenseKey(Edge edge) {
edge.setEdgeLicenseKey(null); edge.setEdgeLicenseKey(null);
} }

35
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); new HttpEntity<>(request, headers), JsonNode.class);
log.trace("checkInstance response: {}", response); 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 // 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<JsonNode>(response.getBody(), response.getStatusCode()); return new ResponseEntity<>(response.getBody(), response.getStatusCode());
} }
@Override @Override
@ -80,7 +80,38 @@ public class DefaultEdgeLicenseService implements EdgeLicenseService {
null, JsonNode.class, params); null, JsonNode.class, params);
log.trace("activateInstance response: {}", response); 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 // 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<JsonNode>(response.getBody(), response.getStatusCode()); return new ResponseEntity<>(response.getBody(), response.getStatusCode());
}
@Override
public ResponseEntity<JsonNode> checkInstanceV2(JsonNode request) {
log.trace("checkInstance V2 [{}]", request);
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
ResponseEntity<JsonNode> 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<JsonNode> activateInstanceV2(String edgeLicenseSecret, String releaseDate, String clusterId, String protocolVersion) {
log.trace("activateInstance V2 [{}][{}][{}]", releaseDate, clusterId, protocolVersion);
Map<String, String> 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<JsonNode> 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() { private RestTemplate initRestTemplate() {

4
application/src/main/java/org/thingsboard/server/service/edge/EdgeLicenseService.java

@ -10,4 +10,8 @@ public interface EdgeLicenseService {
ResponseEntity<JsonNode> checkInstance(JsonNode request); ResponseEntity<JsonNode> checkInstance(JsonNode request);
ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate); ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate);
ResponseEntity<JsonNode> checkInstanceV2(JsonNode request);
ResponseEntity<JsonNode> activateInstanceV2(String licenseSecret, String releaseDate, String clusterId, String protocolVersion);
} }

Loading…
Cancel
Save