Commit cb3353a32d3ea39b1645f8ee9f3368219b417435

Authored by nickAS21
1 parent 17700fe1

Lwm2m: backEnd: refactoring start server/bootstrap without different secure

@@ -635,7 +635,7 @@ transport: @@ -635,7 +635,7 @@ transport:
635 private_s: "${LWM2M_SERVER_PRIVATE_S_BS:9dbdbb073fc63570693a9aaf1013414e261c571f27e27fc6a8c1c2ad9347875a}" 635 private_s: "${LWM2M_SERVER_PRIVATE_S_BS:9dbdbb073fc63570693a9aaf1013414e261c571f27e27fc6a8c1c2ad9347875a}"
636 # Only Certificate_x509: 636 # Only Certificate_x509:
637 alias: "${LWM2M_KEYSTORE_ALIAS_BOOTSTRAP:bootstrap}" 637 alias: "${LWM2M_KEYSTORE_ALIAS_BOOTSTRAP:bootstrap}"
638 - # Redis 638 + # Redis
639 redis_url: "${LWM2M_REDIS_URL:''}" 639 redis_url: "${LWM2M_REDIS_URL:''}"
640 640
641 swagger: 641 swagger:
@@ -61,7 +61,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandle @@ -61,7 +61,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandle
61 61
62 @Slf4j 62 @Slf4j
63 @Component 63 @Component
64 -@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true'&& '${transport.lwm2m.bootstrap.enable:false}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true'&& '${transport.lwm2m.bootstrap.enable}'=='true')") 64 +@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true'&& '${transport.lwm2m.bootstrap.enable:false}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled:false}'=='true'&& '${transport.lwm2m.bootstrap.enable:false}'=='true')")
65 public class LwM2MTransportBootstrapServerConfiguration { 65 public class LwM2MTransportBootstrapServerConfiguration {
66 private PublicKey publicKey; 66 private PublicKey publicKey;
67 private PrivateKey privateKey; 67 private PrivateKey privateKey;
@@ -80,18 +80,21 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -80,18 +80,21 @@ public class LwM2MTransportBootstrapServerConfiguration {
80 80
81 @Primary 81 @Primary
82 @Bean(name = "leshanBootstrapX509") 82 @Bean(name = "leshanBootstrapX509")
  83 + @ConditionalOnExpression("('${transport.lwm2m.bootstrap.secure.start_x509:false}'=='true')")
83 public LeshanBootstrapServer getLeshanBootstrapServerX509() { 84 public LeshanBootstrapServer getLeshanBootstrapServerX509() {
84 log.info("Prepare and start BootstrapServerX509... PostConstruct"); 85 log.info("Prepare and start BootstrapServerX509... PostConstruct");
85 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecX509(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortX509(), X509); 86 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecX509(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortX509(), X509);
86 } 87 }
87 88
88 @Bean(name = "leshanBootstrapPsk") 89 @Bean(name = "leshanBootstrapPsk")
  90 + @ConditionalOnExpression("('${transport.lwm2m.bootstrap.secure.start_psk:false}'=='true')")
89 public LeshanBootstrapServer getLeshanBootstrapServerPsk() { 91 public LeshanBootstrapServer getLeshanBootstrapServerPsk() {
90 log.info("Prepare and start BootstrapServerRsk... PostConstruct"); 92 log.info("Prepare and start BootstrapServerRsk... PostConstruct");
91 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecPsk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortPsk(), PSK); 93 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecPsk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortPsk(), PSK);
92 } 94 }
93 95
94 @Bean(name = "leshanBootstrapRpk") 96 @Bean(name = "leshanBootstrapRpk")
  97 + @ConditionalOnExpression("('${transport.lwm2m.bootstrap.secure.start_rpk:false}'=='true')")
95 public LeshanBootstrapServer getLeshanBootstrapServerRpk() { 98 public LeshanBootstrapServer getLeshanBootstrapServerRpk() {
96 log.info("Prepare and start BootstrapServerRpk... PostConstruct"); 99 log.info("Prepare and start BootstrapServerRpk... PostConstruct");
97 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecRpk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortRpk(), RPK); 100 return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecRpk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortRpk(), RPK);
@@ -27,18 +27,18 @@ import javax.annotation.PreDestroy; @@ -27,18 +27,18 @@ import javax.annotation.PreDestroy;
27 27
28 @Slf4j 28 @Slf4j
29 @Service 29 @Service
30 -@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled}'=='true'&& '${transport.lwm2m.bootstrap.enable}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true'&& '${transport.lwm2m.bootstrap.enable}'=='true')") 30 +@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true'&& '${transport.lwm2m.bootstrap.enable:false}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled:false}'=='true'&& '${transport.lwm2m.bootstrap.enable:false}'=='true')")
31 public class LwM2MTransportBootstrapServerInitializer { 31 public class LwM2MTransportBootstrapServerInitializer {
32 32
33 - @Autowired 33 + @Autowired(required = false)
34 @Qualifier("leshanBootstrapX509") 34 @Qualifier("leshanBootstrapX509")
35 private LeshanBootstrapServer lhBServerCert; 35 private LeshanBootstrapServer lhBServerCert;
36 36
37 - @Autowired 37 + @Autowired(required = false)
38 @Qualifier("leshanBootstrapPsk") 38 @Qualifier("leshanBootstrapPsk")
39 private LeshanBootstrapServer lhBServerPsk; 39 private LeshanBootstrapServer lhBServerPsk;
40 40
41 - @Autowired 41 + @Autowired(required = false)
42 @Qualifier("leshanBootstrapRpk") 42 @Qualifier("leshanBootstrapRpk")
43 private LeshanBootstrapServer lhBServerRpk; 43 private LeshanBootstrapServer lhBServerRpk;
44 44
@@ -85,24 +85,27 @@ public class LwM2MTransportServerConfiguration { @@ -85,24 +85,27 @@ public class LwM2MTransportServerConfiguration {
85 private LwM2mInMemorySecurityStore lwM2mInMemorySecurityStore; 85 private LwM2mInMemorySecurityStore lwM2mInMemorySecurityStore;
86 86
87 @Primary 87 @Primary
88 - @Bean(name = "leshanServerX509")  
89 - public LeshanServer getLeshanServerX509() {  
90 - log.info("Starting LwM2M transport ServerX509... PostConstruct");  
91 - return getLeshanServer(this.context.getCtxServer().getServerPortNoSecX509(), this.context.getCtxServer().getServerPortX509(), X509);  
92 - }  
93 -  
94 @Bean(name = "leshanServerPsk") 88 @Bean(name = "leshanServerPsk")
  89 + @ConditionalOnExpression("('${transport.lwm2m.server.secure.start_psk:false}'=='true')")
95 public LeshanServer getLeshanServerPsk() { 90 public LeshanServer getLeshanServerPsk() {
96 log.info("Starting LwM2M transport ServerPsk... PostConstruct"); 91 log.info("Starting LwM2M transport ServerPsk... PostConstruct");
97 return getLeshanServer(this.context.getCtxServer().getServerPortNoSecPsk(), this.context.getCtxServer().getServerPortPsk(), PSK); 92 return getLeshanServer(this.context.getCtxServer().getServerPortNoSecPsk(), this.context.getCtxServer().getServerPortPsk(), PSK);
98 } 93 }
99 94
100 @Bean(name = "leshanServerRpk") 95 @Bean(name = "leshanServerRpk")
  96 + @ConditionalOnExpression("('${transport.lwm2m.server.secure.start_rpk:false}'=='true')")
101 public LeshanServer getLeshanServerRpk() { 97 public LeshanServer getLeshanServerRpk() {
102 log.info("Starting LwM2M transport ServerRpk... PostConstruct"); 98 log.info("Starting LwM2M transport ServerRpk... PostConstruct");
103 return getLeshanServer(this.context.getCtxServer().getServerPortNoSecRpk(), this.context.getCtxServer().getServerPortRpk(), RPK); 99 return getLeshanServer(this.context.getCtxServer().getServerPortNoSecRpk(), this.context.getCtxServer().getServerPortRpk(), RPK);
104 } 100 }
105 101
  102 + @Bean(name = "leshanServerX509")
  103 + @ConditionalOnExpression("('${transport.lwm2m.server.secure.start_x509:false}'=='true')")
  104 + public LeshanServer getLeshanServerX509() {
  105 + log.info("Starting LwM2M transport ServerX509... PostConstruct");
  106 + return getLeshanServer(this.context.getCtxServer().getServerPortNoSecX509(), this.context.getCtxServer().getServerPortX509(), X509);
  107 + }
  108 +
106 private LeshanServer getLeshanServer(Integer serverPortNoSec, Integer serverSecurePort, LwM2MSecurityMode dtlsMode) { 109 private LeshanServer getLeshanServer(Integer serverPortNoSec, Integer serverSecurePort, LwM2MSecurityMode dtlsMode) {
107 LeshanServerBuilder builder = new LeshanServerBuilder(); 110 LeshanServerBuilder builder = new LeshanServerBuilder();
108 builder.setLocalAddress(this.context.getCtxServer().getServerHost(), serverPortNoSec); 111 builder.setLocalAddress(this.context.getCtxServer().getServerHost(), serverPortNoSec);
@@ -35,15 +35,15 @@ public class LwM2MTransportServerInitializer { @@ -35,15 +35,15 @@ public class LwM2MTransportServerInitializer {
35 @Autowired 35 @Autowired
36 private LwM2MTransportServiceImpl service; 36 private LwM2MTransportServiceImpl service;
37 37
38 - @Autowired 38 + @Autowired(required = false)
39 @Qualifier("leshanServerX509") 39 @Qualifier("leshanServerX509")
40 private LeshanServer lhServerX509; 40 private LeshanServer lhServerX509;
41 41
42 - @Autowired 42 + @Autowired(required = false)
43 @Qualifier("leshanServerPsk") 43 @Qualifier("leshanServerPsk")
44 private LeshanServer lhServerPsk; 44 private LeshanServer lhServerPsk;
45 45
46 - @Autowired 46 + @Autowired(required = false)
47 @Qualifier("leshanServerRpk") 47 @Qualifier("leshanServerRpk")
48 private LeshanServer lhServerRpk; 48 private LeshanServer lhServerRpk;
49 49