Commit b34198f30c6f852eb8fca0e9a37cd0fe2538add7

Authored by ShvaykaD
Committed by GitHub
1 parent e3292e89

refactored CoAP Server component (#4497)

* refactored ce code base needed for coap-integration in pe

* added anotation TbCoapServerComponent on CoapTransportService

* license updated
... ... @@ -621,9 +621,9 @@ transport:
621 621 key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}"
622 622 # Key alias
623 623 key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}"
624   - # Skip certificate validity check for client certificates.
625   - skip_validity_check_for_client_cert: "${COAP_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}"
626 624 x509:
  625 + # Skip certificate validity check for client certificates.
  626 + skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}"
627 627 dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}"
628 628 dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}"
629 629 # Local LwM2M transport parameters
... ...
... ... @@ -19,11 +19,10 @@ import lombok.Getter;
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.springframework.beans.factory.annotation.Value;
22   -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
23 22 import org.springframework.stereotype.Component;
24 23
25 24 @Slf4j
26   -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
  25 +@TbCoapServerComponent
27 26 @Component
28 27 public class CoapServerContext {
29 28
... ...
... ... @@ -23,7 +23,6 @@ import org.eclipse.californium.core.server.resources.Resource;
23 23 import org.eclipse.californium.scandium.DTLSConnector;
24 24 import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
25 25 import org.springframework.beans.factory.annotation.Autowired;
26   -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
27 26 import org.springframework.stereotype.Component;
28 27
29 28 import javax.annotation.PostConstruct;
... ... @@ -39,7 +38,7 @@ import java.util.concurrent.TimeUnit;
39 38
40 39 @Slf4j
41 40 @Component
42   -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
  41 +@TbCoapServerComponent
43 42 public class DefaultCoapServerService implements CoapServerService {
44 43
45 44 @Autowired
... ...
... ... @@ -39,7 +39,6 @@ import java.util.Collections;
39 39 import java.util.Optional;
40 40
41 41 @Slf4j
42   -@ConditionalOnExpression("'${transport.coap.enabled}'=='true'")
43 42 @ConditionalOnProperty(prefix = "transport.coap.dtls", value = "enabled", havingValue = "true", matchIfMissing = false)
44 43 @Component
45 44 public class TbCoapDtlsSettings {
... ... @@ -50,7 +49,7 @@ public class TbCoapDtlsSettings {
50 49 @Value("${transport.coap.dtls.bind_port}")
51 50 private Integer port;
52 51
53   - @Value("${transport.coap.dtls.mode}")
  52 + @Value("${transport.coap.dtls.mode:NO_AUTH}")
54 53 private String mode;
55 54
56 55 @Value("${transport.coap.dtls.key_store}")
... ... @@ -65,13 +64,13 @@ public class TbCoapDtlsSettings {
65 64 @Value("${transport.coap.dtls.key_alias}")
66 65 private String keyAlias;
67 66
68   - @Value("${transport.coap.dtls.skip_validity_check_for_client_cert}")
  67 + @Value("${transport.coap.dtls.x509.skip_validity_check_for_client_cert:false}")
69 68 private boolean skipValidityCheckForClientCert;
70 69
71   - @Value("${transport.coap.dtls.x509.dtls_session_inactivity_timeout}")
  70 + @Value("${transport.coap.dtls.x509.dtls_session_inactivity_timeout:86400000}")
72 71 private long dtlsSessionInactivityTimeout;
73 72
74   - @Value("${transport.coap.dtls.x509.dtls_session_report_timeout}")
  73 + @Value("${transport.coap.dtls.x509.dtls_session_report_timeout:1800000}")
75 74 private long dtlsSessionReportTimeout;
76 75
77 76 @Autowired
... ...
  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.coapserver;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
  19 +
  20 +import java.lang.annotation.Retention;
  21 +import java.lang.annotation.RetentionPolicy;
  22 +
  23 +@Retention(RetentionPolicy.RUNTIME)
  24 +@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
  25 +public @interface TbCoapServerComponent {
  26 +}
... ...
... ... @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
23 23 import org.springframework.stereotype.Service;
24 24 import org.thingsboard.server.common.data.TbTransportService;
25 25 import org.thingsboard.server.coapserver.CoapServerService;
  26 +import org.thingsboard.server.coapserver.TbCoapServerComponent;
26 27 import org.thingsboard.server.transport.coap.efento.CoapEfentoTransportResource;
27 28
28 29 import javax.annotation.PostConstruct;
... ... @@ -30,7 +31,7 @@ import javax.annotation.PreDestroy;
30 31 import java.net.UnknownHostException;
31 32
32 33 @Service("CoapTransportService")
33   -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
  34 +@TbCoapServerComponent
34 35 @Slf4j
35 36 public class CoapTransportService implements TbTransportService {
36 37
... ...
... ... @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
22 22 import com.fasterxml.jackson.databind.node.ObjectNode;
23 23
24 24 import java.io.IOException;
  25 +import java.util.Arrays;
25 26
26 27 /**
27 28 * Created by Valerii Sosliuk on 5/12/2017.
... ... @@ -66,6 +67,15 @@ public class JacksonUtil {
66 67 }
67 68 }
68 69
  70 + public static JsonNode fromBytes(byte[] bytes) {
  71 + try {
  72 + return OBJECT_MAPPER.readTree(bytes);
  73 + } catch (IOException e) {
  74 + throw new IllegalArgumentException("The given byte[] value: "
  75 + + Arrays.toString(bytes) + " cannot be transformed to Json object", e);
  76 + }
  77 + }
  78 +
69 79 public static String toString(Object value) {
70 80 try {
71 81 return value != null ? OBJECT_MAPPER.writeValueAsString(value) : null;
... ...