Browse Source

lwm2m - profile&device bootstrap M4

pull/5520/head
nickAS21 5 years ago
parent
commit
e1442c38bb
  1. 9
      application/src/main/java/org/thingsboard/server/controller/Lwm2mController.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MService.java
  3. 12
      application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java
  4. 3
      common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MBootstrapServerConfig.java
  5. 3
      common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MBootstrapServersConfiguration.java
  6. 6
      common/data/src/main/java/org/thingsboard/server/common/data/lwm2m/ServerSecurityConfig.java
  7. 11
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java

9
application/src/main/java/org/thingsboard/server/controller/Lwm2mController.java

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

2
application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MService.java

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

12
application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java

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

3
common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MBootstrapServerConfig.java

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

3
common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MBootstrapServersConfiguration.java

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

6
common/data/src/main/java/org/thingsboard/server/common/data/lwm2m/ServerSecurityConfig.java

@ -18,10 +18,14 @@ package org.thingsboard.server.common.data.lwm2m;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerConfig;
@ApiModel @ApiModel
@Data @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) @ApiModelProperty(position = 1, value = "Is Bootstrap Server or Lwm2m Server", example = "true or false", readOnly = true)
protected boolean bootstrapServerIs = true; protected boolean bootstrapServerIs = true;
@ApiModelProperty(position = 2, value = "Host for 'No Security' mode", example = "0.0.0.0", readOnly = true) @ApiModelProperty(position = 2, value = "Host for 'No Security' mode", example = "0.0.0.0", readOnly = true)

11
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java

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

Loading…
Cancel
Save