Showing
29 changed files
with
225 additions
and
384 deletions
@@ -15,15 +15,14 @@ | @@ -15,15 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.transport.lwm2m.bootstrap; | 16 | package org.thingsboard.server.transport.lwm2m.bootstrap; |
17 | 17 | ||
18 | +import lombok.RequiredArgsConstructor; | ||
18 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; | 20 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; |
20 | import org.eclipse.leshan.core.util.Hex; | 21 | import org.eclipse.leshan.core.util.Hex; |
21 | import org.eclipse.leshan.server.bootstrap.BootstrapSessionManager; | 22 | import org.eclipse.leshan.server.bootstrap.BootstrapSessionManager; |
22 | import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServer; | 23 | import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServer; |
23 | import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServerBuilder; | 24 | import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServerBuilder; |
24 | -import org.springframework.beans.factory.annotation.Autowired; | ||
25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
26 | -import org.springframework.context.annotation.Bean; | ||
27 | import org.springframework.stereotype.Component; | 26 | import org.springframework.stereotype.Component; |
28 | import org.thingsboard.server.common.data.StringUtils; | 27 | import org.thingsboard.server.common.data.StringUtils; |
29 | import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapSecurityStore; | 28 | import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapSecurityStore; |
@@ -31,8 +30,10 @@ import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MInMemoryBoot | @@ -31,8 +30,10 @@ import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MInMemoryBoot | ||
31 | import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2mDefaultBootstrapSessionManager; | 30 | import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2mDefaultBootstrapSessionManager; |
32 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; | 31 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; |
33 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; | 32 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
34 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; | 33 | +import org.thingsboard.server.transport.lwm2m.secure.LWM2MGenerationPSkRPkECC; |
35 | 34 | ||
35 | +import javax.annotation.PostConstruct; | ||
36 | +import javax.annotation.PreDestroy; | ||
36 | import java.math.BigInteger; | 37 | import java.math.BigInteger; |
37 | import java.security.AlgorithmParameters; | 38 | import java.security.AlgorithmParameters; |
38 | import java.security.KeyFactory; | 39 | import java.security.KeyFactory; |
@@ -62,38 +63,45 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mNetworkConfig.g | @@ -62,38 +63,45 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mNetworkConfig.g | ||
62 | 63 | ||
63 | @Slf4j | 64 | @Slf4j |
64 | @Component | 65 | @Component |
65 | -@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')") | 66 | +@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')") |
67 | +@RequiredArgsConstructor | ||
66 | public class LwM2MTransportBootstrapServerConfiguration { | 68 | public class LwM2MTransportBootstrapServerConfiguration { |
67 | private PublicKey publicKey; | 69 | private PublicKey publicKey; |
68 | private PrivateKey privateKey; | 70 | private PrivateKey privateKey; |
69 | private boolean pskMode = false; | 71 | private boolean pskMode = false; |
70 | 72 | ||
71 | - @Autowired | ||
72 | - private LwM2MTransportServerConfig serverConfig; | 73 | + private final LwM2MTransportServerConfig serverConfig; |
74 | + private final LwM2MTransportBootstrapConfig bootstrapConfig; | ||
75 | + private final LwM2MBootstrapSecurityStore lwM2MBootstrapSecurityStore; | ||
76 | + private final LwM2MInMemoryBootstrapConfigStore lwM2MInMemoryBootstrapConfigStore; | ||
73 | 77 | ||
74 | - @Autowired | ||
75 | - private LwM2MTransportContextBootstrap contextBs; | ||
76 | - | ||
77 | - @Autowired | ||
78 | - private LwM2MBootstrapSecurityStore lwM2MBootstrapSecurityStore; | ||
79 | - | ||
80 | - @Autowired | ||
81 | - private LwM2MInMemoryBootstrapConfigStore lwM2MInMemoryBootstrapConfigStore; | 78 | + private LeshanBootstrapServer server; |
82 | 79 | ||
80 | + @PostConstruct | ||
81 | + public void init() { | ||
82 | + if (serverConfig.getEnableGenNewKeyPskRpk()) { | ||
83 | + new LWM2MGenerationPSkRPkECC(); | ||
84 | + } | ||
85 | + log.info("Starting LwM2M transport bootstrap server..."); | ||
86 | + this.server = getLhBootstrapServer(); | ||
87 | + this.server.start(); | ||
88 | + log.info("Started LwM2M transport bootstrap server."); | ||
89 | + } | ||
83 | 90 | ||
84 | - @Bean | ||
85 | - public LeshanBootstrapServer getLeshanBootstrapServer() { | ||
86 | - log.info("Prepare and start BootstrapServer... PostConstruct"); | ||
87 | - return this.getLhBootstrapServer(this.contextBs.getCtxBootStrap().getPort(), this.contextBs.getCtxBootStrap().getSecurePort()); | 91 | + @PreDestroy |
92 | + public void shutdown() { | ||
93 | + log.info("Stopping LwM2M transport bootstrap server!"); | ||
94 | + server.destroy(); | ||
95 | + log.info("LwM2M transport bootstrap server stopped!"); | ||
88 | } | 96 | } |
89 | 97 | ||
90 | - public LeshanBootstrapServer getLhBootstrapServer(Integer bootstrapPortNoSec, Integer bootstrapSecurePort) { | 98 | + public LeshanBootstrapServer getLhBootstrapServer() { |
91 | LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder(); | 99 | LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder(); |
92 | - builder.setLocalAddress(this.contextBs.getCtxBootStrap().getHost(), bootstrapPortNoSec); | ||
93 | - builder.setLocalSecureAddress(this.contextBs.getCtxBootStrap().getSecureHost(), bootstrapSecurePort); | 100 | + builder.setLocalAddress(bootstrapConfig.getHost(), bootstrapConfig.getPort()); |
101 | + builder.setLocalSecureAddress(bootstrapConfig.getSecureHost(), bootstrapConfig.getSecurePort()); | ||
94 | 102 | ||
95 | /** Create CoAP Config */ | 103 | /** Create CoAP Config */ |
96 | - builder.setCoapConfig(getCoapConfig(bootstrapPortNoSec, bootstrapSecurePort)); | 104 | + builder.setCoapConfig(getCoapConfig(bootstrapConfig.getPort(), bootstrapConfig.getSecurePort())); |
97 | 105 | ||
98 | /** Define model provider (Create Models )*/ | 106 | /** Define model provider (Create Models )*/ |
99 | 107 | ||
@@ -169,8 +177,8 @@ public class LwM2MTransportBootstrapServerConfiguration { | @@ -169,8 +177,8 @@ public class LwM2MTransportBootstrapServerConfiguration { | ||
169 | * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks | 177 | * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks |
170 | */ | 178 | */ |
171 | try { | 179 | try { |
172 | - X509Certificate serverCertificate = (X509Certificate) serverConfig.getKeyStoreValue().getCertificate(this.contextBs.getCtxBootStrap().getCertificateAlias()); | ||
173 | - PrivateKey privateKey = (PrivateKey) serverConfig.getKeyStoreValue().getKey(this.contextBs.getCtxBootStrap().getCertificateAlias(), serverConfig.getKeyStorePassword() == null ? null : serverConfig.getKeyStorePassword().toCharArray()); | 180 | + X509Certificate serverCertificate = (X509Certificate) serverConfig.getKeyStoreValue().getCertificate(this.bootstrapConfig.getCertificateAlias()); |
181 | + PrivateKey privateKey = (PrivateKey) serverConfig.getKeyStoreValue().getKey(this.bootstrapConfig.getCertificateAlias(), serverConfig.getKeyStorePassword() == null ? null : serverConfig.getKeyStorePassword().toCharArray()); | ||
174 | PublicKey publicKey = serverCertificate.getPublicKey(); | 182 | PublicKey publicKey = serverCertificate.getPublicKey(); |
175 | if (privateKey != null && privateKey.getEncoded().length > 0 && publicKey != null && publicKey.getEncoded().length > 0) { | 183 | if (privateKey != null && privateKey.getEncoded().length > 0 && publicKey != null && publicKey.getEncoded().length > 0) { |
176 | builder.setPublicKey(serverCertificate.getPublicKey()); | 184 | builder.setPublicKey(serverCertificate.getPublicKey()); |
@@ -201,10 +209,10 @@ public class LwM2MTransportBootstrapServerConfiguration { | @@ -201,10 +209,10 @@ public class LwM2MTransportBootstrapServerConfiguration { | ||
201 | private void infoPramsUri(String mode) { | 209 | private void infoPramsUri(String mode) { |
202 | log.info("Bootstrap Server uses [{}]: serverNoSecureURI : [{}:{}], serverSecureURI : [{}:{}]", | 210 | log.info("Bootstrap Server uses [{}]: serverNoSecureURI : [{}:{}], serverSecureURI : [{}:{}]", |
203 | mode, | 211 | mode, |
204 | - this.contextBs.getCtxBootStrap().getHost(), | ||
205 | - this.contextBs.getCtxBootStrap().getPort(), | ||
206 | - this.contextBs.getCtxBootStrap().getSecureHost(), | ||
207 | - this.contextBs.getCtxBootStrap().getSecurePort()); | 212 | + this.bootstrapConfig.getHost(), |
213 | + this.bootstrapConfig.getPort(), | ||
214 | + this.bootstrapConfig.getSecureHost(), | ||
215 | + this.bootstrapConfig.getSecurePort()); | ||
208 | } | 216 | } |
209 | 217 | ||
210 | 218 | ||
@@ -238,7 +246,7 @@ public class LwM2MTransportBootstrapServerConfiguration { | @@ -238,7 +246,7 @@ public class LwM2MTransportBootstrapServerConfiguration { | ||
238 | AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); | 246 | AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); |
239 | algoParameters.init(new ECGenParameterSpec("secp256r1")); | 247 | algoParameters.init(new ECGenParameterSpec("secp256r1")); |
240 | ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); | 248 | ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); |
241 | - LwM2MTransportBootstrapConfig serverConfig = this.contextBs.getCtxBootStrap(); | 249 | + LwM2MTransportBootstrapConfig serverConfig = this.bootstrapConfig; |
242 | if (StringUtils.isNotEmpty(serverConfig.getPublicX()) && StringUtils.isNotEmpty(serverConfig.getPublicY())) { | 250 | if (StringUtils.isNotEmpty(serverConfig.getPublicX()) && StringUtils.isNotEmpty(serverConfig.getPublicY())) { |
243 | /** Get point values */ | 251 | /** Get point values */ |
244 | byte[] publicX = Hex.decodeHex(serverConfig.getPublicX().toCharArray()); | 252 | byte[] publicX = Hex.decodeHex(serverConfig.getPublicX().toCharArray()); |
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/LwM2MTransportBootstrapServerInitializer.java
deleted
100644 → 0
1 | -/** | ||
2 | - * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.thingsboard.server.transport.lwm2m.bootstrap; | ||
17 | - | ||
18 | -import lombok.extern.slf4j.Slf4j; | ||
19 | -import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServer; | ||
20 | -import org.springframework.beans.factory.annotation.Autowired; | ||
21 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
22 | -import org.springframework.stereotype.Service; | ||
23 | - | ||
24 | -import javax.annotation.PostConstruct; | ||
25 | -import javax.annotation.PreDestroy; | ||
26 | - | ||
27 | -@Slf4j | ||
28 | -@Service | ||
29 | -@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')") | ||
30 | -public class LwM2MTransportBootstrapServerInitializer { | ||
31 | - | ||
32 | - @Autowired(required = false) | ||
33 | - private LeshanBootstrapServer lhBServer; | ||
34 | - | ||
35 | - @Autowired | ||
36 | - private LwM2MTransportContextBootstrap contextBS; | ||
37 | - | ||
38 | - @PostConstruct | ||
39 | - public void init() { | ||
40 | - this.lhBServer.start(); | ||
41 | - } | ||
42 | - | ||
43 | - @PreDestroy | ||
44 | - public void shutdown() throws InterruptedException { | ||
45 | - log.info("Stopping LwM2M transport Bootstrap Server!"); | ||
46 | - lhBServer.destroy(); | ||
47 | - log.info("LwM2M transport Bootstrap Server stopped!"); | ||
48 | - } | ||
49 | -} |
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/LwM2MTransportContextBootstrap.java
deleted
100644 → 0
1 | -/** | ||
2 | - * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.thingsboard.server.transport.lwm2m.bootstrap; | ||
17 | -/** | ||
18 | - * Copyright © 2016-2020 The Thingsboard Authors | ||
19 | - * | ||
20 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
21 | - * you may not use this file except in compliance with the License. | ||
22 | - * You may obtain a copy of the License at | ||
23 | - * | ||
24 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
25 | - * | ||
26 | - * Unless required by applicable law or agreed to in writing, software | ||
27 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
28 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
29 | - * See the License for the specific language governing permissions and | ||
30 | - * limitations under the License. | ||
31 | - */ | ||
32 | - | ||
33 | -import lombok.extern.slf4j.Slf4j; | ||
34 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
35 | -import org.springframework.stereotype.Component; | ||
36 | -import org.thingsboard.server.common.transport.TransportContext; | ||
37 | -import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; | ||
38 | - | ||
39 | - | ||
40 | -@Slf4j | ||
41 | -@Component | ||
42 | -@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith'") | ||
43 | -public class LwM2MTransportContextBootstrap extends TransportContext { | ||
44 | - | ||
45 | - private final LwM2MTransportBootstrapConfig lwM2MTransportBootstrapConfig; | ||
46 | - | ||
47 | - public LwM2MTransportContextBootstrap(LwM2MTransportBootstrapConfig ctxBootStrap) { | ||
48 | - this.lwM2MTransportBootstrapConfig = ctxBootStrap; | ||
49 | - } | ||
50 | - | ||
51 | - public LwM2MTransportBootstrapConfig getCtxBootStrap() { | ||
52 | - return this.lwM2MTransportBootstrapConfig; | ||
53 | - } | ||
54 | -} |
@@ -25,12 +25,12 @@ import java.nio.charset.StandardCharsets; | @@ -25,12 +25,12 @@ import java.nio.charset.StandardCharsets; | ||
25 | 25 | ||
26 | @Data | 26 | @Data |
27 | public class LwM2MBootstrapConfig { | 27 | public class LwM2MBootstrapConfig { |
28 | - /** | ||
29 | - * interface BootstrapSecurityConfig | ||
30 | - * servers: BootstrapServersSecurityConfig, | ||
31 | - * bootstrapServer: ServerSecurityConfig, | ||
32 | - * lwm2mServer: ServerSecurityConfig | ||
33 | - * } | 28 | + /* |
29 | + interface BootstrapSecurityConfig | ||
30 | + servers: BootstrapServersSecurityConfig, | ||
31 | + bootstrapServer: ServerSecurityConfig, | ||
32 | + lwm2mServer: ServerSecurityConfig | ||
33 | + } | ||
34 | */ | 34 | */ |
35 | /** -servers | 35 | /** -servers |
36 | * shortId: number, | 36 | * shortId: number, |
@@ -60,10 +60,10 @@ public class LwM2MBootstrapConfig { | @@ -60,10 +60,10 @@ public class LwM2MBootstrapConfig { | ||
60 | 60 | ||
61 | public BootstrapConfig getLwM2MBootstrapConfig() { | 61 | public BootstrapConfig getLwM2MBootstrapConfig() { |
62 | BootstrapConfig configBs = new BootstrapConfig(); | 62 | BootstrapConfig configBs = new BootstrapConfig(); |
63 | - /** Delete old security objects */ | 63 | + /* Delete old security objects */ |
64 | configBs.toDelete.add("/0"); | 64 | configBs.toDelete.add("/0"); |
65 | configBs.toDelete.add("/1"); | 65 | configBs.toDelete.add("/1"); |
66 | - /** Server Configuration (object 1) as defined in LWM2M 1.0.x TS. */ | 66 | + /* Server Configuration (object 1) as defined in LWM2M 1.0.x TS. */ |
67 | BootstrapConfig.ServerConfig server0 = new BootstrapConfig.ServerConfig(); | 67 | BootstrapConfig.ServerConfig server0 = new BootstrapConfig.ServerConfig(); |
68 | server0.shortId = servers.getShortId(); | 68 | server0.shortId = servers.getShortId(); |
69 | server0.lifetime = servers.getLifetime(); | 69 | server0.lifetime = servers.getLifetime(); |
@@ -71,10 +71,10 @@ public class LwM2MBootstrapConfig { | @@ -71,10 +71,10 @@ public class LwM2MBootstrapConfig { | ||
71 | server0.notifIfDisabled = servers.isNotifIfDisabled(); | 71 | server0.notifIfDisabled = servers.isNotifIfDisabled(); |
72 | server0.binding = BindingMode.valueOf(servers.getBinding()); | 72 | server0.binding = BindingMode.valueOf(servers.getBinding()); |
73 | configBs.servers.put(0, server0); | 73 | configBs.servers.put(0, server0); |
74 | - /** Security Configuration (object 0) as defined in LWM2M 1.0.x TS. Bootstrap instance = 0 */ | 74 | + /* Security Configuration (object 0) as defined in LWM2M 1.0.x TS. Bootstrap instance = 0 */ |
75 | this.bootstrapServer.setBootstrapServerIs(true); | 75 | this.bootstrapServer.setBootstrapServerIs(true); |
76 | configBs.security.put(0, setServerSecuruty(this.bootstrapServer.getHost(), this.bootstrapServer.getPort(), this.bootstrapServer.isBootstrapServerIs(), this.bootstrapServer.getSecurityMode(), this.bootstrapServer.getClientPublicKeyOrId(), this.bootstrapServer.getServerPublicKey(), this.bootstrapServer.getClientSecretKey(), this.bootstrapServer.getServerId())); | 76 | configBs.security.put(0, setServerSecuruty(this.bootstrapServer.getHost(), this.bootstrapServer.getPort(), this.bootstrapServer.isBootstrapServerIs(), this.bootstrapServer.getSecurityMode(), this.bootstrapServer.getClientPublicKeyOrId(), this.bootstrapServer.getServerPublicKey(), this.bootstrapServer.getClientSecretKey(), this.bootstrapServer.getServerId())); |
77 | - /** Security Configuration (object 0) as defined in LWM2M 1.0.x TS. Server instance = 1 */ | 77 | + /* Security Configuration (object 0) as defined in LWM2M 1.0.x TS. Server instance = 1 */ |
78 | configBs.security.put(1, setServerSecuruty(this.lwm2mServer.getHost(), this.lwm2mServer.getPort(), this.lwm2mServer.isBootstrapServerIs(), this.lwm2mServer.getSecurityMode(), this.lwm2mServer.getClientPublicKeyOrId(), this.lwm2mServer.getServerPublicKey(), this.lwm2mServer.getClientSecretKey(), this.lwm2mServer.getServerId())); | 78 | configBs.security.put(1, setServerSecuruty(this.lwm2mServer.getHost(), this.lwm2mServer.getPort(), this.lwm2mServer.isBootstrapServerIs(), this.lwm2mServer.getSecurityMode(), this.lwm2mServer.getClientPublicKeyOrId(), this.lwm2mServer.getServerPublicKey(), this.lwm2mServer.getClientSecretKey(), this.lwm2mServer.getServerId())); |
79 | return configBs; | 79 | return configBs; |
80 | } | 80 | } |
@@ -92,9 +92,8 @@ public class LwM2MBootstrapConfig { | @@ -92,9 +92,8 @@ public class LwM2MBootstrapConfig { | ||
92 | } | 92 | } |
93 | 93 | ||
94 | private byte[] setPublicKeyOrId(String publicKeyOrIdStr, String securityMode) { | 94 | private byte[] setPublicKeyOrId(String publicKeyOrIdStr, String securityMode) { |
95 | - byte[] publicKey = (publicKeyOrIdStr == null || publicKeyOrIdStr.isEmpty()) ? new byte[]{} : | 95 | + return (publicKeyOrIdStr == null || publicKeyOrIdStr.isEmpty()) ? new byte[]{} : |
96 | SecurityMode.valueOf(securityMode).equals(SecurityMode.PSK) ? publicKeyOrIdStr.getBytes(StandardCharsets.UTF_8) : | 96 | SecurityMode.valueOf(securityMode).equals(SecurityMode.PSK) ? publicKeyOrIdStr.getBytes(StandardCharsets.UTF_8) : |
97 | Hex.decodeHex(publicKeyOrIdStr.toCharArray()); | 97 | Hex.decodeHex(publicKeyOrIdStr.toCharArray()); |
98 | - return publicKey; | ||
99 | } | 98 | } |
100 | } | 99 | } |
@@ -36,7 +36,7 @@ import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; | @@ -36,7 +36,7 @@ import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; | ||
36 | import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; | 36 | import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; |
37 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; | 37 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; |
38 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; | 38 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; |
39 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil; | 39 | +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; |
40 | 40 | ||
41 | import java.io.IOException; | 41 | import java.io.IOException; |
42 | import java.security.GeneralSecurityException; | 42 | import java.security.GeneralSecurityException; |
@@ -44,12 +44,12 @@ import java.util.Collections; | @@ -44,12 +44,12 @@ import java.util.Collections; | ||
44 | import java.util.List; | 44 | import java.util.List; |
45 | import java.util.UUID; | 45 | import java.util.UUID; |
46 | 46 | ||
47 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.BOOTSTRAP_SERVER; | ||
48 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR; | ||
49 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO; | ||
50 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_SERVER; | ||
51 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.SERVERS; | ||
52 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getBootstrapParametersFromThingsboard; | 47 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.BOOTSTRAP_SERVER; |
48 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_ERROR; | ||
49 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; | ||
50 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_SERVER; | ||
51 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SERVERS; | ||
52 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getBootstrapParametersFromThingsboard; | ||
53 | 53 | ||
54 | @Slf4j | 54 | @Slf4j |
55 | @Service("LwM2MBootstrapSecurityStore") | 55 | @Service("LwM2MBootstrapSecurityStore") |
@@ -72,9 +72,9 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | @@ -72,9 +72,9 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | ||
72 | 72 | ||
73 | @Override | 73 | @Override |
74 | public List<SecurityInfo> getAllByEndpoint(String endPoint) { | 74 | public List<SecurityInfo> getAllByEndpoint(String endPoint) { |
75 | - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(endPoint, LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP); | 75 | + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(endPoint, LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP); |
76 | if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { | 76 | if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { |
77 | - /** add value to store from BootstrapJson */ | 77 | + /* add value to store from BootstrapJson */ |
78 | this.setBootstrapConfigScurityInfo(store); | 78 | this.setBootstrapConfigScurityInfo(store); |
79 | BootstrapConfig bsConfigNew = store.getBootstrapConfig(); | 79 | BootstrapConfig bsConfigNew = store.getBootstrapConfig(); |
80 | if (bsConfigNew != null) { | 80 | if (bsConfigNew != null) { |
@@ -96,9 +96,9 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | @@ -96,9 +96,9 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | ||
96 | 96 | ||
97 | @Override | 97 | @Override |
98 | public SecurityInfo getByIdentity(String identity) { | 98 | public SecurityInfo getByIdentity(String identity) { |
99 | - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP); | 99 | + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP); |
100 | if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { | 100 | if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { |
101 | - /** add value to store from BootstrapJson */ | 101 | + /* add value to store from BootstrapJson */ |
102 | this.setBootstrapConfigScurityInfo(store); | 102 | this.setBootstrapConfigScurityInfo(store); |
103 | BootstrapConfig bsConfig = store.getBootstrapConfig(); | 103 | BootstrapConfig bsConfig = store.getBootstrapConfig(); |
104 | if (bsConfig.security != null) { | 104 | if (bsConfig.security != null) { |
@@ -114,12 +114,12 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | @@ -114,12 +114,12 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { | ||
114 | } | 114 | } |
115 | 115 | ||
116 | private void setBootstrapConfigScurityInfo(ReadResultSecurityStore store) { | 116 | private void setBootstrapConfigScurityInfo(ReadResultSecurityStore store) { |
117 | - /** BootstrapConfig */ | 117 | + /* BootstrapConfig */ |
118 | LwM2MBootstrapConfig lwM2MBootstrapConfig = this.getParametersBootstrap(store); | 118 | LwM2MBootstrapConfig lwM2MBootstrapConfig = this.getParametersBootstrap(store); |
119 | if (lwM2MBootstrapConfig != null) { | 119 | if (lwM2MBootstrapConfig != null) { |
120 | - /** Security info */ | 120 | + /* Security info */ |
121 | switch (SecurityMode.valueOf(lwM2MBootstrapConfig.getBootstrapServer().getSecurityMode())) { | 121 | switch (SecurityMode.valueOf(lwM2MBootstrapConfig.getBootstrapServer().getSecurityMode())) { |
122 | - /** Use RPK only */ | 122 | + /* Use RPK only */ |
123 | case PSK: | 123 | case PSK: |
124 | store.setSecurityInfo(SecurityInfo.newPreSharedKeyInfo(store.getEndPoint(), | 124 | store.setSecurityInfo(SecurityInfo.newPreSharedKeyInfo(store.getEndPoint(), |
125 | lwM2MBootstrapConfig.getBootstrapServer().getClientPublicKeyOrId(), | 125 | lwM2MBootstrapConfig.getBootstrapServer().getClientPublicKeyOrId(), |
@@ -21,6 +21,7 @@ import org.eclipse.leshan.server.bootstrap.InMemoryBootstrapConfigStore; | @@ -21,6 +21,7 @@ import org.eclipse.leshan.server.bootstrap.InMemoryBootstrapConfigStore; | ||
21 | import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException; | 21 | import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException; |
22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
23 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
24 | + | ||
24 | import java.util.Map; | 25 | import java.util.Map; |
25 | import java.util.concurrent.locks.Lock; | 26 | import java.util.concurrent.locks.Lock; |
26 | import java.util.concurrent.locks.ReadWriteLock; | 27 | import java.util.concurrent.locks.ReadWriteLock; |
@@ -58,8 +59,7 @@ public class LwM2MInMemoryBootstrapConfigStore extends InMemoryBootstrapConfigSt | @@ -58,8 +59,7 @@ public class LwM2MInMemoryBootstrapConfigStore extends InMemoryBootstrapConfigSt | ||
58 | public BootstrapConfig remove(String enpoint) { | 59 | public BootstrapConfig remove(String enpoint) { |
59 | writeLock.lock(); | 60 | writeLock.lock(); |
60 | try { | 61 | try { |
61 | - BootstrapConfig res = super.remove(enpoint); | ||
62 | - return res; | 62 | + return super.remove(enpoint); |
63 | } finally { | 63 | } finally { |
64 | writeLock.unlock(); | 64 | writeLock.unlock(); |
65 | } | 65 | } |
@@ -24,7 +24,6 @@ import org.eclipse.leshan.server.security.BootstrapSecurityStore; | @@ -24,7 +24,6 @@ import org.eclipse.leshan.server.security.BootstrapSecurityStore; | ||
24 | import org.eclipse.leshan.server.security.SecurityChecker; | 24 | import org.eclipse.leshan.server.security.SecurityChecker; |
25 | import org.eclipse.leshan.server.security.SecurityInfo; | 25 | import org.eclipse.leshan.server.security.SecurityInfo; |
26 | 26 | ||
27 | -import java.util.Arrays; | ||
28 | import java.util.Collections; | 27 | import java.util.Collections; |
29 | import java.util.List; | 28 | import java.util.List; |
30 | 29 |
@@ -16,15 +16,10 @@ | @@ -16,15 +16,10 @@ | ||
16 | package org.thingsboard.server.transport.lwm2m.config; | 16 | package org.thingsboard.server.transport.lwm2m.config; |
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | -import lombok.Setter; | ||
20 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.beans.factory.annotation.Value; | 20 | import org.springframework.beans.factory.annotation.Value; |
22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
23 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
24 | -import org.thingsboard.server.gen.transport.TransportProtos; | ||
25 | - | ||
26 | -import java.security.PublicKey; | ||
27 | -import java.util.Map; | ||
28 | 23 | ||
29 | @Slf4j | 24 | @Slf4j |
30 | @Component | 25 | @Component |
@@ -27,15 +27,9 @@ import org.springframework.stereotype.Component; | @@ -27,15 +27,9 @@ import org.springframework.stereotype.Component; | ||
27 | import javax.annotation.PostConstruct; | 27 | import javax.annotation.PostConstruct; |
28 | import java.io.File; | 28 | import java.io.File; |
29 | import java.io.FileInputStream; | 29 | import java.io.FileInputStream; |
30 | -import java.io.IOException; | ||
31 | import java.io.InputStream; | 30 | import java.io.InputStream; |
32 | import java.net.URI; | 31 | import java.net.URI; |
33 | -import java.nio.file.Path; | ||
34 | -import java.nio.file.Paths; | ||
35 | import java.security.KeyStore; | 32 | import java.security.KeyStore; |
36 | -import java.security.KeyStoreException; | ||
37 | -import java.security.NoSuchAlgorithmException; | ||
38 | -import java.security.cert.CertificateException; | ||
39 | 33 | ||
40 | @Slf4j | 34 | @Slf4j |
41 | @Component | 35 | @Component |
@@ -17,14 +17,15 @@ package org.thingsboard.server.transport.lwm2m.secure; | @@ -17,14 +17,15 @@ package org.thingsboard.server.transport.lwm2m.secure; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.leshan.core.util.Hex; | 19 | import org.eclipse.leshan.core.util.Hex; |
20 | -import java.security.SecureRandom; | ||
21 | -import java.security.KeyPairGenerator; | 20 | + |
21 | +import java.security.InvalidAlgorithmParameterException; | ||
22 | import java.security.KeyPair; | 22 | import java.security.KeyPair; |
23 | -import java.security.PrivateKey; | ||
24 | -import java.security.PublicKey; | 23 | +import java.security.KeyPairGenerator; |
25 | import java.security.NoSuchAlgorithmException; | 24 | import java.security.NoSuchAlgorithmException; |
26 | import java.security.NoSuchProviderException; | 25 | import java.security.NoSuchProviderException; |
27 | -import java.security.InvalidAlgorithmParameterException; | 26 | +import java.security.PrivateKey; |
27 | +import java.security.PublicKey; | ||
28 | +import java.security.SecureRandom; | ||
28 | import java.security.interfaces.ECPublicKey; | 29 | import java.security.interfaces.ECPublicKey; |
29 | import java.security.spec.ECGenParameterSpec; | 30 | import java.security.spec.ECGenParameterSpec; |
30 | import java.util.Arrays; | 31 | import java.util.Arrays; |
@@ -48,33 +49,31 @@ public class LWM2MGenerationPSkRPkECC { | @@ -48,33 +49,31 @@ public class LWM2MGenerationPSkRPkECC { | ||
48 | } | 49 | } |
49 | 50 | ||
50 | private void generationPSkKey() { | 51 | private void generationPSkKey() { |
51 | - /** PSK */ | 52 | + /* PSK */ |
52 | int lenPSkKey = 32; | 53 | int lenPSkKey = 32; |
53 | - /** Start PSK | ||
54 | - * Clients and Servers MUST support PSK keys of up to 64 bytes in length, as required by [RFC7925] | ||
55 | - * SecureRandom object must be unpredictable, and all SecureRandom output sequences must be cryptographically strong, as described in [RFC4086] | ||
56 | - * */ | 54 | + /* Start PSK |
55 | + Clients and Servers MUST support PSK keys of up to 64 bytes in length, as required by [RFC7925] | ||
56 | + SecureRandom object must be unpredictable, and all SecureRandom output sequences must be cryptographically strong, as described in [RFC4086] | ||
57 | + */ | ||
57 | SecureRandom randomPSK = new SecureRandom(); | 58 | SecureRandom randomPSK = new SecureRandom(); |
58 | - byte bytesPSK[] = new byte[lenPSkKey]; | 59 | + byte[] bytesPSK = new byte[lenPSkKey]; |
59 | randomPSK.nextBytes(bytesPSK); | 60 | randomPSK.nextBytes(bytesPSK); |
60 | log.info("\nCreating new PSK: \n for the next start PSK -> security key: [{}]", Hex.encodeHexString(bytesPSK)); | 61 | log.info("\nCreating new PSK: \n for the next start PSK -> security key: [{}]", Hex.encodeHexString(bytesPSK)); |
61 | } | 62 | } |
62 | 63 | ||
63 | private void generationRPKECCKey() { | 64 | private void generationRPKECCKey() { |
64 | - /** RPK */ | 65 | + /* RPK */ |
65 | String algorithm = "EC"; | 66 | String algorithm = "EC"; |
66 | String provider = "SunEC"; | 67 | String provider = "SunEC"; |
67 | String nameParameterSpec = "secp256r1"; | 68 | String nameParameterSpec = "secp256r1"; |
68 | 69 | ||
69 | - /** Start RPK | ||
70 | - * Elliptic Curve parameters : [secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)] | ||
71 | - * */ | 70 | + /* Start RPK |
71 | + Elliptic Curve parameters : [secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)] | ||
72 | + */ | ||
72 | KeyPairGenerator kpg = null; | 73 | KeyPairGenerator kpg = null; |
73 | try { | 74 | try { |
74 | kpg = KeyPairGenerator.getInstance(algorithm, provider); | 75 | kpg = KeyPairGenerator.getInstance(algorithm, provider); |
75 | - } catch (NoSuchAlgorithmException e) { | ||
76 | - log.error("", e); | ||
77 | - } catch (NoSuchProviderException e) { | 76 | + } catch (NoSuchAlgorithmException | NoSuchProviderException e) { |
78 | log.error("", e); | 77 | log.error("", e); |
79 | } | 78 | } |
80 | ECGenParameterSpec ecsp = new ECGenParameterSpec(nameParameterSpec); | 79 | ECGenParameterSpec ecsp = new ECGenParameterSpec(nameParameterSpec); |
@@ -90,17 +89,17 @@ public class LWM2MGenerationPSkRPkECC { | @@ -90,17 +89,17 @@ public class LWM2MGenerationPSkRPkECC { | ||
90 | 89 | ||
91 | if (pubKey instanceof ECPublicKey) { | 90 | if (pubKey instanceof ECPublicKey) { |
92 | ECPublicKey ecPublicKey = (ECPublicKey) pubKey; | 91 | ECPublicKey ecPublicKey = (ECPublicKey) pubKey; |
93 | - /** Get x coordinate */ | 92 | + /* Get x coordinate */ |
94 | byte[] x = ecPublicKey.getW().getAffineX().toByteArray(); | 93 | byte[] x = ecPublicKey.getW().getAffineX().toByteArray(); |
95 | if (x[0] == 0) | 94 | if (x[0] == 0) |
96 | x = Arrays.copyOfRange(x, 1, x.length); | 95 | x = Arrays.copyOfRange(x, 1, x.length); |
97 | 96 | ||
98 | - /** Get Y coordinate */ | 97 | + /* Get Y coordinate */ |
99 | byte[] y = ecPublicKey.getW().getAffineY().toByteArray(); | 98 | byte[] y = ecPublicKey.getW().getAffineY().toByteArray(); |
100 | if (y[0] == 0) | 99 | if (y[0] == 0) |
101 | y = Arrays.copyOfRange(y, 1, y.length); | 100 | y = Arrays.copyOfRange(y, 1, y.length); |
102 | 101 | ||
103 | - /** Get Curves params */ | 102 | + /* Get Curves params */ |
104 | String privHex = Hex.encodeHexString(privKey.getEncoded()); | 103 | String privHex = Hex.encodeHexString(privKey.getEncoded()); |
105 | log.info("\nCreating new RPK for the next start... \n" + | 104 | log.info("\nCreating new RPK for the next start... \n" + |
106 | " Public Key (Hex): [{}]\n" + | 105 | " Public Key (Hex): [{}]\n" + |
@@ -29,8 +29,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MC | @@ -29,8 +29,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MC | ||
29 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | 29 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
30 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; | 30 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
31 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; | 31 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; |
32 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; | ||
33 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil; | 32 | +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; |
34 | 33 | ||
35 | import java.io.IOException; | 34 | import java.io.IOException; |
36 | import java.security.GeneralSecurityException; | 35 | import java.security.GeneralSecurityException; |
@@ -59,7 +58,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | @@ -59,7 +58,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | ||
59 | * @param keyValue - | 58 | * @param keyValue - |
60 | * @return ValidateDeviceCredentialsResponseMsg and SecurityInfo | 59 | * @return ValidateDeviceCredentialsResponseMsg and SecurityInfo |
61 | */ | 60 | */ |
62 | - public ReadResultSecurityStore createAndValidateCredentialsSecurityInfo(String endpoint, LwM2mTransportHandlerUtil.LwM2mTypeServer keyValue) { | 61 | + public ReadResultSecurityStore createAndValidateCredentialsSecurityInfo(String endpoint, LwM2mTransportUtil.LwM2mTypeServer keyValue) { |
63 | CountDownLatch latch = new CountDownLatch(1); | 62 | CountDownLatch latch = new CountDownLatch(1); |
64 | final ReadResultSecurityStore[] resultSecurityStore = new ReadResultSecurityStore[1]; | 63 | final ReadResultSecurityStore[] resultSecurityStore = new ReadResultSecurityStore[1]; |
65 | context.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(endpoint).build(), | 64 | context.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(endpoint).build(), |
@@ -69,7 +68,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | @@ -69,7 +68,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | ||
69 | String credentialsBody = msg.getCredentialsBody(); | 68 | String credentialsBody = msg.getCredentialsBody(); |
70 | resultSecurityStore[0] = createSecurityInfo(endpoint, credentialsBody, keyValue); | 69 | resultSecurityStore[0] = createSecurityInfo(endpoint, credentialsBody, keyValue); |
71 | resultSecurityStore[0].setMsg(msg); | 70 | resultSecurityStore[0].setMsg(msg); |
72 | - Optional<DeviceProfile> deviceProfileOpt = LwM2mTransportHandlerUtil.decode(msg.getProfileBody().toByteArray()); | 71 | + Optional<DeviceProfile> deviceProfileOpt = LwM2mTransportUtil.decode(msg.getProfileBody().toByteArray()); |
73 | deviceProfileOpt.ifPresent(profile -> resultSecurityStore[0].setDeviceProfile(profile)); | 72 | deviceProfileOpt.ifPresent(profile -> resultSecurityStore[0].setDeviceProfile(profile)); |
74 | latch.countDown(); | 73 | latch.countDown(); |
75 | } | 74 | } |
@@ -96,9 +95,9 @@ public class LwM2mCredentialsSecurityInfoValidator { | @@ -96,9 +95,9 @@ public class LwM2mCredentialsSecurityInfoValidator { | ||
96 | * @param keyValue - | 95 | * @param keyValue - |
97 | * @return SecurityInfo | 96 | * @return SecurityInfo |
98 | */ | 97 | */ |
99 | - private ReadResultSecurityStore createSecurityInfo(String endPoint, String jsonStr, LwM2mTransportHandlerUtil.LwM2mTypeServer keyValue) { | 98 | + private ReadResultSecurityStore createSecurityInfo(String endPoint, String jsonStr, LwM2mTransportUtil.LwM2mTypeServer keyValue) { |
100 | ReadResultSecurityStore result = new ReadResultSecurityStore(); | 99 | ReadResultSecurityStore result = new ReadResultSecurityStore(); |
101 | - JsonObject objectMsg = LwM2mTransportHandlerUtil.validateJson(jsonStr); | 100 | + JsonObject objectMsg = LwM2mTransportUtil.validateJson(jsonStr); |
102 | if (objectMsg != null && !objectMsg.isJsonNull()) { | 101 | if (objectMsg != null && !objectMsg.isJsonNull()) { |
103 | JsonObject object = (objectMsg.has(keyValue.type) && !objectMsg.get(keyValue.type).isJsonNull()) ? objectMsg.get(keyValue.type).getAsJsonObject() : null; | 102 | JsonObject object = (objectMsg.has(keyValue.type) && !objectMsg.get(keyValue.type).isJsonNull()) ? objectMsg.get(keyValue.type).getAsJsonObject() : null; |
104 | /** | 103 | /** |
@@ -109,7 +108,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | @@ -109,7 +108,7 @@ public class LwM2mCredentialsSecurityInfoValidator { | ||
109 | && objectMsg.get("client").getAsJsonObject().get("endpoint").isJsonPrimitive()) ? objectMsg.get("client").getAsJsonObject().get("endpoint").getAsString() : null; | 108 | && objectMsg.get("client").getAsJsonObject().get("endpoint").isJsonPrimitive()) ? objectMsg.get("client").getAsJsonObject().get("endpoint").getAsString() : null; |
110 | endPoint = (endPointPsk == null || endPointPsk.isEmpty()) ? endPoint : endPointPsk; | 109 | endPoint = (endPointPsk == null || endPointPsk.isEmpty()) ? endPoint : endPointPsk; |
111 | if (object != null && !object.isJsonNull()) { | 110 | if (object != null && !object.isJsonNull()) { |
112 | - if (keyValue.equals(LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP)) { | 111 | + if (keyValue.equals(LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP)) { |
113 | result.setBootstrapJsonCredential(object); | 112 | result.setBootstrapJsonCredential(object); |
114 | result.setEndPoint(endPoint); | 113 | result.setEndPoint(endPoint); |
115 | result.setSecurityMode(LwM2MSecurityMode.fromSecurityMode(object.get("bootstrapServer").getAsJsonObject().get("securityMode").getAsString().toLowerCase()).code); | 114 | result.setSecurityMode(LwM2MSecurityMode.fromSecurityMode(object.get("bootstrapServer").getAsJsonObject().get("securityMode").getAsString().toLowerCase()).code); |
@@ -18,20 +18,21 @@ package org.thingsboard.server.transport.lwm2m.secure; | @@ -18,20 +18,21 @@ package org.thingsboard.server.transport.lwm2m.secure; | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.eclipse.leshan.core.util.Hex; | 20 | import org.eclipse.leshan.core.util.Hex; |
21 | + | ||
21 | import java.math.BigInteger; | 22 | import java.math.BigInteger; |
22 | -import java.security.PrivateKey; | ||
23 | -import java.security.PublicKey; | ||
24 | import java.security.AlgorithmParameters; | 23 | import java.security.AlgorithmParameters; |
25 | -import java.security.KeyFactory; | ||
26 | import java.security.GeneralSecurityException; | 24 | import java.security.GeneralSecurityException; |
25 | +import java.security.KeyFactory; | ||
26 | +import java.security.PrivateKey; | ||
27 | +import java.security.PublicKey; | ||
27 | import java.security.cert.Certificate; | 28 | import java.security.cert.Certificate; |
28 | import java.security.cert.X509Certificate; | 29 | import java.security.cert.X509Certificate; |
29 | import java.security.spec.ECGenParameterSpec; | 30 | import java.security.spec.ECGenParameterSpec; |
30 | import java.security.spec.ECParameterSpec; | 31 | import java.security.spec.ECParameterSpec; |
32 | +import java.security.spec.ECPoint; | ||
33 | +import java.security.spec.ECPrivateKeySpec; | ||
31 | import java.security.spec.ECPublicKeySpec; | 34 | import java.security.spec.ECPublicKeySpec; |
32 | import java.security.spec.KeySpec; | 35 | import java.security.spec.KeySpec; |
33 | -import java.security.spec.ECPrivateKeySpec; | ||
34 | -import java.security.spec.ECPoint; | ||
35 | import java.util.List; | 36 | import java.util.List; |
36 | 37 | ||
37 | @Slf4j | 38 | @Slf4j |
@@ -54,7 +55,7 @@ public class LwM2mRPkCredentials { | @@ -54,7 +55,7 @@ public class LwM2mRPkCredentials { | ||
54 | 55 | ||
55 | private void generatePublicKeyRPK(String publX, String publY, String privS) { | 56 | private void generatePublicKeyRPK(String publX, String publY, String privS) { |
56 | try { | 57 | try { |
57 | - /**Get Elliptic Curve Parameter spec for secp256r1 */ | 58 | + /*Get Elliptic Curve Parameter spec for secp256r1 */ |
58 | AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); | 59 | AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); |
59 | algoParameters.init(new ECGenParameterSpec("secp256r1")); | 60 | algoParameters.init(new ECGenParameterSpec("secp256r1")); |
60 | ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); | 61 | ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); |
@@ -62,18 +63,18 @@ public class LwM2mRPkCredentials { | @@ -62,18 +63,18 @@ public class LwM2mRPkCredentials { | ||
62 | // Get point values | 63 | // Get point values |
63 | byte[] publicX = Hex.decodeHex(publX.toCharArray()); | 64 | byte[] publicX = Hex.decodeHex(publX.toCharArray()); |
64 | byte[] publicY = Hex.decodeHex(publY.toCharArray()); | 65 | byte[] publicY = Hex.decodeHex(publY.toCharArray()); |
65 | - /** Create key specs */ | 66 | + /* Create key specs */ |
66 | KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)), | 67 | KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)), |
67 | parameterSpec); | 68 | parameterSpec); |
68 | - /** Get keys */ | 69 | + /* Get keys */ |
69 | this.serverPublicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec); | 70 | this.serverPublicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec); |
70 | } | 71 | } |
71 | if (privS != null && !privS.isEmpty()) { | 72 | if (privS != null && !privS.isEmpty()) { |
72 | - /** Get point values */ | 73 | + /* Get point values */ |
73 | byte[] privateS = Hex.decodeHex(privS.toCharArray()); | 74 | byte[] privateS = Hex.decodeHex(privS.toCharArray()); |
74 | - /** Create key specs */ | 75 | + /* Create key specs */ |
75 | KeySpec privateKeySpec = new ECPrivateKeySpec(new BigInteger(privateS), parameterSpec); | 76 | KeySpec privateKeySpec = new ECPrivateKeySpec(new BigInteger(privateS), parameterSpec); |
76 | - /** Get keys */ | 77 | + /* Get keys */ |
77 | this.serverPrivateKey = KeyFactory.getInstance("EC").generatePrivate(privateKeySpec); | 78 | this.serverPrivateKey = KeyFactory.getInstance("EC").generatePrivate(privateKeySpec); |
78 | } | 79 | } |
79 | } catch (GeneralSecurityException | IllegalArgumentException e) { | 80 | } catch (GeneralSecurityException | IllegalArgumentException e) { |
@@ -31,8 +31,8 @@ public class ReadResultSecurityStore { | @@ -31,8 +31,8 @@ public class ReadResultSecurityStore { | ||
31 | private int securityMode = DEFAULT_MODE.code; | 31 | private int securityMode = DEFAULT_MODE.code; |
32 | 32 | ||
33 | /** bootstrap */ | 33 | /** bootstrap */ |
34 | - DeviceProfile deviceProfile; | ||
35 | - JsonObject bootstrapJsonCredential; | ||
36 | - String endPoint; | ||
37 | - BootstrapConfig bootstrapConfig; | 34 | + private DeviceProfile deviceProfile; |
35 | + private JsonObject bootstrapJsonCredential; | ||
36 | + private String endPoint; | ||
37 | + private BootstrapConfig bootstrapConfig; | ||
38 | } | 38 | } |
@@ -33,7 +33,6 @@ import org.eclipse.leshan.core.request.ContentFormat; | @@ -33,7 +33,6 @@ import org.eclipse.leshan.core.request.ContentFormat; | ||
33 | import org.eclipse.leshan.core.request.WriteRequest; | 33 | import org.eclipse.leshan.core.request.WriteRequest; |
34 | import org.eclipse.leshan.core.response.ReadResponse; | 34 | import org.eclipse.leshan.core.response.ReadResponse; |
35 | import org.eclipse.leshan.core.util.NamedThreadFactory; | 35 | import org.eclipse.leshan.core.util.NamedThreadFactory; |
36 | -import org.eclipse.leshan.server.californium.LeshanServer; | ||
37 | import org.eclipse.leshan.server.registration.Registration; | 36 | import org.eclipse.leshan.server.registration.Registration; |
38 | import org.springframework.context.annotation.Lazy; | 37 | import org.springframework.context.annotation.Lazy; |
39 | import org.springframework.stereotype.Service; | 38 | import org.springframework.stereotype.Service; |
@@ -55,6 +54,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; | @@ -55,6 +54,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; | ||
55 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; | 54 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; |
56 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | 55 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
57 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; | 56 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
57 | +import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; | ||
58 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; | 58 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
59 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; | 59 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; |
60 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile; | 60 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile; |
@@ -85,30 +85,30 @@ import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; | @@ -85,30 +85,30 @@ import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; | ||
85 | import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; | 85 | import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; |
86 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; | 86 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; |
87 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; | 87 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
88 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.CLIENT_NOT_AUTHORIZED; | ||
89 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.DEVICE_ATTRIBUTES_REQUEST; | ||
90 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.FR_OBJECT_ID; | ||
91 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.FR_PATH_RESOURCE_VER_ID; | ||
92 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR; | ||
93 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO; | ||
94 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE; | ||
95 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_STRATEGY_2; | ||
96 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper; | ||
97 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.DISCOVER; | ||
98 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.EXECUTE; | ||
99 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE; | ||
100 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_CANCEL; | ||
101 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_READ_ALL; | ||
102 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.READ; | ||
103 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_ATTRIBUTES; | ||
104 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_REPLACE; | ||
105 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_UPDATE; | ||
106 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.SERVICE_CHANNEL; | ||
107 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertJsonArrayToSet; | ||
108 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId; | ||
109 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer; | ||
110 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getAckCallback; | ||
111 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.validateObjectVerFromKey; | 88 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.CLIENT_NOT_AUTHORIZED; |
89 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST; | ||
90 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FR_OBJECT_ID; | ||
91 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FR_PATH_RESOURCE_VER_ID; | ||
92 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_ERROR; | ||
93 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; | ||
94 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; | ||
95 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2; | ||
96 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; | ||
97 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER; | ||
98 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; | ||
99 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE; | ||
100 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL; | ||
101 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL; | ||
102 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.READ; | ||
103 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_ATTRIBUTES; | ||
104 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_REPLACE; | ||
105 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_UPDATE; | ||
106 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SERVICE_CHANNEL; | ||
107 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertJsonArrayToSet; | ||
108 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromIdVerToObjectId; | ||
109 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; | ||
110 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getAckCallback; | ||
111 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.validateObjectVerFromKey; | ||
112 | 112 | ||
113 | @Slf4j | 113 | @Slf4j |
114 | @Service | 114 | @Service |
@@ -125,6 +125,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -125,6 +125,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
125 | private final LwM2MTransportServerConfig config; | 125 | private final LwM2MTransportServerConfig config; |
126 | private final FirmwareDataCache firmwareDataCache; | 126 | private final FirmwareDataCache firmwareDataCache; |
127 | private final LwM2mTransportServerHelper helper; | 127 | private final LwM2mTransportServerHelper helper; |
128 | + private final LwM2MJsonAdaptor adaptor; | ||
128 | private final LwM2mClientContext lwM2mClientContext; | 129 | private final LwM2mClientContext lwM2mClientContext; |
129 | private final LwM2mTransportRequest lwM2mTransportRequest; | 130 | private final LwM2mTransportRequest lwM2mTransportRequest; |
130 | 131 | ||
@@ -132,7 +133,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -132,7 +133,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
132 | LwM2mClientContext lwM2mClientContext, | 133 | LwM2mClientContext lwM2mClientContext, |
133 | @Lazy LwM2mTransportRequest lwM2mTransportRequest, | 134 | @Lazy LwM2mTransportRequest lwM2mTransportRequest, |
134 | FirmwareDataCache firmwareDataCache, | 135 | FirmwareDataCache firmwareDataCache, |
135 | - LwM2mTransportContext context) { | 136 | + LwM2mTransportContext context, LwM2MJsonAdaptor adaptor) { |
136 | this.transportService = transportService; | 137 | this.transportService = transportService; |
137 | this.config = config; | 138 | this.config = config; |
138 | this.helper = helper; | 139 | this.helper = helper; |
@@ -140,6 +141,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -140,6 +141,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
140 | this.lwM2mTransportRequest = lwM2mTransportRequest; | 141 | this.lwM2mTransportRequest = lwM2mTransportRequest; |
141 | this.firmwareDataCache = firmwareDataCache; | 142 | this.firmwareDataCache = firmwareDataCache; |
142 | this.context = context; | 143 | this.context = context; |
144 | + this.adaptor = adaptor; | ||
143 | } | 145 | } |
144 | 146 | ||
145 | @PostConstruct | 147 | @PostConstruct |
@@ -334,7 +336,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -334,7 +336,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
334 | msg.getSharedUpdatedList().forEach(tsKvProto -> { | 336 | msg.getSharedUpdatedList().forEach(tsKvProto -> { |
335 | String pathName = tsKvProto.getKv().getKey(); | 337 | String pathName = tsKvProto.getKv().getKey(); |
336 | String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); | 338 | String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); |
337 | - Object valueNew = this.helper.getValueFromKvProto(tsKvProto.getKv()); | 339 | + Object valueNew = LwM2mTransportServerHelper.getValueFromKvProto(tsKvProto.getKv()); |
338 | //TODO: react on change of the firmware name. | 340 | //TODO: react on change of the firmware name. |
339 | if (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFrUpdate().getCurrentFwVersion())) { | 341 | if (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFrUpdate().getCurrentFwVersion())) { |
340 | this.getInfoFirmwareUpdate(lwM2MClient); | 342 | this.getInfoFirmwareUpdate(lwM2MClient); |
@@ -361,7 +363,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -361,7 +363,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
361 | } else if (msg.getSharedDeletedCount() > 0) { | 363 | } else if (msg.getSharedDeletedCount() > 0) { |
362 | msg.getSharedUpdatedList().forEach(tsKvProto -> { | 364 | msg.getSharedUpdatedList().forEach(tsKvProto -> { |
363 | String pathName = tsKvProto.getKv().getKey(); | 365 | String pathName = tsKvProto.getKv().getKey(); |
364 | - Object valueNew = this.helper.getValueFromKvProto(tsKvProto.getKv()); | 366 | + Object valueNew = LwM2mTransportServerHelper.getValueFromKvProto(tsKvProto.getKv()); |
365 | if (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFrUpdate().getCurrentFwVersion())) { | 367 | if (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFrUpdate().getCurrentFwVersion())) { |
366 | lwM2MClient.getFrUpdate().setCurrentFwVersion((String) valueNew); | 368 | lwM2MClient.getFrUpdate().setCurrentFwVersion((String) valueNew); |
367 | } | 369 | } |
@@ -458,7 +460,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -458,7 +460,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
458 | lwm2mClientRpcRequest.setRequestId(toDeviceRequest.getRequestId()); | 460 | lwm2mClientRpcRequest.setRequestId(toDeviceRequest.getRequestId()); |
459 | lwm2mClientRpcRequest.setSessionInfo(sessionInfo); | 461 | lwm2mClientRpcRequest.setSessionInfo(sessionInfo); |
460 | lwm2mClientRpcRequest.setValidTypeOper(toDeviceRequest.getMethodName()); | 462 | lwm2mClientRpcRequest.setValidTypeOper(toDeviceRequest.getMethodName()); |
461 | - JsonObject rpcRequest = LwM2mTransportHandlerUtil.validateJson(toDeviceRequest.getParams()); | 463 | + JsonObject rpcRequest = LwM2mTransportUtil.validateJson(toDeviceRequest.getParams()); |
462 | if (rpcRequest != null) { | 464 | if (rpcRequest != null) { |
463 | if (rpcRequest.has(lwm2mClientRpcRequest.keyNameKey)) { | 465 | if (rpcRequest.has(lwm2mClientRpcRequest.keyNameKey)) { |
464 | String targetIdVer = this.getPresentPathIntoProfile(sessionInfo, | 466 | String targetIdVer = this.getPresentPathIntoProfile(sessionInfo, |
@@ -639,7 +641,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -639,7 +641,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
639 | LwM2mClientProfile lwM2MClientProfile = lwM2mClientContext.getProfile(registration); | 641 | LwM2mClientProfile lwM2MClientProfile = lwM2mClientContext.getProfile(registration); |
640 | Set<String> clientObjects = lwM2mClientContext.getSupportedIdVerInClient(registration); | 642 | Set<String> clientObjects = lwM2mClientContext.getSupportedIdVerInClient(registration); |
641 | if (clientObjects != null && clientObjects.size() > 0) { | 643 | if (clientObjects != null && clientObjects.size() > 0) { |
642 | - if (LWM2M_STRATEGY_2 == LwM2mTransportHandlerUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { | 644 | + if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { |
643 | // #2 | 645 | // #2 |
644 | lwM2MClient.getPendingReadRequests().addAll(clientObjects); | 646 | lwM2MClient.getPendingReadRequests().addAll(clientObjects); |
645 | clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(), | 647 | clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(), |
@@ -1361,7 +1363,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -1361,7 +1363,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
1361 | if (keyNamesMap.values().size() > 0) { | 1363 | if (keyNamesMap.values().size() > 0) { |
1362 | try { | 1364 | try { |
1363 | //#1.2 | 1365 | //#1.2 |
1364 | - TransportProtos.GetAttributeRequestMsg getAttributeMsg = helper.getAdaptor().convertToGetAttributes(null, keyNamesMap.values()); | 1366 | + TransportProtos.GetAttributeRequestMsg getAttributeMsg = adaptor.convertToGetAttributes(null, keyNamesMap.values()); |
1365 | transportService.process(sessionInfo, getAttributeMsg, getAckCallback(lwM2MClient, getAttributeMsg.getRequestId(), DEVICE_ATTRIBUTES_REQUEST)); | 1367 | transportService.process(sessionInfo, getAttributeMsg, getAckCallback(lwM2MClient, getAttributeMsg.getRequestId(), DEVICE_ATTRIBUTES_REQUEST)); |
1366 | } catch (AdaptorException e) { | 1368 | } catch (AdaptorException e) { |
1367 | log.warn("Failed to decode get attributes request", e); | 1369 | log.warn("Failed to decode get attributes request", e); |
@@ -17,8 +17,6 @@ package org.thingsboard.server.transport.lwm2m.server; | @@ -17,8 +17,6 @@ package org.thingsboard.server.transport.lwm2m.server; | ||
17 | 17 | ||
18 | import lombok.RequiredArgsConstructor; | 18 | import lombok.RequiredArgsConstructor; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | -import org.eclipse.californium.core.network.config.NetworkConfig; | ||
21 | -import org.eclipse.californium.core.network.stack.BlockwiseLayer; | ||
22 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; | 20 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; |
23 | import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder; | 21 | import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder; |
24 | import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeEncoder; | 22 | import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeEncoder; |
@@ -91,40 +89,39 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService { | @@ -91,40 +89,39 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService { | ||
91 | if (config.getEnableGenNewKeyPskRpk()) { | 89 | if (config.getEnableGenNewKeyPskRpk()) { |
92 | new LWM2MGenerationPSkRPkECC(); | 90 | new LWM2MGenerationPSkRPkECC(); |
93 | } | 91 | } |
94 | - this.server = getLhServer(config.getPort(), config.getSecurePort()); | 92 | + this.server = getLhServer(); |
95 | this.startLhServer(); | 93 | this.startLhServer(); |
96 | this.context.setServer(server); | 94 | this.context.setServer(server); |
97 | } | 95 | } |
98 | 96 | ||
99 | private void startLhServer() { | 97 | private void startLhServer() { |
100 | - log.info("Starting LwM2M transport Server..."); | 98 | + log.info("Starting LwM2M transport server..."); |
101 | this.server.start(); | 99 | this.server.start(); |
102 | LwM2mServerListener lhServerCertListener = new LwM2mServerListener(handler); | 100 | LwM2mServerListener lhServerCertListener = new LwM2mServerListener(handler); |
103 | this.server.getRegistrationService().addListener(lhServerCertListener.registrationListener); | 101 | this.server.getRegistrationService().addListener(lhServerCertListener.registrationListener); |
104 | this.server.getPresenceService().addListener(lhServerCertListener.presenceListener); | 102 | this.server.getPresenceService().addListener(lhServerCertListener.presenceListener); |
105 | this.server.getObservationService().addListener(lhServerCertListener.observationListener); | 103 | this.server.getObservationService().addListener(lhServerCertListener.observationListener); |
104 | + log.info("Started LwM2M transport server."); | ||
106 | } | 105 | } |
107 | 106 | ||
108 | @PreDestroy | 107 | @PreDestroy |
109 | public void shutdown() { | 108 | public void shutdown() { |
110 | - log.info("Stopping LwM2M transport Server!"); | 109 | + log.info("Stopping LwM2M transport server!"); |
111 | server.destroy(); | 110 | server.destroy(); |
112 | - log.info("LwM2M transport Server stopped!"); | 111 | + log.info("LwM2M transport server stopped!"); |
113 | } | 112 | } |
114 | 113 | ||
115 | - private LeshanServer getLhServer(Integer serverPortNoSec, Integer serverSecurePort) { | 114 | + private LeshanServer getLhServer() { |
116 | LeshanServerBuilder builder = new LeshanServerBuilder(); | 115 | LeshanServerBuilder builder = new LeshanServerBuilder(); |
117 | - builder.setLocalAddress(config.getHost(), serverPortNoSec); | ||
118 | - builder.setLocalSecureAddress(config.getSecureHost(), serverSecurePort); | 116 | + builder.setLocalAddress(config.getHost(), config.getPort()); |
117 | + builder.setLocalSecureAddress(config.getSecureHost(), config.getSecurePort()); | ||
119 | builder.setDecoder(new DefaultLwM2mNodeDecoder()); | 118 | builder.setDecoder(new DefaultLwM2mNodeDecoder()); |
120 | /* Use a magic converter to support bad type send by the UI. */ | 119 | /* Use a magic converter to support bad type send by the UI. */ |
121 | builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance())); | 120 | builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance())); |
122 | 121 | ||
123 | 122 | ||
124 | /* Create CoAP Config */ | 123 | /* Create CoAP Config */ |
125 | - NetworkConfig networkConfig = getCoapConfig(serverPortNoSec, serverSecurePort); | ||
126 | - BlockwiseLayer blockwiseLayer = new BlockwiseLayer(networkConfig); | ||
127 | - builder.setCoapConfig(getCoapConfig(serverPortNoSec, serverSecurePort)); | 124 | + builder.setCoapConfig(getCoapConfig(config.getPort(), config.getSecurePort())); |
128 | 125 | ||
129 | /* Define model provider (Create Models )*/ | 126 | /* Define model provider (Create Models )*/ |
130 | LwM2mModelProvider modelProvider = new LwM2mVersionedModelProvider(this.lwM2mClientContext, this.helper, this.context); | 127 | LwM2mModelProvider modelProvider = new LwM2mVersionedModelProvider(this.lwM2mClientContext, this.helper, this.context); |
@@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.RegistrationUpdate; | @@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.RegistrationUpdate; | ||
26 | 26 | ||
27 | import java.util.Collection; | 27 | import java.util.Collection; |
28 | 28 | ||
29 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO; | ||
30 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer; | 29 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; |
30 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; | ||
31 | 31 | ||
32 | @Slf4j | 32 | @Slf4j |
33 | public class LwM2mServerListener { | 33 | public class LwM2mServerListener { |
@@ -35,22 +35,22 @@ import java.util.Optional; | @@ -35,22 +35,22 @@ import java.util.Optional; | ||
35 | 35 | ||
36 | @Slf4j | 36 | @Slf4j |
37 | public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? super Void>>, SessionMsgListener { | 37 | public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? super Void>>, SessionMsgListener { |
38 | - private DefaultLwM2MTransportMsgHandler service; | 38 | + private DefaultLwM2MTransportMsgHandler handler; |
39 | private TransportProtos.SessionInfoProto sessionInfo; | 39 | private TransportProtos.SessionInfoProto sessionInfo; |
40 | 40 | ||
41 | - public LwM2mSessionMsgListener(DefaultLwM2MTransportMsgHandler service, TransportProtos.SessionInfoProto sessionInfo) { | ||
42 | - this.service = service; | 41 | + public LwM2mSessionMsgListener(DefaultLwM2MTransportMsgHandler handler, TransportProtos.SessionInfoProto sessionInfo) { |
42 | + this.handler = handler; | ||
43 | this.sessionInfo = sessionInfo; | 43 | this.sessionInfo = sessionInfo; |
44 | } | 44 | } |
45 | 45 | ||
46 | @Override | 46 | @Override |
47 | public void onGetAttributesResponse(GetAttributeResponseMsg getAttributesResponse) { | 47 | public void onGetAttributesResponse(GetAttributeResponseMsg getAttributesResponse) { |
48 | - this.service.onGetAttributesResponse(getAttributesResponse, this.sessionInfo); | 48 | + this.handler.onGetAttributesResponse(getAttributesResponse, this.sessionInfo); |
49 | } | 49 | } |
50 | 50 | ||
51 | @Override | 51 | @Override |
52 | public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) { | 52 | public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) { |
53 | - this.service.onAttributeUpdate(attributeUpdateNotification, this.sessionInfo); | 53 | + this.handler.onAttributeUpdate(attributeUpdateNotification, this.sessionInfo); |
54 | } | 54 | } |
55 | 55 | ||
56 | @Override | 56 | @Override |
@@ -60,27 +60,27 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s | @@ -60,27 +60,27 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s | ||
60 | 60 | ||
61 | @Override | 61 | @Override |
62 | public void onToTransportUpdateCredentials(ToTransportUpdateCredentialsProto updateCredentials) { | 62 | public void onToTransportUpdateCredentials(ToTransportUpdateCredentialsProto updateCredentials) { |
63 | - this.service.onToTransportUpdateCredentials(updateCredentials); | 63 | + this.handler.onToTransportUpdateCredentials(updateCredentials); |
64 | } | 64 | } |
65 | 65 | ||
66 | @Override | 66 | @Override |
67 | public void onDeviceProfileUpdate(TransportProtos.SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { | 67 | public void onDeviceProfileUpdate(TransportProtos.SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { |
68 | - this.service.onDeviceProfileUpdate(sessionInfo, deviceProfile); | 68 | + this.handler.onDeviceProfileUpdate(sessionInfo, deviceProfile); |
69 | } | 69 | } |
70 | 70 | ||
71 | @Override | 71 | @Override |
72 | public void onDeviceUpdate(TransportProtos.SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) { | 72 | public void onDeviceUpdate(TransportProtos.SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) { |
73 | - this.service.onDeviceUpdate(sessionInfo, device, deviceProfileOpt); | 73 | + this.handler.onDeviceUpdate(sessionInfo, device, deviceProfileOpt); |
74 | } | 74 | } |
75 | 75 | ||
76 | @Override | 76 | @Override |
77 | public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) { | 77 | public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) { |
78 | - this.service.onToDeviceRpcRequest(toDeviceRequest,this.sessionInfo); | 78 | + this.handler.onToDeviceRpcRequest(toDeviceRequest,this.sessionInfo); |
79 | } | 79 | } |
80 | 80 | ||
81 | @Override | 81 | @Override |
82 | public void onToServerRpcResponse(ToServerRpcResponseMsg toServerResponse) { | 82 | public void onToServerRpcResponse(ToServerRpcResponseMsg toServerResponse) { |
83 | - this.service.onToServerRpcResponse(toServerResponse); | 83 | + this.handler.onToServerRpcResponse(toServerResponse); |
84 | } | 84 | } |
85 | 85 | ||
86 | @Override | 86 | @Override |
@@ -91,14 +91,14 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s | @@ -91,14 +91,14 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s | ||
91 | @Override | 91 | @Override |
92 | public void onResourceUpdate(@NotNull Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) { | 92 | public void onResourceUpdate(@NotNull Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) { |
93 | if (ResourceType.LWM2M_MODEL.name().equals(resourceUpdateMsgOpt.get().getResourceType())) { | 93 | if (ResourceType.LWM2M_MODEL.name().equals(resourceUpdateMsgOpt.get().getResourceType())) { |
94 | - this.service.onResourceUpdate(resourceUpdateMsgOpt); | 94 | + this.handler.onResourceUpdate(resourceUpdateMsgOpt); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | @Override | 98 | @Override |
99 | public void onResourceDelete(@NotNull Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) { | 99 | public void onResourceDelete(@NotNull Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) { |
100 | if (ResourceType.LWM2M_MODEL.name().equals(resourceDeleteMsgOpt.get().getResourceType())) { | 100 | if (ResourceType.LWM2M_MODEL.name().equals(resourceDeleteMsgOpt.get().getResourceType())) { |
101 | - this.service.onResourceDelete(resourceDeleteMsgOpt); | 101 | + this.handler.onResourceDelete(resourceDeleteMsgOpt); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | } | 104 | } |
@@ -20,7 +20,6 @@ import org.eclipse.leshan.core.response.ReadResponse; | @@ -20,7 +20,6 @@ import org.eclipse.leshan.core.response.ReadResponse; | ||
20 | import org.eclipse.leshan.server.registration.Registration; | 20 | import org.eclipse.leshan.server.registration.Registration; |
21 | import org.thingsboard.server.common.data.Device; | 21 | import org.thingsboard.server.common.data.Device; |
22 | import org.thingsboard.server.common.data.DeviceProfile; | 22 | import org.thingsboard.server.common.data.DeviceProfile; |
23 | -import org.thingsboard.server.common.data.TbTransportService; | ||
24 | import org.thingsboard.server.gen.transport.TransportProtos; | 23 | import org.thingsboard.server.gen.transport.TransportProtos; |
25 | import org.thingsboard.server.transport.lwm2m.server.client.Lwm2mClientRpcRequest; | 24 | import org.thingsboard.server.transport.lwm2m.server.client.Lwm2mClientRpcRequest; |
26 | 25 |
@@ -46,10 +46,8 @@ import org.eclipse.leshan.core.response.WriteAttributesResponse; | @@ -46,10 +46,8 @@ import org.eclipse.leshan.core.response.WriteAttributesResponse; | ||
46 | import org.eclipse.leshan.core.response.WriteResponse; | 46 | import org.eclipse.leshan.core.response.WriteResponse; |
47 | import org.eclipse.leshan.core.util.Hex; | 47 | import org.eclipse.leshan.core.util.Hex; |
48 | import org.eclipse.leshan.core.util.NamedThreadFactory; | 48 | import org.eclipse.leshan.core.util.NamedThreadFactory; |
49 | -import org.eclipse.leshan.server.californium.LeshanServer; | ||
50 | import org.eclipse.leshan.server.registration.Registration; | 49 | import org.eclipse.leshan.server.registration.Registration; |
51 | import org.springframework.stereotype.Service; | 50 | import org.springframework.stereotype.Service; |
52 | -import org.thingsboard.server.common.transport.TransportService; | ||
53 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | 51 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
54 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; | 52 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
55 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; | 53 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
@@ -68,18 +66,18 @@ import java.util.stream.Collectors; | @@ -68,18 +66,18 @@ import java.util.stream.Collectors; | ||
68 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; | 66 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; |
69 | import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; | 67 | import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; |
70 | import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND; | 68 | import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND; |
71 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.DEFAULT_TIMEOUT; | ||
72 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.FR_PATH_RESOURCE_VER_ID; | ||
73 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR; | ||
74 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO; | ||
75 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE; | ||
76 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper; | ||
77 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_CANCEL; | ||
78 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_READ_ALL; | ||
79 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.RESPONSE_CHANNEL; | ||
80 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId; | ||
81 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer; | ||
82 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.createWriteAttributeRequest; | 69 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEFAULT_TIMEOUT; |
70 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FR_PATH_RESOURCE_VER_ID; | ||
71 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_ERROR; | ||
72 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; | ||
73 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; | ||
74 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; | ||
75 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL; | ||
76 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL; | ||
77 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.RESPONSE_CHANNEL; | ||
78 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromIdVerToObjectId; | ||
79 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; | ||
80 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.createWriteAttributeRequest; | ||
83 | 81 | ||
84 | @Slf4j | 82 | @Slf4j |
85 | @Service | 83 | @Service |
@@ -92,7 +90,6 @@ public class LwM2mTransportRequest { | @@ -92,7 +90,6 @@ public class LwM2mTransportRequest { | ||
92 | 90 | ||
93 | private final LwM2mTransportContext context; | 91 | private final LwM2mTransportContext context; |
94 | private final LwM2MTransportServerConfig config; | 92 | private final LwM2MTransportServerConfig config; |
95 | - private final LwM2mTransportServerHelper lwM2MTransportServerHelper; | ||
96 | private final LwM2mClientContext lwM2mClientContext; | 93 | private final LwM2mClientContext lwM2mClientContext; |
97 | private final DefaultLwM2MTransportMsgHandler serviceImpl; | 94 | private final DefaultLwM2MTransportMsgHandler serviceImpl; |
98 | 95 | ||
@@ -120,8 +117,7 @@ public class LwM2mTransportRequest { | @@ -120,8 +117,7 @@ public class LwM2mTransportRequest { | ||
120 | ContentFormat contentFormat = contentFormatName != null ? ContentFormat.fromName(contentFormatName.toUpperCase()) : ContentFormat.DEFAULT; | 117 | ContentFormat contentFormat = contentFormatName != null ? ContentFormat.fromName(contentFormatName.toUpperCase()) : ContentFormat.DEFAULT; |
121 | LwM2mClient lwM2MClient = this.lwM2mClientContext.getLwM2mClientWithReg(registration, null); | 118 | LwM2mClient lwM2MClient = this.lwM2mClientContext.getLwM2mClientWithReg(registration, null); |
122 | LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null; | 119 | LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null; |
123 | - if (!OBSERVE_READ_ALL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && | ||
124 | - lwM2MClient != null) { | 120 | + if (!OBSERVE_READ_ALL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) { |
125 | if (lwM2MClient.isValidObjectVersion(targetIdVer)) { | 121 | if (lwM2MClient.isValidObjectVersion(targetIdVer)) { |
126 | timeoutInMs = timeoutInMs > 0 ? timeoutInMs : DEFAULT_TIMEOUT; | 122 | timeoutInMs = timeoutInMs > 0 ? timeoutInMs : DEFAULT_TIMEOUT; |
127 | ResourceModel resourceModel = null; | 123 | ResourceModel resourceModel = null; |
@@ -142,10 +138,10 @@ public class LwM2mTransportRequest { | @@ -142,10 +138,10 @@ public class LwM2mTransportRequest { | ||
142 | } | 138 | } |
143 | break; | 139 | break; |
144 | case OBSERVE_CANCEL: | 140 | case OBSERVE_CANCEL: |
145 | - /** | ||
146 | - * lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, POST_TYPE_OPER_OBSERVE_CANCEL, null, null, null, null, context.getTimeout()); | ||
147 | - * At server side this will not remove the observation from the observation store, to do it you need to use | ||
148 | - * {@code ObservationService#cancelObservation()} | 141 | + /* |
142 | + lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, POST_TYPE_OPER_OBSERVE_CANCEL, null, null, null, null, context.getTimeout()); | ||
143 | + At server side this will not remove the observation from the observation store, to do it you need to use | ||
144 | + {@code ObservationService#cancelObservation()} | ||
149 | */ | 145 | */ |
150 | context.getServer().getObservationService().cancelObservations(registration, target); | 146 | context.getServer().getObservationService().cancelObservations(registration, target); |
151 | break; | 147 | break; |
@@ -266,9 +262,9 @@ public class LwM2mTransportRequest { | @@ -266,9 +262,9 @@ public class LwM2mTransportRequest { | ||
266 | if (rpcRequest != null) { | 262 | if (rpcRequest != null) { |
267 | serviceImpl.sentRpcRequest(rpcRequest, response.getCode().getName(), response.getErrorMessage(), LOG_LW2M_ERROR); | 263 | serviceImpl.sentRpcRequest(rpcRequest, response.getCode().getName(), response.getErrorMessage(), LOG_LW2M_ERROR); |
268 | } | 264 | } |
269 | - /** Not Found | ||
270 | - * set setClient_fw_version = empty | ||
271 | - **/ | 265 | + /* Not Found |
266 | + set setClient_fw_version = empty | ||
267 | + */ | ||
272 | if (FR_PATH_RESOURCE_VER_ID.equals(request.getPath().toString()) && lwM2MClient.isUpdateFw()) { | 268 | if (FR_PATH_RESOURCE_VER_ID.equals(request.getPath().toString()) && lwM2MClient.isUpdateFw()) { |
273 | lwM2MClient.setUpdateFw(false); | 269 | lwM2MClient.setUpdateFw(false); |
274 | lwM2MClient.getFrUpdate().setClientFwVersion(""); | 270 | lwM2MClient.getFrUpdate().setClientFwVersion(""); |
@@ -277,9 +273,9 @@ public class LwM2mTransportRequest { | @@ -277,9 +273,9 @@ public class LwM2mTransportRequest { | ||
277 | } | 273 | } |
278 | } | 274 | } |
279 | }, e -> { | 275 | }, e -> { |
280 | - /** version == null | ||
281 | - * set setClient_fw_version = empty | ||
282 | - **/ | 276 | + /* version == null |
277 | + set setClient_fw_version = empty | ||
278 | + */ | ||
283 | if (FR_PATH_RESOURCE_VER_ID.equals(request.getPath().toString()) && lwM2MClient.isUpdateFw()) { | 279 | if (FR_PATH_RESOURCE_VER_ID.equals(request.getPath().toString()) && lwM2MClient.isUpdateFw()) { |
284 | lwM2MClient.setUpdateFw(false); | 280 | lwM2MClient.setUpdateFw(false); |
285 | lwM2MClient.getFrUpdate().setClientFwVersion(""); | 281 | lwM2MClient.getFrUpdate().setClientFwVersion(""); |
@@ -30,7 +30,6 @@ package org.thingsboard.server.transport.lwm2m.server; | @@ -30,7 +30,6 @@ package org.thingsboard.server.transport.lwm2m.server; | ||
30 | * limitations under the License. | 30 | * limitations under the License. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | -import lombok.Getter; | ||
34 | import lombok.RequiredArgsConstructor; | 33 | import lombok.RequiredArgsConstructor; |
35 | import lombok.extern.slf4j.Slf4j; | 34 | import lombok.extern.slf4j.Slf4j; |
36 | import org.eclipse.leshan.core.model.DDFFileParser; | 35 | import org.eclipse.leshan.core.model.DDFFileParser; |
@@ -40,7 +39,6 @@ import org.eclipse.leshan.core.model.ObjectModel; | @@ -40,7 +39,6 @@ import org.eclipse.leshan.core.model.ObjectModel; | ||
40 | import org.eclipse.leshan.core.model.ResourceModel; | 39 | import org.eclipse.leshan.core.model.ResourceModel; |
41 | import org.eclipse.leshan.core.node.codec.CodecException; | 40 | import org.eclipse.leshan.core.node.codec.CodecException; |
42 | import org.springframework.stereotype.Component; | 41 | import org.springframework.stereotype.Component; |
43 | -import org.thingsboard.server.common.transport.TransportService; | ||
44 | import org.thingsboard.server.common.transport.TransportServiceCallback; | 42 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
45 | import org.thingsboard.server.gen.transport.TransportProtos; | 43 | import org.thingsboard.server.gen.transport.TransportProtos; |
46 | import org.thingsboard.server.gen.transport.TransportProtos.PostAttributeMsg; | 44 | import org.thingsboard.server.gen.transport.TransportProtos.PostAttributeMsg; |
@@ -55,7 +53,7 @@ import java.util.ArrayList; | @@ -55,7 +53,7 @@ import java.util.ArrayList; | ||
55 | import java.util.List; | 53 | import java.util.List; |
56 | 54 | ||
57 | import static org.thingsboard.server.gen.transport.TransportProtos.KeyValueType.BOOLEAN_V; | 55 | import static org.thingsboard.server.gen.transport.TransportProtos.KeyValueType.BOOLEAN_V; |
58 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_TELEMETRY; | 56 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY; |
59 | 57 | ||
60 | @Slf4j | 58 | @Slf4j |
61 | @Component | 59 | @Component |
@@ -64,10 +62,6 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle | @@ -64,10 +62,6 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle | ||
64 | public class LwM2mTransportServerHelper { | 62 | public class LwM2mTransportServerHelper { |
65 | 63 | ||
66 | private final LwM2mTransportContext context; | 64 | private final LwM2mTransportContext context; |
67 | - | ||
68 | - private final TransportService transportService; | ||
69 | - | ||
70 | - @Getter | ||
71 | private final LwM2MJsonAdaptor adaptor; | 65 | private final LwM2MJsonAdaptor adaptor; |
72 | 66 | ||
73 | /** | 67 | /** |
@@ -95,7 +89,7 @@ public class LwM2mTransportServerHelper { | @@ -95,7 +89,7 @@ public class LwM2mTransportServerHelper { | ||
95 | request.addAllKv(result); | 89 | request.addAllKv(result); |
96 | PostAttributeMsg postAttributeMsg = request.build(); | 90 | PostAttributeMsg postAttributeMsg = request.build(); |
97 | TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postAttributeMsg); | 91 | TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postAttributeMsg); |
98 | - transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSendAttrTelemetry(call)); | 92 | + context.getTransportService().process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSendAttrTelemetry(call)); |
99 | } | 93 | } |
100 | 94 | ||
101 | public void sendParametersOnThingsboardTelemetry(List<TransportProtos.KeyValueProto> result, SessionInfoProto sessionInfo) { | 95 | public void sendParametersOnThingsboardTelemetry(List<TransportProtos.KeyValueProto> result, SessionInfoProto sessionInfo) { |
@@ -106,7 +100,7 @@ public class LwM2mTransportServerHelper { | @@ -106,7 +100,7 @@ public class LwM2mTransportServerHelper { | ||
106 | request.addTsKvList(builder.build()); | 100 | request.addTsKvList(builder.build()); |
107 | PostTelemetryMsg postTelemetryMsg = request.build(); | 101 | PostTelemetryMsg postTelemetryMsg = request.build(); |
108 | TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postTelemetryMsg); | 102 | TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postTelemetryMsg); |
109 | - transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSendAttrTelemetry(call)); | 103 | + context.getTransportService().process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSendAttrTelemetry(call)); |
110 | } | 104 | } |
111 | 105 | ||
112 | /** | 106 | /** |
@@ -191,7 +185,7 @@ public class LwM2mTransportServerHelper { | @@ -191,7 +185,7 @@ public class LwM2mTransportServerHelper { | ||
191 | * @param resourcePath - | 185 | * @param resourcePath - |
192 | * @return | 186 | * @return |
193 | */ | 187 | */ |
194 | - public ResourceModel.Type getResourceModelTypeEqualsKvProtoValueType(ResourceModel.Type currentType, String resourcePath) { | 188 | + public static ResourceModel.Type getResourceModelTypeEqualsKvProtoValueType(ResourceModel.Type currentType, String resourcePath) { |
195 | switch (currentType) { | 189 | switch (currentType) { |
196 | case BOOLEAN: | 190 | case BOOLEAN: |
197 | return ResourceModel.Type.BOOLEAN; | 191 | return ResourceModel.Type.BOOLEAN; |
@@ -209,7 +203,7 @@ public class LwM2mTransportServerHelper { | @@ -209,7 +203,7 @@ public class LwM2mTransportServerHelper { | ||
209 | throw new CodecException("Invalid ResourceModel_Type for resource %s, got %s", resourcePath, currentType); | 203 | throw new CodecException("Invalid ResourceModel_Type for resource %s, got %s", resourcePath, currentType); |
210 | } | 204 | } |
211 | 205 | ||
212 | - public Object getValueFromKvProto(TransportProtos.KeyValueProto kv) { | 206 | + public static Object getValueFromKvProto(TransportProtos.KeyValueProto kv) { |
213 | switch (kv.getType()) { | 207 | switch (kv.getType()) { |
214 | case BOOLEAN_V: | 208 | case BOOLEAN_V: |
215 | return kv.getBoolV(); | 209 | return kv.getBoolV(); |
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportServerInitializer.java
deleted
100644 → 0
1 | -/** | ||
2 | - * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.thingsboard.server.transport.lwm2m.server; | ||
17 | - | ||
18 | -import lombok.extern.slf4j.Slf4j; | ||
19 | -import org.eclipse.leshan.server.californium.LeshanServer; | ||
20 | -import org.springframework.beans.factory.annotation.Autowired; | ||
21 | -import org.springframework.stereotype.Component; | ||
22 | -import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | ||
23 | -import org.thingsboard.server.transport.lwm2m.secure.LWM2MGenerationPSkRPkECC; | ||
24 | - | ||
25 | -import javax.annotation.PostConstruct; | ||
26 | -import javax.annotation.PreDestroy; | ||
27 | - | ||
28 | -@Slf4j | ||
29 | -@Component("LwM2MTransportServerInitializer") | ||
30 | -@TbLwM2mTransportComponent | ||
31 | -public class LwM2mTransportServerInitializer { | ||
32 | - | ||
33 | -} |
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportUtil.java
renamed from
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportHandlerUtil.java
@@ -67,7 +67,7 @@ import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPA | @@ -67,7 +67,7 @@ import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPA | ||
67 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; | 67 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
68 | 68 | ||
69 | @Slf4j | 69 | @Slf4j |
70 | -public class LwM2mTransportHandlerUtil { | 70 | +public class LwM2mTransportUtil { |
71 | 71 | ||
72 | public static final String TRANSPORT_DEFAULT_LWM2M_VERSION = "1.0"; | 72 | public static final String TRANSPORT_DEFAULT_LWM2M_VERSION = "1.0"; |
73 | public static final String CLIENT_LWM2M_SETTINGS = "clientLwM2mSettings"; | 73 | public static final String CLIENT_LWM2M_SETTINGS = "clientLwM2mSettings"; |
@@ -150,8 +150,8 @@ public class LwM2mTransportHandlerUtil { | @@ -150,8 +150,8 @@ public class LwM2mTransportHandlerUtil { | ||
150 | * if all resources are to be replaced | 150 | * if all resources are to be replaced |
151 | */ | 151 | */ |
152 | WRITE_REPLACE(6, "WriteReplace"), | 152 | WRITE_REPLACE(6, "WriteReplace"), |
153 | - /** | ||
154 | - * PUT | 153 | + /* |
154 | + PUT | ||
155 | */ | 155 | */ |
156 | /** | 156 | /** |
157 | * Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section | 157 | * Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section |
@@ -178,7 +178,7 @@ public class LwM2mTransportHandlerUtil { | @@ -178,7 +178,7 @@ public class LwM2mTransportHandlerUtil { | ||
178 | return to; | 178 | return to; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | - throw new IllegalArgumentException(String.format("Unsupported typeOper type : %d", type)); | 181 | + throw new IllegalArgumentException(String.format("Unsupported typeOper type : %s", type)); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
@@ -198,7 +198,7 @@ public class LwM2mTransportHandlerUtil { | @@ -198,7 +198,7 @@ public class LwM2mTransportHandlerUtil { | ||
198 | case OBJLNK: | 198 | case OBJLNK: |
199 | return valueOld.equals(valueNew); | 199 | return valueOld.equals(valueNew); |
200 | case OPAQUE: | 200 | case OPAQUE: |
201 | - return Hex.decodeHex(((String) valueOld).toCharArray()).equals(Hex.decodeHex(((String) valueNew).toCharArray())); | 201 | + return Arrays.equals(Hex.decodeHex(((String) valueOld).toCharArray()), Hex.decodeHex(((String) valueNew).toCharArray())); |
202 | default: | 202 | default: |
203 | throw new CodecException("Invalid value type for resource %s, type %s", resourcePath, type); | 203 | throw new CodecException("Invalid value type for resource %s, type %s", resourcePath, type); |
204 | } | 204 | } |
@@ -256,7 +256,7 @@ public class LwM2mTransportHandlerUtil { | @@ -256,7 +256,7 @@ public class LwM2mTransportHandlerUtil { | ||
256 | ObjectMapper mapper = new ObjectMapper(); | 256 | ObjectMapper mapper = new ObjectMapper(); |
257 | String profileStr = mapper.writeValueAsString(profile); | 257 | String profileStr = mapper.writeValueAsString(profile); |
258 | JsonObject profileJson = (profileStr != null) ? validateJson(profileStr) : null; | 258 | JsonObject profileJson = (profileStr != null) ? validateJson(profileStr) : null; |
259 | - return getValidateCredentialsBodyFromThingsboard(profileJson) ? LwM2mTransportHandlerUtil.getNewProfileParameters(profileJson, deviceProfile.getTenantId()) : null; | 259 | + return getValidateCredentialsBodyFromThingsboard(profileJson) ? LwM2mTransportUtil.getNewProfileParameters(profileJson, deviceProfile.getTenantId()) : null; |
260 | } catch (IOException e) { | 260 | } catch (IOException e) { |
261 | log.error("", e); | 261 | log.error("", e); |
262 | } | 262 | } |
@@ -415,7 +415,7 @@ public class LwM2mTransportHandlerUtil { | @@ -415,7 +415,7 @@ public class LwM2mTransportHandlerUtil { | ||
415 | } | 415 | } |
416 | 416 | ||
417 | public static String validPathIdVer(String pathIdVer, Registration registration) throws IllegalArgumentException { | 417 | public static String validPathIdVer(String pathIdVer, Registration registration) throws IllegalArgumentException { |
418 | - if (pathIdVer.indexOf(LWM2M_SEPARATOR_PATH) < 0) { | 418 | + if (!pathIdVer.contains(LWM2M_SEPARATOR_PATH)) { |
419 | throw new IllegalArgumentException(String.format("Error:")); | 419 | throw new IllegalArgumentException(String.format("Error:")); |
420 | } else { | 420 | } else { |
421 | String[] keyArray = pathIdVer.split(LWM2M_SEPARATOR_PATH); | 421 | String[] keyArray = pathIdVer.split(LWM2M_SEPARATOR_PATH); |
@@ -488,7 +488,7 @@ public class LwM2mTransportHandlerUtil { | @@ -488,7 +488,7 @@ public class LwM2mTransportHandlerUtil { | ||
488 | } | 488 | } |
489 | 489 | ||
490 | private static Attribute[] createWriteAttributes(Object params) { | 490 | private static Attribute[] createWriteAttributes(Object params) { |
491 | - List attributeLists = new ArrayList<Attribute>(); | 491 | + List<Attribute> attributeLists = new ArrayList<>(); |
492 | ObjectMapper oMapper = new ObjectMapper(); | 492 | ObjectMapper oMapper = new ObjectMapper(); |
493 | Map<String, Object> map = oMapper.convertValue(params, ConcurrentHashMap.class); | 493 | Map<String, Object> map = oMapper.convertValue(params, ConcurrentHashMap.class); |
494 | map.forEach((k, v) -> { | 494 | map.forEach((k, v) -> { |
@@ -498,7 +498,7 @@ public class LwM2mTransportHandlerUtil { | @@ -498,7 +498,7 @@ public class LwM2mTransportHandlerUtil { | ||
498 | ((Double) v).longValue() : v)); | 498 | ((Double) v).longValue() : v)); |
499 | } | 499 | } |
500 | }); | 500 | }); |
501 | - return (Attribute[]) attributeLists.toArray(Attribute[]::new); | 501 | + return attributeLists.toArray(Attribute[]::new); |
502 | } | 502 | } |
503 | 503 | ||
504 | 504 |
@@ -30,7 +30,6 @@ import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; | @@ -30,7 +30,6 @@ import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; | ||
30 | import java.util.ArrayList; | 30 | import java.util.ArrayList; |
31 | import java.util.Base64; | 31 | import java.util.Base64; |
32 | import java.util.Collection; | 32 | import java.util.Collection; |
33 | -import java.util.Iterator; | ||
34 | import java.util.Map; | 33 | import java.util.Map; |
35 | import java.util.Optional; | 34 | import java.util.Optional; |
36 | 35 | ||
@@ -51,7 +50,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | @@ -51,7 +50,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | ||
51 | private final LwM2mTransportServerHelper helper; | 50 | private final LwM2mTransportServerHelper helper; |
52 | private final LwM2mTransportContext context; | 51 | private final LwM2mTransportContext context; |
53 | 52 | ||
54 | - private String getKeyIdVer(Integer objectId, String version) { | 53 | + private String getKeyIdVer(Integer objectId, String version) { |
55 | return objectId != null ? objectId + LWM2M_SEPARATOR_KEY + ((version == null || version.isEmpty()) ? ObjectModel.DEFAULT_VERSION : version) : null; | 54 | return objectId != null ? objectId + LWM2M_SEPARATOR_KEY + ((version == null || version.isEmpty()) ? ObjectModel.DEFAULT_VERSION : version) : null; |
56 | } | 55 | } |
57 | 56 | ||
@@ -84,7 +83,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | @@ -84,7 +83,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | ||
84 | return objectModel.resources.get(resourceId); | 83 | return objectModel.resources.get(resourceId); |
85 | else | 84 | else |
86 | log.warn("TbResources (Object model) with id [{}/0/{}] not found on the server", objectId, resourceId); | 85 | log.warn("TbResources (Object model) with id [{}/0/{}] not found on the server", objectId, resourceId); |
87 | - return null; | 86 | + return null; |
88 | } catch (Exception e) { | 87 | } catch (Exception e) { |
89 | log.error("", e); | 88 | log.error("", e); |
90 | return null; | 89 | return null; |
@@ -104,9 +103,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | @@ -104,9 +103,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider { | ||
104 | public Collection<ObjectModel> getObjectModels() { | 103 | public Collection<ObjectModel> getObjectModels() { |
105 | Map<Integer, String> supportedObjects = this.registration.getSupportedObject(); | 104 | Map<Integer, String> supportedObjects = this.registration.getSupportedObject(); |
106 | Collection<ObjectModel> result = new ArrayList<>(supportedObjects.size()); | 105 | Collection<ObjectModel> result = new ArrayList<>(supportedObjects.size()); |
107 | - Iterator<Map.Entry<Integer, String>> i$ = supportedObjects.entrySet().iterator(); | ||
108 | - while (i$.hasNext()) { | ||
109 | - Map.Entry<Integer, String> supportedObject = i$.next(); | 106 | + for (Map.Entry<Integer, String> supportedObject : supportedObjects.entrySet()) { |
110 | ObjectModel objectModel = this.getObjectModelDynamic(supportedObject.getKey(), supportedObject.getValue()); | 107 | ObjectModel objectModel = this.getObjectModelDynamic(supportedObject.getKey(), supportedObject.getValue()); |
111 | if (objectModel != null) { | 108 | if (objectModel != null) { |
112 | result.add(objectModel); | 109 | result.add(objectModel); |
@@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.Registration; | @@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.Registration; | ||
26 | import org.eclipse.leshan.server.security.SecurityInfo; | 26 | import org.eclipse.leshan.server.security.SecurityInfo; |
27 | import org.thingsboard.server.gen.transport.TransportProtos; | 27 | import org.thingsboard.server.gen.transport.TransportProtos; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg; |
29 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest; | ||
30 | import org.thingsboard.server.transport.lwm2m.server.DefaultLwM2MTransportMsgHandler; | 29 | import org.thingsboard.server.transport.lwm2m.server.DefaultLwM2MTransportMsgHandler; |
30 | +import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest; | ||
31 | import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; | 31 | import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; |
32 | 32 | ||
33 | import java.util.Collection; | 33 | import java.util.Collection; |
@@ -42,9 +42,9 @@ import java.util.concurrent.CopyOnWriteArrayList; | @@ -42,9 +42,9 @@ import java.util.concurrent.CopyOnWriteArrayList; | ||
42 | import java.util.stream.Collectors; | 42 | import java.util.stream.Collectors; |
43 | 43 | ||
44 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; | 44 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
45 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.TRANSPORT_DEFAULT_LWM2M_VERSION; | ||
46 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId; | ||
47 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getVerFromPathIdVerOrId; | 45 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.TRANSPORT_DEFAULT_LWM2M_VERSION; |
46 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromIdVerToObjectId; | ||
47 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getVerFromPathIdVerOrId; | ||
48 | 48 | ||
49 | @Slf4j | 49 | @Slf4j |
50 | @Data | 50 | @Data |
@@ -25,7 +25,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | @@ -25,7 +25,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; | ||
25 | import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; | 25 | import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; |
26 | import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator; | 26 | import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator; |
27 | import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; | 27 | import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; |
28 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil; | 28 | +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; |
29 | 29 | ||
30 | import java.util.Arrays; | 30 | import java.util.Arrays; |
31 | import java.util.Map; | 31 | import java.util.Map; |
@@ -34,7 +34,7 @@ import java.util.UUID; | @@ -34,7 +34,7 @@ import java.util.UUID; | ||
34 | import java.util.concurrent.ConcurrentHashMap; | 34 | import java.util.concurrent.ConcurrentHashMap; |
35 | 35 | ||
36 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO_SEC; | 36 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO_SEC; |
37 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer; | 37 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; |
38 | 38 | ||
39 | @Service | 39 | @Service |
40 | @TbLwM2mTransportComponent | 40 | @TbLwM2mTransportComponent |
@@ -118,7 +118,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | @@ -118,7 +118,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | ||
118 | */ | 118 | */ |
119 | @Override | 119 | @Override |
120 | public LwM2mClient addLwM2mClientToSession(String identity) { | 120 | public LwM2mClient addLwM2mClientToSession(String identity) { |
121 | - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandlerUtil.LwM2mTypeServer.CLIENT); | 121 | + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportUtil.LwM2mTypeServer.CLIENT); |
122 | if (store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { | 122 | if (store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { |
123 | UUID profileUuid = (store.getDeviceProfile() != null && addUpdateProfileParameters(store.getDeviceProfile())) ? store.getDeviceProfile().getUuidId() : null; | 123 | UUID profileUuid = (store.getDeviceProfile() != null && addUpdateProfileParameters(store.getDeviceProfile())) ? store.getDeviceProfile().getUuidId() : null; |
124 | LwM2mClient client; | 124 | LwM2mClient client; |
@@ -165,7 +165,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | @@ -165,7 +165,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | ||
165 | 165 | ||
166 | @Override | 166 | @Override |
167 | public boolean addUpdateProfileParameters(DeviceProfile deviceProfile) { | 167 | public boolean addUpdateProfileParameters(DeviceProfile deviceProfile) { |
168 | - LwM2mClientProfile lwM2MClientProfile = LwM2mTransportHandlerUtil.getLwM2MClientProfileFromThingsboard(deviceProfile); | 168 | + LwM2mClientProfile lwM2MClientProfile = LwM2mTransportUtil.getLwM2MClientProfileFromThingsboard(deviceProfile); |
169 | if (lwM2MClientProfile != null) { | 169 | if (lwM2MClientProfile != null) { |
170 | profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile); | 170 | profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile); |
171 | return true; | 171 | return true; |
@@ -21,11 +21,11 @@ import org.eclipse.leshan.core.request.ContentFormat; | @@ -21,11 +21,11 @@ import org.eclipse.leshan.core.request.ContentFormat; | ||
21 | import org.eclipse.leshan.server.registration.Registration; | 21 | import org.eclipse.leshan.server.registration.Registration; |
22 | import org.thingsboard.server.gen.transport.TransportProtos; | 22 | import org.thingsboard.server.gen.transport.TransportProtos; |
23 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; | 23 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; |
24 | -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper; | 24 | +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; |
25 | 25 | ||
26 | import java.util.concurrent.ConcurrentHashMap; | 26 | import java.util.concurrent.ConcurrentHashMap; |
27 | 27 | ||
28 | -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.validPathIdVer; | 28 | +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.validPathIdVer; |
29 | 29 | ||
30 | @Data | 30 | @Data |
31 | public class Lwm2mClientRpcRequest { | 31 | public class Lwm2mClientRpcRequest { |
@@ -43,7 +43,7 @@ public class Lwm2mClientRpcRequest { | @@ -43,7 +43,7 @@ public class Lwm2mClientRpcRequest { | ||
43 | 43 | ||
44 | private LwM2mTypeOper typeOper; | 44 | private LwM2mTypeOper typeOper; |
45 | private String targetIdVer; | 45 | private String targetIdVer; |
46 | - private String contentFormatName; | 46 | + private String contentFormatName; |
47 | private long timeoutInMs; | 47 | private long timeoutInMs; |
48 | private Object value; | 48 | private Object value; |
49 | private ConcurrentHashMap<String, Object> params; | 49 | private ConcurrentHashMap<String, Object> params; |
@@ -54,19 +54,19 @@ public class Lwm2mClientRpcRequest { | @@ -54,19 +54,19 @@ public class Lwm2mClientRpcRequest { | ||
54 | private String infoMsg; | 54 | private String infoMsg; |
55 | private String responseCode; | 55 | private String responseCode; |
56 | 56 | ||
57 | - public void setValidTypeOper (String typeOper){ | 57 | + public void setValidTypeOper(String typeOper) { |
58 | try { | 58 | try { |
59 | this.typeOper = LwM2mTypeOper.fromLwLwM2mTypeOper(typeOper); | 59 | this.typeOper = LwM2mTypeOper.fromLwLwM2mTypeOper(typeOper); |
60 | } catch (Exception e) { | 60 | } catch (Exception e) { |
61 | this.errorMsg = this.methodKey + " - " + typeOper + " is not valid."; | 61 | this.errorMsg = this.methodKey + " - " + typeOper + " is not valid."; |
62 | } | 62 | } |
63 | } | 63 | } |
64 | - public void setValidContentFormatName (JsonObject rpcRequest){ | 64 | + |
65 | + public void setValidContentFormatName(JsonObject rpcRequest) { | ||
65 | try { | 66 | try { |
66 | if (ContentFormat.fromName(rpcRequest.get(this.contentFormatNameKey).getAsString()) != null) { | 67 | if (ContentFormat.fromName(rpcRequest.get(this.contentFormatNameKey).getAsString()) != null) { |
67 | this.contentFormatName = rpcRequest.get(this.contentFormatNameKey).getAsString(); | 68 | this.contentFormatName = rpcRequest.get(this.contentFormatNameKey).getAsString(); |
68 | - } | ||
69 | - else { | 69 | + } else { |
70 | this.errorMsg = this.contentFormatNameKey + " - " + rpcRequest.get(this.contentFormatNameKey).getAsString() + " is not valid."; | 70 | this.errorMsg = this.contentFormatNameKey + " - " + rpcRequest.get(this.contentFormatNameKey).getAsString() + " is not valid."; |
71 | } | 71 | } |
72 | } catch (Exception e) { | 72 | } catch (Exception e) { |
@@ -74,14 +74,14 @@ public class Lwm2mClientRpcRequest { | @@ -74,14 +74,14 @@ public class Lwm2mClientRpcRequest { | ||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | - public void setValidTargetIdVerKey (JsonObject rpcRequest, Registration registration){ | 77 | + public void setValidTargetIdVerKey(JsonObject rpcRequest, Registration registration) { |
78 | if (rpcRequest.has(this.targetIdVerKey)) { | 78 | if (rpcRequest.has(this.targetIdVerKey)) { |
79 | String targetIdVerStr = rpcRequest.get(targetIdVerKey).getAsString(); | 79 | String targetIdVerStr = rpcRequest.get(targetIdVerKey).getAsString(); |
80 | // targetIdVer without ver - ok | 80 | // targetIdVer without ver - ok |
81 | try { | 81 | try { |
82 | // targetIdVer with/without ver - ok | 82 | // targetIdVer with/without ver - ok |
83 | this.targetIdVer = validPathIdVer(targetIdVerStr, registration); | 83 | this.targetIdVer = validPathIdVer(targetIdVerStr, registration); |
84 | - if (this.targetIdVer != null){ | 84 | + if (this.targetIdVer != null) { |
85 | this.infoMsg = String.format("Changed by: pathIdVer - %s", this.targetIdVer); | 85 | this.infoMsg = String.format("Changed by: pathIdVer - %s", this.targetIdVer); |
86 | } | 86 | } |
87 | } catch (Exception e) { | 87 | } catch (Exception e) { |
@@ -97,11 +97,9 @@ public class Lwm2mClientRpcRequest { | @@ -97,11 +97,9 @@ public class Lwm2mClientRpcRequest { | ||
97 | payloadResp.addProperty(this.resultKey, this.responseCode); | 97 | payloadResp.addProperty(this.resultKey, this.responseCode); |
98 | if (this.errorMsg != null) { | 98 | if (this.errorMsg != null) { |
99 | payloadResp.addProperty(this.errorKey, this.errorMsg); | 99 | payloadResp.addProperty(this.errorKey, this.errorMsg); |
100 | - } | ||
101 | - else if (this.valueMsg != null) { | 100 | + } else if (this.valueMsg != null) { |
102 | payloadResp.addProperty(this.valueKey, this.valueMsg); | 101 | payloadResp.addProperty(this.valueKey, this.valueMsg); |
103 | - } | ||
104 | - else if (this.infoMsg != null) { | 102 | + } else if (this.infoMsg != null) { |
105 | payloadResp.addProperty(this.infoKey, this.infoMsg); | 103 | payloadResp.addProperty(this.infoKey, this.infoMsg); |
106 | } | 104 | } |
107 | return TransportProtos.ToDeviceRpcResponseMsg.newBuilder() | 105 | return TransportProtos.ToDeviceRpcResponseMsg.newBuilder() |
@@ -18,6 +18,7 @@ package org.thingsboard.server.transport.lwm2m.server.client; | @@ -18,6 +18,7 @@ package org.thingsboard.server.transport.lwm2m.server.client; | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.eclipse.leshan.core.model.ObjectModel; | 19 | import org.eclipse.leshan.core.model.ObjectModel; |
20 | import org.eclipse.leshan.core.node.LwM2mObjectInstance; | 20 | import org.eclipse.leshan.core.node.LwM2mObjectInstance; |
21 | + | ||
21 | import java.util.Map; | 22 | import java.util.Map; |
22 | 23 | ||
23 | @Data | 24 | @Data |
@@ -18,12 +18,12 @@ package org.thingsboard.server.transport.lwm2m.server.store; | @@ -18,12 +18,12 @@ package org.thingsboard.server.transport.lwm2m.server.store; | ||
18 | import org.eclipse.californium.core.coap.Token; | 18 | import org.eclipse.californium.core.coap.Token; |
19 | import org.eclipse.californium.core.observe.ObservationStoreException; | 19 | import org.eclipse.californium.core.observe.ObservationStoreException; |
20 | import org.eclipse.californium.elements.EndpointContext; | 20 | import org.eclipse.californium.elements.EndpointContext; |
21 | -import org.eclipse.leshan.core.observation.Observation; | ||
22 | -import org.eclipse.leshan.core.util.NamedThreadFactory; | ||
23 | -import org.eclipse.leshan.core.util.Validate; | ||
24 | import org.eclipse.leshan.core.Destroyable; | 21 | import org.eclipse.leshan.core.Destroyable; |
25 | import org.eclipse.leshan.core.Startable; | 22 | import org.eclipse.leshan.core.Startable; |
26 | import org.eclipse.leshan.core.Stoppable; | 23 | import org.eclipse.leshan.core.Stoppable; |
24 | +import org.eclipse.leshan.core.observation.Observation; | ||
25 | +import org.eclipse.leshan.core.util.NamedThreadFactory; | ||
26 | +import org.eclipse.leshan.core.util.Validate; | ||
27 | import org.eclipse.leshan.server.californium.observation.ObserveUtil; | 27 | import org.eclipse.leshan.server.californium.observation.ObserveUtil; |
28 | import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore; | 28 | import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore; |
29 | import org.eclipse.leshan.server.redis.JedisLock; | 29 | import org.eclipse.leshan.server.redis.JedisLock; |
@@ -21,7 +21,6 @@ import org.eclipse.leshan.server.security.NonUniqueSecurityInfoException; | @@ -21,7 +21,6 @@ import org.eclipse.leshan.server.security.NonUniqueSecurityInfoException; | ||
21 | import org.eclipse.leshan.server.security.SecurityInfo; | 21 | import org.eclipse.leshan.server.security.SecurityInfo; |
22 | import org.eclipse.leshan.server.security.SecurityStoreListener; | 22 | import org.eclipse.leshan.server.security.SecurityStoreListener; |
23 | import org.springframework.data.redis.connection.RedisConnectionFactory; | 23 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
24 | -import org.springframework.stereotype.Service; | ||
25 | import redis.clients.jedis.Jedis; | 24 | import redis.clients.jedis.Jedis; |
26 | import redis.clients.jedis.ScanParams; | 25 | import redis.clients.jedis.ScanParams; |
27 | import redis.clients.jedis.ScanResult; | 26 | import redis.clients.jedis.ScanResult; |