Merge pull request #4313 from thingsboard/lwm2m_fix_bug_front
Lwm2m fix bug front
This commit is contained in:
commit
712bab434e
@ -109,14 +109,15 @@ public class LwM2mTransportRequest {
|
|||||||
* Device management and service enablement, including Read, Write, Execute, Discover, Create, Delete and Write-Attributes
|
* Device management and service enablement, including Read, Write, Execute, Discover, Create, Delete and Write-Attributes
|
||||||
*
|
*
|
||||||
* @param registration -
|
* @param registration -
|
||||||
* @param target -
|
* @param targetIdVer -
|
||||||
* @param typeOper -
|
* @param typeOper -
|
||||||
* @param contentFormatParam -
|
* @param contentFormatParam -
|
||||||
* @param observation -
|
* @param observation -
|
||||||
*/
|
*/
|
||||||
public void sendAllRequest(Registration registration, String target, String typeOper,
|
public void sendAllRequest(Registration registration, String targetIdVer, String typeOper,
|
||||||
String contentFormatParam, Observation observation, Object params, long timeoutInMs) {
|
String contentFormatParam, Observation observation, Object params, long timeoutInMs) {
|
||||||
LwM2mPath resultIds = new LwM2mPath(convertToObjectIdFromIdVer(target));
|
String target = convertToObjectIdFromIdVer(targetIdVer);
|
||||||
|
LwM2mPath resultIds = new LwM2mPath(target);
|
||||||
if (registration != null && resultIds.getObjectId() >= 0) {
|
if (registration != null && resultIds.getObjectId() >= 0) {
|
||||||
DownlinkRequest request = null;
|
DownlinkRequest request = null;
|
||||||
ContentFormat contentFormat = contentFormatParam != null ? ContentFormat.fromName(contentFormatParam.toUpperCase()) : null;
|
ContentFormat contentFormat = contentFormatParam != null ? ContentFormat.fromName(contentFormatParam.toUpperCase()) : null;
|
||||||
@ -221,7 +222,7 @@ public class LwM2mTransportRequest {
|
|||||||
this.sendRequest(registration, lwM2MClient, request, timeoutInMs);
|
this.sendRequest(registration, lwM2MClient, request, timeoutInMs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.error("[{}], [{}] - [{}] error SendRequest", registration.getEndpoint(), typeOper, target);
|
log.error("[{}], [{}] - [{}] error SendRequest", registration.getEndpoint(), typeOper, targetIdVer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -360,7 +360,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResourceUpdate (Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) {
|
public void onResourceUpdate (Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) {
|
||||||
String idVer = resourceUpdateMsgOpt.get().getResourceKey(); // 19_1.0
|
String idVer = resourceUpdateMsgOpt.get().getResourceKey();
|
||||||
lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.updateResourceModel(idVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider()));
|
lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.updateResourceModel(idVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResourceDelete(Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) {
|
public void onResourceDelete(Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) {
|
||||||
String pathIdVer = resourceDeleteMsgOpt.get().getResourceKey(); // 19_1.0
|
String pathIdVer = resourceDeleteMsgOpt.get().getResourceKey();
|
||||||
lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.deleteResources(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider()));
|
lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.deleteResources(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,8 +537,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
Set<String> paths = new HashSet<>();
|
Set<String> paths = new HashSet<>();
|
||||||
paths.add(path);
|
paths.add(path);
|
||||||
this.updateAttrTelemetry(registration, paths);
|
this.updateAttrTelemetry(registration, paths);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
log.error("Fail update Resource [{}]", lwM2mResource);
|
log.error("Fail update Resource [{}]", lwM2mResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -574,7 +573,8 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
private boolean validatePathInAttrProfile(LwM2mClientProfile clientProfile, String path) {
|
private boolean validatePathInAttrProfile(LwM2mClientProfile clientProfile, String path) {
|
||||||
try {
|
try {
|
||||||
List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(),
|
List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(),
|
||||||
new TypeToken<List<String>>() {}.getType());
|
new TypeToken<List<String>>() {
|
||||||
|
}.getType());
|
||||||
return attributesSet.stream().anyMatch(p -> p.equals(path));
|
return attributesSet.stream().anyMatch(p -> p.equals(path));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Fail Validate Path [{}] ClientProfile.Attribute", path, e);
|
log.error("Fail Validate Path [{}] ClientProfile.Attribute", path, e);
|
||||||
@ -830,7 +830,6 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
|
if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
|
||||||
// update value in Resources
|
// update value in Resources
|
||||||
registrationIds.forEach(registrationId -> {
|
registrationIds.forEach(registrationId -> {
|
||||||
// LeshanServer lwServer = leshanServer;
|
|
||||||
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
||||||
this.readResourceValueObserve(registration, sendAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
this.readResourceValueObserve(registration, sendAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
||||||
// send attr/telemetry to tingsboard for new path
|
// send attr/telemetry to tingsboard for new path
|
||||||
|
|||||||
@ -84,16 +84,18 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="mat-block">
|
<mat-form-field class="mat-block">
|
||||||
<mat-label translate>device.lwm2m-value</mat-label>
|
<mat-label translate>device.lwm2m-value</mat-label>
|
||||||
<textarea matInput formControlName="credentialsValue" rows="10" required></textarea>
|
<textarea matInput formControlName="credentialsValue" rows="10" required
|
||||||
|
[matTooltip]="lwm2mCredentialsValueTip(deviceCredentialsFormGroup.get('credentialsValue').hasError('jsonError'))"
|
||||||
|
matTooltipPosition="above"
|
||||||
|
></textarea>
|
||||||
<mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsValue').hasError('required')">
|
<mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsValue').hasError('required')">
|
||||||
{{ 'device.lwm2m-value-required' | translate }}
|
{{ 'device.lwm2m-value-required' | translate }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
<mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsValue').hasError('jsonError')">
|
<mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsValue').hasError('jsonError')">
|
||||||
{{ 'device.lwm2m-value-json-error' | translate }}
|
{{ 'device.lwm2m-value-format-error' | translate }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
<div mat-dialog-actions fxLayoutAlign="center center">
|
<div mat-dialog-actions fxLayoutAlign="center center">
|
||||||
<button mat-raised-button color="primary"
|
<button mat-raised-button color="primary"
|
||||||
matTooltip="{{'device.lwm2m-value-edit-tip' | translate }}"
|
|
||||||
(click)="openSecurityInfoLwM2mDialog($event)"
|
(click)="openSecurityInfoLwM2mDialog($event)"
|
||||||
>
|
>
|
||||||
{{'device.lwm2m-value-edit' | translate }}
|
{{'device.lwm2m-value-edit' | translate }}
|
||||||
|
|||||||
@ -37,11 +37,13 @@ import {Subscription} from 'rxjs';
|
|||||||
import {distinctUntilChanged} from 'rxjs/operators';
|
import {distinctUntilChanged} from 'rxjs/operators';
|
||||||
import {SecurityConfigComponent} from '@home/pages/device/lwm2m/security-config.component';
|
import {SecurityConfigComponent} from '@home/pages/device/lwm2m/security-config.component';
|
||||||
import {
|
import {
|
||||||
|
ClientSecurityConfig,
|
||||||
DEFAULT_END_POINT,
|
DEFAULT_END_POINT,
|
||||||
DeviceCredentialsDialogLwm2mData,
|
DeviceCredentialsDialogLwm2mData,
|
||||||
END_POINT,
|
END_POINT,
|
||||||
getDefaultSecurityConfig,
|
getDefaultSecurityConfig,
|
||||||
JSON_ALL_CONFIG, SecurityConfigModels, validateSecurityConfig
|
JSON_ALL_CONFIG,
|
||||||
|
validateSecurityConfig
|
||||||
} from '@home/pages/device/lwm2m/security-config.models';
|
} from '@home/pages/device/lwm2m/security-config.models';
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import {MatDialog} from '@angular/material/dialog';
|
import {MatDialog} from '@angular/material/dialog';
|
||||||
@ -129,6 +131,8 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
|
|||||||
let credentialsValue = null;
|
let credentialsValue = null;
|
||||||
if (value.credentialsType === DeviceCredentialsType.MQTT_BASIC) {
|
if (value.credentialsType === DeviceCredentialsType.MQTT_BASIC) {
|
||||||
credentialsBasic = JSON.parse(value.credentialsValue) as DeviceCredentialMQTTBasic;
|
credentialsBasic = JSON.parse(value.credentialsValue) as DeviceCredentialMQTTBasic;
|
||||||
|
} else if (value.credentialsType === DeviceCredentialsType.LWM2M_CREDENTIALS) {
|
||||||
|
credentialsValue = JSON.parse(JSON.stringify(value.credentialsValue)) as ClientSecurityConfig;
|
||||||
} else {
|
} else {
|
||||||
credentialsValue = value.credentialsValue;
|
credentialsValue = value.credentialsValue;
|
||||||
}
|
}
|
||||||
@ -178,7 +182,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
|
|||||||
credentialsTypeChanged(): void {
|
credentialsTypeChanged(): void {
|
||||||
this.deviceCredentialsFormGroup.patchValue({
|
this.deviceCredentialsFormGroup.patchValue({
|
||||||
credentialsId: null,
|
credentialsId: null,
|
||||||
credentialsValue: null,
|
credentialsValue: JSON.stringify(getDefaultSecurityConfig(), null, 2),
|
||||||
credentialsBasic: {clientId: '', userName: '', password: ''}
|
credentialsBasic: {clientId: '', userName: '', password: ''}
|
||||||
});
|
});
|
||||||
this.updateValidators();
|
this.updateValidators();
|
||||||
@ -203,7 +207,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
|
|||||||
this.deviceCredentialsFormGroup.get('credentialsBasic').disable({emitEvent: false});
|
this.deviceCredentialsFormGroup.get('credentialsBasic').disable({emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case DeviceCredentialsType.LWM2M_CREDENTIALS:
|
case DeviceCredentialsType.LWM2M_CREDENTIALS:
|
||||||
this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required, this.jsonValidator]);
|
this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required, this.lwm2mConfigJsonValidator]);
|
||||||
this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false});
|
this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false});
|
||||||
this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]);
|
this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]);
|
||||||
this.deviceCredentialsFormGroup.get('credentialsId').updateValueAndValidity({emitEvent: false});
|
this.deviceCredentialsFormGroup.get('credentialsId').updateValueAndValidity({emitEvent: false});
|
||||||
@ -284,7 +288,12 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
|
|||||||
return Object.keys(response).length === 0 || JSON.stringify(response) === '[{}]';
|
return Object.keys(response).length === 0 || JSON.stringify(response) === '[{}]';
|
||||||
}
|
}
|
||||||
|
|
||||||
private jsonValidator(control: FormControl) {
|
private lwm2mConfigJsonValidator(control: FormControl) {
|
||||||
return validateSecurityConfig(control.value) ? null: {jsonError: {parsedJson: "error"}};
|
return validateSecurityConfig(control.value) ? null: {jsonError: {parsedJson: "error"}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lwm2mCredentialsValueTip (flag: boolean): string {
|
||||||
|
let jsonConfigDef = JSON.stringify(getDefaultSecurityConfig(), null, 2);
|
||||||
|
return !flag ? "" : 'Example (mode=\"NoSec\"):\n\r ' + jsonConfigDef;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}">
|
<mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}">
|
||||||
<ng-template matTabContent>
|
<ng-template matTabContent>
|
||||||
<section [formGroup]="lwm2mDeviceProfileFormGroup">
|
<section [formGroup]="lwm2mDeviceProfileFormGroup">
|
||||||
<div class="mat-padding" style="padding-bottom: 0px">
|
<div *ngIf="false" class="mat-padding" style="padding-bottom: 0px">
|
||||||
<mat-form-field class="mat-block">
|
<mat-form-field class="mat-block">
|
||||||
<mat-label>{{ 'device-profile.lwm2m.client-only-observe-after-connect-label' | translate }}</mat-label>
|
<mat-label>{{ 'device-profile.lwm2m.client-only-observe-after-connect-label' | translate }}</mat-label>
|
||||||
<mat-select formControlName="clientOnlyObserveAfterConnect"
|
<mat-select formControlName="clientOnlyObserveAfterConnect"
|
||||||
|
|||||||
@ -127,9 +127,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initWriteValue = (): void => {
|
private initWriteValue = (): void => {
|
||||||
const modelValue = {objectIds: null, objectsList: []} as ModelValue;
|
const modelValue = {objectIds: [], objectsList: []} as ModelValue;
|
||||||
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
||||||
if (modelValue.objectIds !== null) {
|
if (modelValue.objectIds.length > 0) {
|
||||||
const sortOrder = {
|
const sortOrder = {
|
||||||
property: 'id',
|
property: 'id',
|
||||||
direction: Direction.ASC
|
direction: Direction.ASC
|
||||||
@ -205,13 +205,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
if (this.includesNotZeroInstance(attributeArray, telemetryArray)) {
|
if (this.includesNotZeroInstance(attributeArray, telemetryArray)) {
|
||||||
this.addInstances(attributeArray, telemetryArray, objectLwM2MS);
|
this.addInstances(attributeArray, telemetryArray, objectLwM2MS);
|
||||||
}
|
}
|
||||||
if (isDefinedAndNotNull(observeArray)) {
|
if (isDefinedAndNotNull(observeArray) && observeArray.length > 0) {
|
||||||
this.updateObserveAttrTelemetryObjects(observeArray, objectLwM2MS, OBSERVE);
|
this.updateObserveAttrTelemetryObjects(observeArray, objectLwM2MS, OBSERVE);
|
||||||
}
|
}
|
||||||
if (isDefinedAndNotNull(attributeArray)) {
|
if (isDefinedAndNotNull(attributeArray) && attributeArray.length > 0) {
|
||||||
this.updateObserveAttrTelemetryObjects(attributeArray, objectLwM2MS, ATTRIBUTE);
|
this.updateObserveAttrTelemetryObjects(attributeArray, objectLwM2MS, ATTRIBUTE);
|
||||||
}
|
}
|
||||||
if (isDefinedAndNotNull(telemetryArray)) {
|
if (isDefinedAndNotNull(telemetryArray) && telemetryArray.length > 0) {
|
||||||
this.updateObserveAttrTelemetryObjects(telemetryArray, objectLwM2MS, TELEMETRY);
|
this.updateObserveAttrTelemetryObjects(telemetryArray, objectLwM2MS, TELEMETRY);
|
||||||
}
|
}
|
||||||
if (isDefinedAndNotNull(keyNameJson)) {
|
if (isDefinedAndNotNull(keyNameJson)) {
|
||||||
@ -368,7 +368,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (objectsIds.size > 0) ? Array.from(objectsIds) : null;
|
return (objectsIds.size > 0) ? Array.from(objectsIds) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private upDateJsonAllConfig = (): void => {
|
private upDateJsonAllConfig = (): void => {
|
||||||
|
|||||||
@ -55,12 +55,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div fxFlex="10">
|
<div fxFlex="10">
|
||||||
<mat-checkbox formControlName="attribute" color="warn"
|
<mat-checkbox formControlName="attribute" color="warn"
|
||||||
|
[checked]="updateObserve(i)"
|
||||||
matTooltip="{{'device-profile.lwm2m.is-attr-tip' | translate}}"
|
matTooltip="{{'device-profile.lwm2m.is-attr-tip' | translate}}"
|
||||||
matTooltipPosition="above">
|
matTooltipPosition="above">
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
<div fxFlex="10">
|
<div fxFlex="10">
|
||||||
<mat-checkbox formControlName="telemetry" color="primary"
|
<mat-checkbox formControlName="telemetry" color="primary"
|
||||||
|
[checked]="updateObserve(i)"
|
||||||
matTooltip="{{'device-profile.lwm2m.is-telemetry-tip' | translate}}"
|
matTooltip="{{'device-profile.lwm2m.is-telemetry-tip' | translate}}"
|
||||||
matTooltipPosition="above">
|
matTooltipPosition="above">
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
|
|||||||
@ -124,4 +124,10 @@ export class Lwm2mObserveAttrTelemetryResourceComponent implements ControlValueA
|
|||||||
trackByParams = (index: number): number => {
|
trackByParams = (index: number): number => {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateObserve = (index: number): void =>{
|
||||||
|
if (this.resourceFormArray.at(index).value.attribute === false && this.resourceFormArray.at(index).value.telemetry === false) {
|
||||||
|
this.resourceFormArray.at(index).patchValue({observe: false});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ export const SECURITY_CONFIG_MODE_NAMES = new Map<SECURITY_CONFIG_MODE, string>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export interface ModelValue {
|
export interface ModelValue {
|
||||||
objectIds: string[] | null,
|
objectIds: string[],
|
||||||
objectsList: ObjectLwM2M[]
|
objectsList: ObjectLwM2M[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ export interface ProfileConfigModels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientLwM2mSettings {
|
export interface ClientLwM2mSettings {
|
||||||
clientOnlyObserveAfterConnect: boolean;
|
clientOnlyObserveAfterConnect: number;
|
||||||
}
|
}
|
||||||
export interface ObservableAttributes {
|
export interface ObservableAttributes {
|
||||||
observe: string[];
|
observe: string[];
|
||||||
@ -157,7 +157,7 @@ function getDefaultProfileObserveAttrConfig(): ObservableAttributes {
|
|||||||
|
|
||||||
function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
|
function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
|
||||||
return {
|
return {
|
||||||
clientOnlyObserveAfterConnect: true
|
clientOnlyObserveAfterConnect: 1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,12 +26,9 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import {
|
import {
|
||||||
BOOTSTRAP_SERVER,
|
BOOTSTRAP_SERVER,
|
||||||
BOOTSTRAP_SERVERS,
|
BOOTSTRAP_SERVERS,
|
||||||
ClientSecurityConfigNoSEC,
|
ClientSecurityConfig,
|
||||||
ClientSecurityConfigPSK,
|
|
||||||
ClientSecurityConfigRPK,
|
|
||||||
ClientSecurityConfigX509,
|
|
||||||
DeviceCredentialsDialogLwm2mData,
|
DeviceCredentialsDialogLwm2mData,
|
||||||
getDefaultClientSecurityConfigType,
|
getClientSecurityConfig,
|
||||||
JSON_ALL_CONFIG,
|
JSON_ALL_CONFIG,
|
||||||
KEY_REGEXP_HEX_DEC,
|
KEY_REGEXP_HEX_DEC,
|
||||||
LEN_MAX_PSK,
|
LEN_MAX_PSK,
|
||||||
@ -115,20 +112,20 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
case SECURITY_CONFIG_MODE.NO_SEC:
|
case SECURITY_CONFIG_MODE.NO_SEC:
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.PSK:
|
case SECURITY_CONFIG_MODE.PSK:
|
||||||
const clientSecurityConfigPSK = jsonAllConfig.client as ClientSecurityConfigPSK;
|
const clientSecurityConfigPSK = jsonAllConfig.client as ClientSecurityConfig;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
identityPSK: clientSecurityConfigPSK.identity,
|
identityPSK: clientSecurityConfigPSK.identity,
|
||||||
clientKey: clientSecurityConfigPSK.key,
|
clientKey: clientSecurityConfigPSK.key,
|
||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.RPK:
|
case SECURITY_CONFIG_MODE.RPK:
|
||||||
const clientSecurityConfigRPK = jsonAllConfig.client as ClientSecurityConfigRPK;
|
const clientSecurityConfigRPK = jsonAllConfig.client as ClientSecurityConfig;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
clientKey: clientSecurityConfigRPK.key,
|
clientKey: clientSecurityConfigRPK.key,
|
||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.X509:
|
case SECURITY_CONFIG_MODE.X509:
|
||||||
const clientSecurityConfigX509 = jsonAllConfig.client as ClientSecurityConfigX509;
|
const clientSecurityConfigX509 = jsonAllConfig.client as ClientSecurityConfig;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
clientCertificate: clientSecurityConfigX509.x509
|
clientCertificate: clientSecurityConfigX509.x509
|
||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
@ -140,7 +137,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
securityConfigClientModeChanged = (mode: SECURITY_CONFIG_MODE): void => {
|
securityConfigClientModeChanged = (mode: SECURITY_CONFIG_MODE): void => {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SECURITY_CONFIG_MODE.NO_SEC:
|
case SECURITY_CONFIG_MODE.NO_SEC:
|
||||||
const clientSecurityConfigNoSEC = getDefaultClientSecurityConfigType(mode) as ClientSecurityConfigNoSEC;
|
const clientSecurityConfigNoSEC = getClientSecurityConfig(mode) as ClientSecurityConfig;
|
||||||
this.jsonAllConfig.client = clientSecurityConfigNoSEC;
|
this.jsonAllConfig.client = clientSecurityConfigNoSEC;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
jsonAllConfig: this.jsonAllConfig,
|
jsonAllConfig: this.jsonAllConfig,
|
||||||
@ -148,8 +145,8 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.PSK:
|
case SECURITY_CONFIG_MODE.PSK:
|
||||||
const clientSecurityConfigPSK = getDefaultClientSecurityConfigType(mode, this.lwm2mConfigFormGroup.get('endPoint')
|
const clientSecurityConfigPSK = getClientSecurityConfig(mode, this.lwm2mConfigFormGroup.get('endPoint')
|
||||||
.value) as ClientSecurityConfigPSK;
|
.value) as ClientSecurityConfig;
|
||||||
clientSecurityConfigPSK.identity = this.data.endPoint;
|
clientSecurityConfigPSK.identity = this.data.endPoint;
|
||||||
clientSecurityConfigPSK.key = this.lwm2mConfigFormGroup.get('clientKey').value;
|
clientSecurityConfigPSK.key = this.lwm2mConfigFormGroup.get('clientKey').value;
|
||||||
this.jsonAllConfig.client = clientSecurityConfigPSK;
|
this.jsonAllConfig.client = clientSecurityConfigPSK;
|
||||||
@ -159,7 +156,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.RPK:
|
case SECURITY_CONFIG_MODE.RPK:
|
||||||
const clientSecurityConfigRPK = getDefaultClientSecurityConfigType(mode) as ClientSecurityConfigRPK;
|
const clientSecurityConfigRPK = getClientSecurityConfig(mode) as ClientSecurityConfig;
|
||||||
clientSecurityConfigRPK.key = this.lwm2mConfigFormGroup.get('clientKey').value;
|
clientSecurityConfigRPK.key = this.lwm2mConfigFormGroup.get('clientKey').value;
|
||||||
this.jsonAllConfig.client = clientSecurityConfigRPK;
|
this.jsonAllConfig.client = clientSecurityConfigRPK;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
@ -167,7 +164,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.X509:
|
case SECURITY_CONFIG_MODE.X509:
|
||||||
this.jsonAllConfig.client = getDefaultClientSecurityConfigType(mode) as ClientSecurityConfigX509;
|
this.jsonAllConfig.client = getClientSecurityConfig(mode) as ClientSecurityConfig;
|
||||||
this.lwm2mConfigFormGroup.patchValue({
|
this.lwm2mConfigFormGroup.patchValue({
|
||||||
clientCertificate: true
|
clientCertificate: true
|
||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
@ -236,11 +233,11 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
|
|||||||
if (this.lwm2mConfigFormGroup !== null) {
|
if (this.lwm2mConfigFormGroup !== null) {
|
||||||
if (!this.lwm2mConfigFormGroup.get('endPoint').pristine && this.lwm2mConfigFormGroup.get('endPoint').valid) {
|
if (!this.lwm2mConfigFormGroup.get('endPoint').pristine && this.lwm2mConfigFormGroup.get('endPoint').valid) {
|
||||||
this.data.endPoint = this.lwm2mConfigFormGroup.get('endPoint').value;
|
this.data.endPoint = this.lwm2mConfigFormGroup.get('endPoint').value;
|
||||||
// Client mode == PSK
|
/** Client mode == PSK */
|
||||||
if (this.lwm2mConfigFormGroup.get('securityConfigClientMode').value === SECURITY_CONFIG_MODE.PSK) {
|
if (this.lwm2mConfigFormGroup.get('securityConfigClientMode').value === SECURITY_CONFIG_MODE.PSK) {
|
||||||
const endPoint = 'endpoint';
|
const endPoint = 'endpoint';
|
||||||
this.jsonAllConfig.client[endPoint] = this.data.endPoint;
|
this.jsonAllConfig.client[endPoint] = this.data.endPoint;
|
||||||
this.jsonAllConfig.client[endPoint].markAsPristine({
|
this.lwm2mConfigFormGroup.get('endPoint').markAsPristine({
|
||||||
onlySelf: true
|
onlySelf: true
|
||||||
});
|
});
|
||||||
this.upDateJsonAllConfig();
|
this.upDateJsonAllConfig();
|
||||||
|
|||||||
@ -48,33 +48,14 @@ export const SECURITY_CONFIG_MODE_NAMES = new Map<SECURITY_CONFIG_MODE, string>(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
export type ClientSecurityConfigType =
|
export interface ClientSecurityConfig {
|
||||||
ClientSecurityConfigPSK
|
|
||||||
| ClientSecurityConfigRPK
|
|
||||||
| ClientSecurityConfigX509
|
|
||||||
| ClientSecurityConfigNoSEC;
|
|
||||||
|
|
||||||
export interface ClientSecurityConfigPSK {
|
|
||||||
securityConfigClientMode: string;
|
securityConfigClientMode: string;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
identity: string;
|
identity: string;
|
||||||
key: string;
|
key: string;
|
||||||
}
|
|
||||||
|
|
||||||
export interface ClientSecurityConfigRPK {
|
|
||||||
securityConfigClientMode: string;
|
|
||||||
key: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ClientSecurityConfigX509 {
|
|
||||||
securityConfigClientMode: string;
|
|
||||||
x509: boolean;
|
x509: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientSecurityConfigNoSEC {
|
|
||||||
securityConfigClientMode: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ServerSecurityConfig {
|
export interface ServerSecurityConfig {
|
||||||
securityMode: string;
|
securityMode: string;
|
||||||
clientPublicKeyOrId?: string;
|
clientPublicKeyOrId?: string;
|
||||||
@ -87,43 +68,36 @@ interface BootstrapSecurityConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SecurityConfigModels {
|
export interface SecurityConfigModels {
|
||||||
client: ClientSecurityConfigType;
|
client: ClientSecurityConfig;
|
||||||
bootstrap: BootstrapSecurityConfig;
|
bootstrap: BootstrapSecurityConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultClientSecurityConfigType(securityConfigMode: SECURITY_CONFIG_MODE, endPoint?: string): ClientSecurityConfigType {
|
export function getClientSecurityConfig(securityConfigMode: SECURITY_CONFIG_MODE, endPoint?: string): ClientSecurityConfig {
|
||||||
let security: ClientSecurityConfigType;
|
let security = getDefaultClientSecurityConfig();
|
||||||
|
security.securityConfigClientMode = securityConfigMode.toString();
|
||||||
switch (securityConfigMode) {
|
switch (securityConfigMode) {
|
||||||
case SECURITY_CONFIG_MODE.PSK:
|
case SECURITY_CONFIG_MODE.PSK:
|
||||||
security = {
|
security.endpoint = endPoint;
|
||||||
securityConfigClientMode: '',
|
security.identity = endPoint;
|
||||||
endpoint: endPoint,
|
|
||||||
identity: endPoint,
|
|
||||||
key: ''
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case SECURITY_CONFIG_MODE.RPK:
|
|
||||||
security = {
|
|
||||||
securityConfigClientMode: '',
|
|
||||||
key: ''
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
case SECURITY_CONFIG_MODE.X509:
|
case SECURITY_CONFIG_MODE.X509:
|
||||||
security = {
|
security.x509 = true;
|
||||||
securityConfigClientMode: '',
|
|
||||||
x509: true
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case SECURITY_CONFIG_MODE.NO_SEC:
|
|
||||||
security = {
|
|
||||||
securityConfigClientMode: ''
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
security.securityConfigClientMode = securityConfigMode.toString();
|
|
||||||
return security;
|
return security;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getDefaultClientSecurityConfig(): ClientSecurityConfig {
|
||||||
|
return {
|
||||||
|
securityConfigClientMode: SECURITY_CONFIG_MODE.NO_SEC.toString(),
|
||||||
|
endpoint: '',
|
||||||
|
identity: '',
|
||||||
|
key: '',
|
||||||
|
x509: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function getDefaultServerSecurityConfig(): ServerSecurityConfig {
|
export function getDefaultServerSecurityConfig(): ServerSecurityConfig {
|
||||||
return {
|
return {
|
||||||
securityMode: SECURITY_CONFIG_MODE.NO_SEC.toString(),
|
securityMode: SECURITY_CONFIG_MODE.NO_SEC.toString(),
|
||||||
@ -141,7 +115,7 @@ function getDefaultBootstrapSecurityConfig(): BootstrapSecurityConfig {
|
|||||||
|
|
||||||
export function getDefaultSecurityConfig(): SecurityConfigModels {
|
export function getDefaultSecurityConfig(): SecurityConfigModels {
|
||||||
const securityConfigModels = {
|
const securityConfigModels = {
|
||||||
client: getDefaultClientSecurityConfigType(SECURITY_CONFIG_MODE.NO_SEC),
|
client: getClientSecurityConfig(SECURITY_CONFIG_MODE.NO_SEC),
|
||||||
bootstrap: getDefaultBootstrapSecurityConfig()
|
bootstrap: getDefaultBootstrapSecurityConfig()
|
||||||
};
|
};
|
||||||
return securityConfigModels;
|
return securityConfigModels;
|
||||||
@ -153,7 +127,7 @@ const isSecurityConfigModels = (p: any): p is SecurityConfigModels =>
|
|||||||
p.hasOwnProperty('bootstrap') &&
|
p.hasOwnProperty('bootstrap') &&
|
||||||
isBootstrapSecurityConfig(p['bootstrap']);
|
isBootstrapSecurityConfig(p['bootstrap']);
|
||||||
|
|
||||||
const isClientSecurityConfigType = (p: any): p is ClientSecurityConfigType =>
|
const isClientSecurityConfigType = (p: any): p is ClientSecurityConfig =>
|
||||||
p.hasOwnProperty('securityConfigClientMode') &&
|
p.hasOwnProperty('securityConfigClientMode') &&
|
||||||
p.hasOwnProperty('endpoint') &&
|
p.hasOwnProperty('endpoint') &&
|
||||||
p.hasOwnProperty('identity') &&
|
p.hasOwnProperty('identity') &&
|
||||||
|
|||||||
@ -888,11 +888,11 @@
|
|||||||
"lwm2m-key-required": "LwM2M Security config key is required.",
|
"lwm2m-key-required": "LwM2M Security config key is required.",
|
||||||
"lwm2m-value": "LwM2M Security config",
|
"lwm2m-value": "LwM2M Security config",
|
||||||
"lwm2m-value-required": "LwM2M Security config value is required.",
|
"lwm2m-value-required": "LwM2M Security config value is required.",
|
||||||
"lwm2m-value-json-error": "LwM2M Security config value is not json format.",
|
"lwm2m-value-format-error": "Security config value must be in LwM2M Security config format.",
|
||||||
"lwm2m-endpoint": "Client endpoint/identity",
|
"lwm2m-endpoint": "Client endpoint/identity",
|
||||||
"lwm2m-security-info": "Security Config Info",
|
"lwm2m-security-info": "Security Config Info",
|
||||||
"lwm2m-value-edit": "Edit Security config",
|
"lwm2m-value-edit": "Edit Security config",
|
||||||
"lwm2m-value-edit-tip": "Edit security config json editor",
|
"lwm2m-credentials-value-tip": "Edit security config json editor",
|
||||||
"lwm2m-security-config": {
|
"lwm2m-security-config": {
|
||||||
"identity": "Client Identity",
|
"identity": "Client Identity",
|
||||||
"client-key": "Client Key",
|
"client-key": "Client Key",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user