lwm2m - profile&device bootstrap M4

This commit is contained in:
nickAS21 2021-11-08 21:56:26 +02:00
parent f24924ddf2
commit e1442c38bb
7 changed files with 35 additions and 11 deletions

View File

@ -37,6 +37,7 @@ import org.thingsboard.server.service.lwm2m.LwM2MService;
import org.thingsboard.server.service.lwm2m.LwM2MServiceImpl;
import org.thingsboard.server.service.security.permission.Resource;
import java.util.List;
import java.util.Map;
import static org.thingsboard.server.controller.ControllerConstants.IS_BOOTSTRAP_SERVER_PARAM_DESCRIPTION;
@ -61,13 +62,11 @@ public class Lwm2mController extends BaseController {
TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
produces = "application/json")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{isBootstrapServer}", method = RequestMethod.GET)
@RequestMapping(value = "/lwm2m/deviceProfile/bootstrap", method = RequestMethod.GET)
@ResponseBody
public ServerSecurityConfig getLwm2mBootstrapSecurityInfo(
@ApiParam(value = IS_BOOTSTRAP_SERVER_PARAM_DESCRIPTION)
@PathVariable(IS_BOOTSTRAP_SERVER) boolean bootstrapServer) throws ThingsboardException {
public ServerSecurityConfig [] getLwm2mBootstrapSecurityInfo() throws ThingsboardException {
try {
return lwM2MService.getServerSecurityInfo(bootstrapServer);
return lwM2MService.getServerSecurityInfo();
} catch (Exception e) {
throw handleException(e);
}

View File

@ -19,6 +19,6 @@ import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
public interface LwM2MService {
ServerSecurityConfig getServerSecurityInfo(boolean bootstrapServer);
ServerSecurityConfig [] getServerSecurityInfo();
}

View File

@ -26,6 +26,8 @@ import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
@ -36,10 +38,12 @@ public class LwM2MServiceImpl implements LwM2MService {
private final LwM2MTransportBootstrapConfig bootstrapConfig;
@Override
public ServerSecurityConfig getServerSecurityInfo(boolean bootstrapServer) {
ServerSecurityConfig result = getServerSecurityConfig(bootstrapServer ? bootstrapConfig : serverConfig);
result.setBootstrapServerIs(bootstrapServer);
return result;
public ServerSecurityConfig [] getServerSecurityInfo() {
ServerSecurityConfig bootstrapServer = getServerSecurityConfig(bootstrapConfig);
bootstrapServer.setBootstrapServerIs(true);
ServerSecurityConfig lwm2mServer = getServerSecurityConfig(serverConfig);
lwm2mServer.setBootstrapServerIs(false);
return new ServerSecurityConfig[] {bootstrapServer, lwm2mServer};
}
private ServerSecurityConfig getServerSecurityConfig(LwM2MSecureServerConfig serverConfig) {

View File

@ -19,6 +19,9 @@ import lombok.Data;
@Data
public class LwM2MBootstrapServerConfig {
protected Integer shortServerId = 123;
private Integer shortId = 123;
private Integer lifetime = 300;
private Integer defaultMinPeriod = 1;

View File

@ -17,10 +17,13 @@ package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap;
import lombok.Data;
import java.util.List;
@Data
public class LwM2MBootstrapServersConfiguration {
//TODO
List<LwM2MBootstrapServerCredential> serversConfiguration;
// List <LwM2MBootstrapServersConfiguration> LwM2MBootstrapServersConfigurations;
// LwM2MBootstrapServersConfiguration: Integer shortId, LwM2MBootstrapServerConfig serverConfig; LwM2MBootstrapServerCredential serverSecurity.

View File

@ -18,10 +18,14 @@ package org.thingsboard.server.common.data.lwm2m;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerConfig;
@ApiModel
@Data
public class ServerSecurityConfig {
public class ServerSecurityConfig extends LwM2MBootstrapServerConfig {
protected Integer shortServerId = 123;
@ApiModelProperty(position = 1, value = "Is Bootstrap Server or Lwm2m Server", example = "true or false", readOnly = true)
protected boolean bootstrapServerIs = true;
@ApiModelProperty(position = 2, value = "Host for 'No Security' mode", example = "0.0.0.0", readOnly = true)

View File

@ -23,12 +23,18 @@ import org.eclipse.leshan.core.SecurityMode;
import org.eclipse.leshan.core.request.BindingMode;
import org.eclipse.leshan.core.util.Hex;
import org.eclipse.leshan.server.bootstrap.BootstrapConfig;
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredential;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Data
public class LwM2MBootstrapConfig implements Serializable {
List<LwM2MBootstrapServerCredential> serversConfiguration;
LwM2MBootstrapClientCredential bootstrapClientCredential;
/*
interface BootstrapSecurityConfig
servers: BootstrapServersSecurityConfig,
@ -68,6 +74,11 @@ public class LwM2MBootstrapConfig implements Serializable {
@Setter
private LwM2MServerBootstrap lwm2mServer;
public LwM2MBootstrapConfig(List<LwM2MBootstrapServerCredential> serversConfiguration, LwM2MBootstrapClientCredential bootstrapClientCredential) {
this.serversConfiguration = serversConfiguration;
this.bootstrapClientCredential = bootstrapClientCredential;
}
@JsonIgnore
public BootstrapConfig getLwM2MBootstrapConfig() {
BootstrapConfig configBs = new BootstrapConfig();