Browse Source

Lwm2m: front add validator json for security config device

pull/4133/head
nickAS21 6 years ago
parent
commit
d2469420ad
  1. 13
      ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts
  2. 17
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts
  4. 38
      ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts

13
ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts

@ -41,7 +41,7 @@ import {
DeviceCredentialsDialogLwm2mData,
END_POINT,
getDefaultSecurityConfig,
JSON_ALL_CONFIG
JSON_ALL_CONFIG, SecurityConfigModels, validateSecurityConfig
} from '@home/pages/device/lwm2m/security-config.models';
import {TranslateService} from '@ngx-translate/core';
import {MatDialog} from '@angular/material/dialog';
@ -285,15 +285,6 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
}
private jsonValidator(control: FormControl) {
try {
JSON.parse(control.value);
return null
} catch (e) {
return {
jsonError: {
parsedJson: "error"
}
}
}
return validateSecurityConfig(control.value) ? null: {jsonError: {parsedJson: "error"}};
}
}

17
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

@ -395,21 +395,4 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}
});
}
isPathInJson(path: string): boolean {
let isPath = this.findPathInJson(path, ATTRIBUTE);
if (!isPath) {
isPath = this.findPathInJson(path, TELEMETRY);
}
return !!isPath;
}
private findPathInJson = (path: string, side: string): string => {
if (this.configurationValue.observeAttr) {
if (this.configurationValue.observeAttr[side]) {
return this.configurationValue.bootstrap[side].find(
pathJs => pathJs === path);
}
}
}
}

2
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts

@ -27,7 +27,7 @@ export const DEFAULT_ID_SERVER = 123;
export const DEFAULT_ID_BOOTSTRAP = 111;
export const DEFAULT_HOST_NAME = 'localhost';
export const DEFAULT_PORT_SERVER_NO_SEC = 5685;
export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5686;
export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5687;
export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1;
export const DEFAULT_LIFE_TIME = 300;
export const DEFAULT_MIN_PERIOD = 1;

38
ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts

@ -20,7 +20,6 @@ export const DEFAULT_END_POINT = 'default_client_lwm2m_end_point_no_sec';
export const BOOTSTRAP_SERVERS = 'servers';
export const BOOTSTRAP_SERVER = 'bootstrapServer';
export const LWM2M_SERVER = 'lwm2mServer';
export const JSON_OBSERVE = 'jsonObserve';
export const LEN_MAX_PSK = 64;
export const LEN_MAX_PRIVATE_KEY = 134;
export const LEN_MAX_PUBLIC_KEY_RPK = 182;
@ -148,4 +147,41 @@ export function getDefaultSecurityConfig(): SecurityConfigModels {
return securityConfigModels;
}
const isSecurityConfigModels = (p: any): p is SecurityConfigModels =>
p.hasOwnProperty('client') &&
isClientSecurityConfigType(p['client']) &&
p.hasOwnProperty('bootstrap') &&
isBootstrapSecurityConfig(p['bootstrap']);
const isClientSecurityConfigType = (p: any): p is ClientSecurityConfigType =>
p.hasOwnProperty('securityConfigClientMode') &&
p.hasOwnProperty('endpoint') &&
p.hasOwnProperty('identity') &&
p.hasOwnProperty('key') &&
p.hasOwnProperty('x509');
const isBootstrapSecurityConfig = (p: any): p is BootstrapSecurityConfig =>
p.hasOwnProperty('bootstrapServer') &&
isServerSecurityConfig(p['bootstrapServer']) &&
p.hasOwnProperty('lwm2mServer') &&
isServerSecurityConfig(p['lwm2mServer']);
const isServerSecurityConfig = (p: any): p is ServerSecurityConfig =>
p.hasOwnProperty('securityMode') &&
p.hasOwnProperty('clientPublicKeyOrId') &&
p.hasOwnProperty('clientSecretKey');
export function validateSecurityConfig(config: string): boolean {
try {
const securityConfig= JSON.parse(config);
if (isSecurityConfigModels(securityConfig)) {
return true;
} else {
return false;
}
} catch (e) {
return false;
}
}

Loading…
Cancel
Save