Comparing version 0.2.1 to 0.3.0
118
index.js
'use strict'; | ||
const js2xml = require('js2xmlparser'); | ||
const os = require('os'); | ||
const libxml = require('libxmljs'); | ||
const fs = require('fs'); | ||
var js2xml = require('js2xmlparser'); | ||
var os = require('os'); | ||
var libxml = require('libxmljs'); | ||
var fs = require('fs'); | ||
var validate = true; | ||
// Event Outcome Indicator | ||
exports.OUTCOME_SUCCESS = 0; | ||
exports.OUTCOME_MINOR_FAILURE = 4; | ||
exports.OUTCOME_SERIOUS_FAILURE = 8; | ||
exports.OUTCOME_MAJOR_FAILURE = 12; | ||
exports.disableValidation = () => validate = false; | ||
exports.enableValidation = () => validate = true; | ||
// Network Access Point Type Code | ||
exports.EVENT_ACTION_CREATE = 'C'; | ||
exports.EVENT_ACTION_READ = 'R'; | ||
exports.EVENT_ACTION_UPDATE = 'U'; | ||
exports.EVENT_ACTION_DELETE = 'D'; | ||
exports.EVENT_ACTION_EXECUTE = 'E'; | ||
// Network Access Point Type Code | ||
exports.NET_AP_TYPE_DNS = 1; | ||
exports.NET_AP_TYPE_IP = 2; | ||
exports.NET_AP_TYPE_TEL = 3; | ||
// Audit Source Type Code | ||
exports.AUDIT_SRC_TYPE_UI = 1; | ||
exports.AUDIT_SRC_TYPE_DATA_AQUISITION = 2; | ||
exports.AUDIT_SRC_TYPE_WEB_SERVER = 3; | ||
exports.AUDIT_SRC_TYPE_APP_SERVER = 4; | ||
exports.AUDIT_SRC_TYPE_DB_SERVER = 5; | ||
exports.AUDIT_SRC_TYPE_SECURITY_SERVER = 6; | ||
exports.AUDIT_SRC_TYPE_NET_COMP = 7; | ||
exports.AUDIT_SRC_TYPE_OS = 8; | ||
exports.AUDIT_SRC_TYPE_EXTERN = 9; | ||
// Participant Object Type Code | ||
exports.OBJ_TYPE_PERSON = 1; | ||
exports.OBJ_TYPE_SYS_OBJ = 2; | ||
exports.OBJ_TYPE_ORG = 3; | ||
exports.OBJ_TYPE_OTHER = 4; | ||
// Participant Object ID Type Code | ||
exports.OBJ_ID_TYPE_MRN = 1; | ||
exports.OBJ_ID_TYPE_PAT_NUM = 2; | ||
exports.OBJ_ID_TYPE_ENCOUNTER_NUM = 3; | ||
exports.OBJ_ID_TYPE_ENROLLEE_NUM = 4; | ||
exports.OBJ_ID_TYPE_SSN = 5; | ||
exports.OBJ_ID_TYPE_ACC_NUM = 6; | ||
exports.OBJ_ID_TYPE_GUARANTOR_NUM = 7; | ||
exports.OBJ_ID_TYPE_REPORT_NAME = 8; | ||
exports.OBJ_ID_TYPE_REPORT_NUM = 9; | ||
exports.OBJ_ID_TYPE_SEARCH_CRIT = 10; | ||
exports.OBJ_ID_TYPE_USER_ID = 11; | ||
exports.OBJ_ID_TYPE_URI = 12; | ||
function Code(code, displayName, codeSystemName) { | ||
@@ -139,7 +183,7 @@ this['@'] = { | ||
function validateAudit(auditXml) { | ||
var xsd = fs.readFileSync(`${__dirname}/rfc-3881.xsd`).toString(); | ||
var xsd = fs.readFileSync(__dirname + '/rfc-3881.xsd').toString(); | ||
var xsdDoc = libxml.parseXml(xsd); | ||
var xml = libxml.parseXml(auditXml); | ||
if (!xml.validate(xsdDoc)) { | ||
throw new Error(`XML audit not valid according to XSD: \n ${xml.validationErrors}`); | ||
throw new Error('XML audit not valid according to XSD:\n' + xml.validationErrors); | ||
} | ||
@@ -150,3 +194,3 @@ } | ||
function wrapInSyslog(msg) { | ||
return `<85>1 ${new Date().toISOString()} ${os.hostname()} atna-audit.js ${process.pid} IHE+RFC-3881 - ${msg}`; | ||
return '<85>1 ' + new Date().toISOString() + ' ' + os.hostname() + ' atna-audit.js ' + process.pid + ' IHE+RFC-3881 - ' + msg; | ||
} | ||
@@ -156,22 +200,17 @@ exports.wrapInSyslog = wrapInSyslog; | ||
exports.userLoginAudit = function(outcome, sysname, hostname, username, userRole, userRoleCode) { | ||
let eventID = new Code(110114, 'UserAuthenticated', 'DCM'); | ||
let typeCode = new Code(110122, 'Login', 'DCM'); | ||
let eIdent = new EventIdentification('E', new Date(), outcome, eventID, typeCode); | ||
var eventID = new Code(110114, 'UserAuthenticated', 'DCM'); | ||
var typeCode = new Code(110122, 'Login', 'DCM'); | ||
var eIdent = new EventIdentification(exports.EVENT_ACTION_EXECUTE, new Date(), outcome, eventID, typeCode); | ||
let sysRoleCode = new Code(110150, 'Application', 'DCM'); | ||
let sysParticipant = new ActiveParticipant(sysname, '', true, hostname, 1, [sysRoleCode]); | ||
var sysRoleCode = new Code(110150, 'Application', 'DCM'); | ||
var sysParticipant = new ActiveParticipant(sysname, '', true, hostname, exports.NET_AP_TYPE_DNS, [sysRoleCode]); | ||
let userRoleCodeDef = new Code(userRole, userRole, userRoleCode); | ||
let userParticipant = new ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
var userRoleCodeDef = new Code(userRole, userRole, userRoleCode); | ||
var userParticipant = new ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
let sourceTypeCode = new Code(1, '', ''); | ||
let sourceIdent = new AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
var sourceTypeCode = new Code(exports.AUDIT_SRC_TYPE_UI, '', ''); | ||
var sourceIdent = new AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
let audit = new AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
let xml = audit.toXML(); | ||
if (validate) { | ||
validateAudit(xml); | ||
} | ||
return xml; | ||
var audit = new AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
return audit.toXML(); | ||
}; | ||
@@ -184,4 +223,4 @@ | ||
let eventID = new Code(110100, 'Application Activity', 'DCM'); | ||
let typeCode; | ||
var eventID = new Code(110100, 'Application Activity', 'DCM'); | ||
var typeCode; | ||
if (isStart) { | ||
@@ -192,20 +231,15 @@ typeCode = new Code(110120, 'Application Start', 'DCM'); | ||
} | ||
let eIdent = new EventIdentification('E', new Date(), 0, eventID, typeCode); | ||
var eIdent = new EventIdentification(exports.EVENT_ACTION_EXECUTE, new Date(), exports.OUTCOME_SUCCESS, eventID, typeCode); | ||
let sysRoleCode = new Code(110150, 'Application', 'DCM'); | ||
let sysParticipant = new ActiveParticipant(sysname, '', true, hostname, 1, [sysRoleCode]); | ||
var sysRoleCode = new Code(110150, 'Application', 'DCM'); | ||
var sysParticipant = new ActiveParticipant(sysname, '', true, hostname, exports.NET_AP_TYPE_DNS, [sysRoleCode]); | ||
let userRoleCodeDef = new Code(110151, 'Application Launcher', 'DCM'); | ||
let userParticipant = new ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
var userRoleCodeDef = new Code(110151, 'Application Launcher', 'DCM'); | ||
var userParticipant = new ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
let sourceTypeCode = new Code(3, '', ''); | ||
let sourceIdent = new AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
var sourceTypeCode = new Code(exports.AUDIT_SRC_TYPE_WEB_SERVER, '', ''); | ||
var sourceIdent = new AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
let audit = new AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
let xml = audit.toXML(); | ||
if (validate) { | ||
validateAudit(xml); | ||
} | ||
return xml; | ||
var audit = new AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
return audit.toXML(); | ||
}; |
{ | ||
"name": "atna-audit", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Assists in the creation of ATNA audit trail messages for IHE profiles.", | ||
@@ -12,6 +12,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"js2xmlparser": "^1.0.0", | ||
"libxmljs": "^0.15.0" | ||
"js2xmlparser": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"libxmljs": "^0.15.0", | ||
"eslint": "^1.7.3" | ||
@@ -18,0 +18,0 @@ }, |
@@ -16,4 +16,4 @@ [](https://travis-ci.org/jembi/atna-audit) | ||
```js | ||
let audit = atna.userLoginAudit(0, 'openhim', 'x.x.x.x', 'testUser', 'testRole', '123'); | ||
let syslog = atna.wrapInSyslog(audit); | ||
var audit = atna.userLoginAudit(atna.OUTCOME_SUCCESS, 'openhim', 'x.x.x.x', 'testUser', 'testRole', '123'); | ||
var syslog = atna.wrapInSyslog(audit); | ||
``` | ||
@@ -24,21 +24,13 @@ | ||
```js | ||
let eventID = new atna.Code(110114, 'UserAuthenticated', 'DCM'); | ||
let typeCode = new atna.Code(110122, 'Login', 'DCM'); | ||
let eIdent = new atna.EventIdentification('E', new Date(), 0, eventID, typeCode); | ||
let sysRoleCode = new atna.Code(110150, 'Application', 'DCM'); | ||
let sysParticipant = new atna.ActiveParticipant(sysname, '', true, sysIp, 2, [sysRoleCode]); | ||
let userRoleCodeDef = new atna.Code(userRole, userRole, userRoleCode); | ||
let userParticipant = new atna.ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
let sourceTypeCode = new atna.Code(1, '', ''); | ||
let sourceIdent = new atna.AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
let audit = new atna.AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
let xml = audit.toXML(); | ||
var eventID = new atna.Code(110114, 'UserAuthenticated', 'DCM'); | ||
var typeCode = new atna.Code(110122, 'Login', 'DCM'); | ||
var eIdent = new atna.EventIdentification(atna.EVENT_ACTION_EXECUTE, new Date(), atna.OUTCOME_SUCCESS, eventID, typeCode); | ||
var sysRoleCode = new atna.Code(110150, 'Application', 'DCM'); | ||
var sysParticipant = new atna.ActiveParticipant(sysname, '', true, sysIp, atna.NET_AP_TYPE_IP, [sysRoleCode]); | ||
var userRoleCodeDef = new atna.Code(userRole, userRole, userRoleCode); | ||
var userParticipant = new atna.ActiveParticipant(username, '', true, null, null, [userRoleCodeDef]); | ||
var sourceTypeCode = new atna.Code(atna.AUDIT_SRC_TYPE_UI, '', ''); | ||
var sourceIdent = new atna.AuditSourceIdentification(null, sysname, sourceTypeCode); | ||
var audit = new atna.AuditMessage(eIdent, [sysParticipant, userParticipant], null, [sourceIdent]); | ||
var xml = audit.toXML(); | ||
``` | ||
Validate your audit XML against the rfc-3881 xsd like this: | ||
```js | ||
atna.validateAudit(xml); | ||
``` | ||
This function will throw an exception if a problem is found. |
'use strict'; | ||
const atna = require('./index'); | ||
var atna = require('./index'); | ||
// I'm validate manually so the test fail here | ||
atna.disableValidation(); | ||
let syslog = atna.wrapInSyslog('test'); | ||
var syslog = atna.wrapInSyslog('test'); | ||
console.log(syslog); | ||
let audit = atna.userLoginAudit(0, 'openhim', 'openhim.org', 'testUser', 'testRole', '123'); | ||
var audit = atna.userLoginAudit(atna.OUTCOME_SUCCESS, 'openhim', 'openhim.org', 'testUser', 'testRole', '123'); | ||
atna.validateAudit(audit); | ||
@@ -13,0 +10,0 @@ console.log(audit); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31904
1
223
2
35
- Removedlibxmljs@^0.15.0
- Removedbindings@1.2.1(transitive)
- Removedlibxmljs@0.15.0(transitive)
- Removednan@2.0.7(transitive)