not-node 5.0.22 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +1 -1
- package/bin/not-deploy.js +52 -0
- package/index.js +21 -19
- package/package.json +1 -1
- package/src/app.js +61 -58
- package/src/auth/abstract.js +17 -19
- package/src/auth/const.js +8 -12
- package/src/auth/fields.js +143 -124
- package/src/auth/index.js +14 -14
- package/src/auth/roles.js +64 -63
- package/src/auth/routes.js +89 -54
- package/src/auth/rules.js +63 -63
- package/src/auth/session.js +60 -62
- package/src/bootstrap/form.js +13 -13
- package/src/bootstrap/logic.js +45 -41
- package/src/bootstrap/model.js +14 -17
- package/src/bootstrap/route.js +132 -53
- package/src/common.js +86 -79
- package/src/core/fields/ID.js +6 -6
- package/src/core/fields/__closed.js +3 -3
- package/src/core/fields/__latest.js +3 -3
- package/src/core/fields/__version.js +3 -3
- package/src/core/fields/__versions.js +3 -3
- package/src/core/fields/_id.js +6 -6
- package/src/core/fields/active.js +9 -9
- package/src/core/fields/codeName.js +9 -9
- package/src/core/fields/createdAt.js +17 -17
- package/src/core/fields/default.js +9 -9
- package/src/core/fields/description.js +11 -11
- package/src/core/fields/email.js +9 -9
- package/src/core/fields/enabled.js +9 -9
- package/src/core/fields/expiredAt.js +16 -16
- package/src/core/fields/height.js +11 -11
- package/src/core/fields/ip.js +10 -10
- package/src/core/fields/objectId.js +10 -10
- package/src/core/fields/owner.js +13 -13
- package/src/core/fields/ownerModel.js +11 -11
- package/src/core/fields/price.js +11 -11
- package/src/core/fields/requiredObject.js +10 -10
- package/src/core/fields/session.js +10 -10
- package/src/core/fields/size.js +11 -11
- package/src/core/fields/telephone.js +9 -9
- package/src/core/fields/title.js +15 -15
- package/src/core/fields/updatedAt.js +17 -17
- package/src/core/fields/userId.js +11 -12
- package/src/core/fields/uuid.js +11 -11
- package/src/core/fields/validators/email.js +6 -4
- package/src/core/fields/validators/owner.js +6 -4
- package/src/core/fields/width.js +11 -11
- package/src/domain.js +435 -431
- package/src/env.js +23 -23
- package/src/error.js +20 -23
- package/src/exceptions/db.js +23 -0
- package/src/exceptions/http.js +43 -0
- package/src/fields/index.js +106 -111
- package/src/form/fabric.js +19 -24
- package/src/form/form.js +195 -186
- package/src/form/index.js +2 -2
- package/src/generic/index.js +2 -0
- package/src/generic/logic.js +595 -0
- package/src/generic/route.js +76 -0
- package/src/init/additional.js +7 -7
- package/src/init/app.js +75 -68
- package/src/init/bodyparser.js +14 -14
- package/src/init/compression.js +6 -7
- package/src/init/core.js +12 -12
- package/src/init/cors.js +22 -24
- package/src/init/db/index.js +41 -43
- package/src/init/db/ioredis.js +28 -20
- package/src/init/db/mongoose.js +42 -32
- package/src/init/db/redis.js +59 -48
- package/src/init/env.js +44 -36
- package/src/init/express.js +18 -21
- package/src/init/fileupload.js +8 -10
- package/src/init/http.js +65 -47
- package/src/init/index.js +141 -148
- package/src/init/informer.js +7 -9
- package/src/init/methodoverride.js +4 -6
- package/src/init/middleware.js +23 -26
- package/src/init/modules.js +4 -4
- package/src/init/monitoring.js +8 -8
- package/src/init/rateLimiter.js +53 -45
- package/src/init/routes.js +67 -69
- package/src/init/security.js +37 -33
- package/src/init/sequence.js +111 -107
- package/src/init/sequence.standart.js +54 -56
- package/src/init/sessions/index.js +21 -21
- package/src/init/sessions/mongoose.js +49 -36
- package/src/init/sessions/redis.js +28 -27
- package/src/init/static.js +53 -40
- package/src/init/template.js +17 -17
- package/src/lib.js +230 -200
- package/src/manifest/batchRunner.js +26 -25
- package/src/manifest/initializator/forms.js +24 -24
- package/src/manifest/initializator/index.js +8 -10
- package/src/manifest/initializator/manifests.js +45 -42
- package/src/manifest/initializator/models.js +37 -34
- package/src/manifest/manifest.filter.js +130 -97
- package/src/manifest/manifest.js +103 -77
- package/src/manifest/module.js +350 -360
- package/src/manifest/registrator/fields.js +90 -85
- package/src/manifest/registrator/forms.js +47 -47
- package/src/manifest/registrator/index.js +14 -16
- package/src/manifest/registrator/locales.js +17 -16
- package/src/manifest/registrator/logics.js +66 -64
- package/src/manifest/registrator/models.js +64 -62
- package/src/manifest/registrator/routes.js +171 -132
- package/src/manifest/registrator/routes.ws.js +109 -103
- package/src/manifest/route.js +216 -161
- package/src/model/buildValidator.js +53 -42
- package/src/model/default.js +304 -286
- package/src/model/enrich.js +69 -61
- package/src/model/increment.js +124 -137
- package/src/model/proto.js +179 -148
- package/src/model/routine.js +85 -76
- package/src/model/utils.js +33 -0
- package/src/model/versioning.js +148 -130
- package/src/obsolete.js +12 -8
- package/src/parser.js +29 -22
- package/src/repos.js +29 -31
- package/src/rollup.js +75 -65
- package/src/shell.helpers.js +28 -28
- package/static.js +31 -0
- package/src/generic/router.js +0 -16
- package/src/manifest/module.models.js +0 -0
- package/src/manifest/module.status.js +0 -0
package/src/auth/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/** @module Auth */
|
|
2
2
|
|
|
3
|
-
const CONST = require(
|
|
4
|
-
const ABSTRACT = require(
|
|
5
|
-
const FIELDS = require(
|
|
6
|
-
const ROLES = require(
|
|
7
|
-
const RULES = require(
|
|
8
|
-
const ROUTES = require(
|
|
9
|
-
const SESSION = require(
|
|
3
|
+
const CONST = require("./const");
|
|
4
|
+
const ABSTRACT = require("./abstract");
|
|
5
|
+
const FIELDS = require("./fields");
|
|
6
|
+
const ROLES = require("./roles");
|
|
7
|
+
const RULES = require("./rules");
|
|
8
|
+
const ROUTES = require("./routes");
|
|
9
|
+
const SESSION = require("./session");
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
...CONST,
|
|
13
|
+
...ABSTRACT,
|
|
14
|
+
...SESSION,
|
|
15
|
+
...ROLES,
|
|
16
|
+
...RULES,
|
|
17
|
+
...ROUTES,
|
|
18
|
+
...FIELDS,
|
|
19
19
|
};
|
package/src/auth/roles.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
const ABSTRACT = require(
|
|
1
|
+
const ABSTRACT = require("./abstract");
|
|
2
2
|
|
|
3
|
-
function compareRolesArrayAgainstArray(userRoles, actionRoles, strict){
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
function compareRolesArrayAgainstArray(userRoles, actionRoles, strict) {
|
|
4
|
+
if (strict) {
|
|
5
|
+
return (
|
|
6
|
+
ABSTRACT.intersect_safe(userRoles, actionRoles).length ===
|
|
7
|
+
actionRoles.length
|
|
8
|
+
);
|
|
9
|
+
} else {
|
|
10
|
+
return ABSTRACT.intersect_safe(userRoles, actionRoles).length > 0;
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -16,45 +19,44 @@ function compareRolesArrayAgainstArray(userRoles, actionRoles, strict){
|
|
|
16
19
|
* @return {boolean} if user roles comply to action roles
|
|
17
20
|
**/
|
|
18
21
|
function compareRoles(userRoles, actionRoles, strict = true) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}else{
|
|
34
|
-
return actionRoles.indexOf(userRoles) > -1;
|
|
35
|
-
}
|
|
22
|
+
//console.log('compare roles', userRoles, actionRoles);
|
|
23
|
+
//user have many roles
|
|
24
|
+
if (userRoles && Array.isArray(userRoles)) {
|
|
25
|
+
//action can be accessed by various roles
|
|
26
|
+
if (actionRoles && Array.isArray(actionRoles)) {
|
|
27
|
+
//if we have similar elements in those two arrays - grant access
|
|
28
|
+
return compareRolesArrayAgainstArray(
|
|
29
|
+
userRoles,
|
|
30
|
+
actionRoles,
|
|
31
|
+
strict
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
return userRoles.indexOf(actionRoles) > -1;
|
|
35
|
+
}
|
|
36
36
|
} else {
|
|
37
|
-
|
|
37
|
+
if (Array.isArray(actionRoles)) {
|
|
38
|
+
if (strict) {
|
|
39
|
+
return false;
|
|
40
|
+
} else {
|
|
41
|
+
return actionRoles.indexOf(userRoles) > -1;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
return userRoles === actionRoles;
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
|
-
}
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!Array.isArray(roleSet)) {
|
|
50
|
-
roleSet = [roleSet];
|
|
49
|
+
function sanitizeAndValidateRoleSet(roleSet, name) {
|
|
50
|
+
if (!Array.isArray(roleSet) && !ABSTRACT.isObjectString(roleSet)) {
|
|
51
|
+
throw new Error(`${name} role set is not valid`);
|
|
52
|
+
} else {
|
|
53
|
+
if (!Array.isArray(roleSet)) {
|
|
54
|
+
roleSet = [roleSet];
|
|
55
|
+
}
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
return roleSet;
|
|
57
|
+
return roleSet;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
60
|
/**
|
|
59
61
|
* Check to sets of roles against each other
|
|
60
62
|
* to define if base is strictly higher than second
|
|
@@ -64,33 +66,32 @@ function sanitizeAndValidateRoleSet(roleSet, name){
|
|
|
64
66
|
* @return {boolean} true if base > against
|
|
65
67
|
*/
|
|
66
68
|
function checkSupremacy(base, against, roles) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
base = sanitizeAndValidateRoleSet(base, "Base");
|
|
70
|
+
against = sanitizeAndValidateRoleSet(against, "Against");
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let baseIndex = -1;
|
|
75
|
-
let againstIndex = -1;
|
|
76
|
-
roles.forEach((role, index) => {
|
|
77
|
-
if ((!ABSTRACT.isObjectString(role))) {
|
|
78
|
-
throw new Error('Supremacy order element is not a string');
|
|
79
|
-
}
|
|
80
|
-
if (baseIndex === -1 && base.indexOf(role) > -1) {
|
|
81
|
-
baseIndex = index;
|
|
72
|
+
if (!Array.isArray(roles)) {
|
|
73
|
+
throw new Error("No roles supremacy order!");
|
|
82
74
|
}
|
|
83
|
-
if (againstIndex === -1 && against.indexOf(role) > -1) {
|
|
84
|
-
againstIndex = index;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return ((baseIndex > -1) && ((baseIndex < againstIndex) || againstIndex === -1));
|
|
88
|
-
}
|
|
89
75
|
|
|
76
|
+
let baseIndex = -1;
|
|
77
|
+
let againstIndex = -1;
|
|
78
|
+
roles.forEach((role, index) => {
|
|
79
|
+
if (!ABSTRACT.isObjectString(role)) {
|
|
80
|
+
throw new Error("Supremacy order element is not a string");
|
|
81
|
+
}
|
|
82
|
+
if (baseIndex === -1 && base.indexOf(role) > -1) {
|
|
83
|
+
baseIndex = index;
|
|
84
|
+
}
|
|
85
|
+
if (againstIndex === -1 && against.indexOf(role) > -1) {
|
|
86
|
+
againstIndex = index;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return baseIndex > -1 && (baseIndex < againstIndex || againstIndex === -1);
|
|
90
|
+
}
|
|
90
91
|
|
|
91
92
|
module.exports = {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
checkSupremacy,
|
|
94
|
+
sanitizeAndValidateRoleSet,
|
|
95
|
+
compareRoles,
|
|
96
|
+
compareRolesArrayAgainstArray,
|
|
96
97
|
};
|
package/src/auth/routes.js
CHANGED
|
@@ -1,61 +1,77 @@
|
|
|
1
|
-
const log = require(
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const log = require("not-log")(module, "Auth");
|
|
2
|
+
const {
|
|
3
|
+
HttpExceptionUnauthorized,
|
|
4
|
+
HttpExceptionForbidden,
|
|
5
|
+
} = require("../exceptions/http");
|
|
6
|
+
const SESSION = require("./session");
|
|
7
|
+
const ROLES = require("./roles");
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Get request ip
|
|
10
11
|
* @param {object} req Express Request
|
|
11
12
|
**/
|
|
12
13
|
function getIP(req) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (req) {
|
|
15
|
+
return (
|
|
16
|
+
(req.headers && req.headers["x-forwarded-for"]) ||
|
|
17
|
+
(req.connection && req.connection.remoteAddress) ||
|
|
18
|
+
(req.socket && req.socket.remoteAddress) ||
|
|
19
|
+
(req.connection &&
|
|
20
|
+
req.connection.socket &&
|
|
21
|
+
req.connection.socket.remoteAddress)
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
|
|
24
28
|
/**
|
|
25
29
|
* Collects various authentification and authorization data from request object
|
|
26
30
|
* @params {object} req ExpressRequest
|
|
27
31
|
* @return {object} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
28
32
|
*/
|
|
29
33
|
function extractAuthData(req) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
return {
|
|
35
|
+
root: SESSION.isRoot(req),
|
|
36
|
+
auth: SESSION.isUser(req),
|
|
37
|
+
role: SESSION.getRole(req),
|
|
38
|
+
uid: SESSION.getUserId(req),
|
|
39
|
+
sid: SESSION.getSessionId(req),
|
|
40
|
+
ip: getIP(req),
|
|
41
|
+
};
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
42
44
|
/**
|
|
43
45
|
* Returns Express middleware witch check role against one presented in request
|
|
44
46
|
* @param {string|array} role action roles
|
|
45
47
|
* @return {function} express middleware
|
|
46
48
|
**/
|
|
47
49
|
function checkRoleBuilder(role) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
return (req, res, next) => {
|
|
51
|
+
let userRole = SESSION.getRole(req);
|
|
52
|
+
if (!SESSION.isUser(req)) {
|
|
53
|
+
return next(
|
|
54
|
+
new HttpExceptionUnauthorized({
|
|
55
|
+
params: { ip: getIP(req) },
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (ROLES.compareRoles(userRole, role)) {
|
|
60
|
+
return next();
|
|
61
|
+
} else {
|
|
62
|
+
return next(
|
|
63
|
+
new HttpExceptionForbidden({
|
|
64
|
+
params: {
|
|
65
|
+
ip: getIP(req),
|
|
66
|
+
user: req.session.user,
|
|
67
|
+
role: req.session.role,
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
56
73
|
}
|
|
57
74
|
|
|
58
|
-
|
|
59
75
|
/**
|
|
60
76
|
* Checks if user is authenticated, by searching req.session.user
|
|
61
77
|
* If auth pass next, else throw error
|
|
@@ -64,14 +80,17 @@ function checkRoleBuilder(role) {
|
|
|
64
80
|
* @param {function} next callback
|
|
65
81
|
**/
|
|
66
82
|
function checkUser(req, res, next) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
if (SESSION.isUser(req)) {
|
|
84
|
+
return next();
|
|
85
|
+
} else {
|
|
86
|
+
return next(
|
|
87
|
+
new HttpExceptionUnauthorized({
|
|
88
|
+
params: { ip: getIP(req) },
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}
|
|
72
92
|
}
|
|
73
93
|
|
|
74
|
-
|
|
75
94
|
/**
|
|
76
95
|
* Checks if user is authenticated, by searching req.session.user
|
|
77
96
|
* If auth pass next, else throw error
|
|
@@ -80,24 +99,40 @@ function checkUser(req, res, next) {
|
|
|
80
99
|
* @param {function} next callback
|
|
81
100
|
**/
|
|
82
101
|
function checkAdmin(req, res, next) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
log.error("checkAdmin is obsolete, use new version as checkRoot");
|
|
103
|
+
log.error(req.originalUrl);
|
|
104
|
+
return checkRoot(req, res, next);
|
|
86
105
|
}
|
|
87
106
|
|
|
88
107
|
function checkRoot(req, res, next) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
if (SESSION.isRoot(req)) {
|
|
109
|
+
return next();
|
|
110
|
+
} else {
|
|
111
|
+
if (SESSION.isUser(req)) {
|
|
112
|
+
return next(
|
|
113
|
+
new HttpExceptionForbidden({
|
|
114
|
+
params: {
|
|
115
|
+
ip: getIP(req),
|
|
116
|
+
user: req.session.user,
|
|
117
|
+
role: req.session.role,
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
return next(
|
|
123
|
+
new HttpExceptionUnauthorized({
|
|
124
|
+
params: { ip: getIP(req) },
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
94
129
|
}
|
|
95
130
|
|
|
96
131
|
module.exports = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
checkRoot,
|
|
133
|
+
checkAdmin,
|
|
134
|
+
checkUser,
|
|
135
|
+
checkRoleBuilder,
|
|
136
|
+
extractAuthData,
|
|
137
|
+
getIP,
|
|
103
138
|
};
|
package/src/auth/rules.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
const ROLES = require(
|
|
2
|
-
const postWarning = require(
|
|
1
|
+
const ROLES = require("./roles");
|
|
2
|
+
const postWarning = require("../obsolete");
|
|
3
3
|
|
|
4
|
-
function ruleHasRootDirective(rule){
|
|
5
|
-
|
|
4
|
+
function ruleHasRootDirective(rule) {
|
|
5
|
+
return (
|
|
6
|
+
(Object.prototype.hasOwnProperty.call(rule, "admin") && rule.admin) ||
|
|
7
|
+
(Object.prototype.hasOwnProperty.call(rule, "root") && rule.root)
|
|
8
|
+
);
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
11
|
+
function compareWithRoot(rule, root) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(rule, "admin")) {
|
|
13
|
+
return rule.admin && root;
|
|
14
|
+
} else {
|
|
15
|
+
return rule.root && root;
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
function compareRuleRoles(rule, role, auth){
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
function compareRuleRoles(rule, role, auth) {
|
|
20
|
+
if (ROLES.compareRoles(rule.role, role)) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(rule, "auth")) {
|
|
22
|
+
if (rule.auth && auth) {
|
|
23
|
+
return true;
|
|
24
|
+
} else {
|
|
25
|
+
return !rule.auth && !auth;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
25
30
|
} else {
|
|
26
|
-
|
|
31
|
+
return false;
|
|
27
32
|
}
|
|
28
|
-
} else {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function roleRequireAuthState(requiredAuth, userAuth){
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
function roleRequireAuthState(requiredAuth, userAuth) {
|
|
36
|
+
if (requiredAuth && userAuth) {
|
|
37
|
+
return true;
|
|
38
|
+
} else {
|
|
39
|
+
return !requiredAuth && !userAuth;
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
function compareAuthStatus(rule, auth){
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
function compareAuthStatus(rule, auth) {
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(rule, "auth")) {
|
|
45
|
+
return roleRequireAuthState(rule.auth, auth);
|
|
46
|
+
} else if (Object.prototype.hasOwnProperty.call(rule, "user")) {
|
|
47
|
+
return roleRequireAuthState(rule.user, auth);
|
|
48
|
+
} else {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
52
53
|
/**
|
|
53
54
|
* Check rule against presented credentials
|
|
54
55
|
* @param {object} rule action rule
|
|
@@ -61,34 +62,33 @@ function compareAuthStatus(rule, auth){
|
|
|
61
62
|
* @return {boolean} pass or not
|
|
62
63
|
*/
|
|
63
64
|
function checkCredentials(rule, auth, role, root) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} else {
|
|
68
|
-
//posting message about obsolete options keys if found
|
|
69
|
-
postWarning(rule);
|
|
70
|
-
//start comparing from top tier flags
|
|
71
|
-
//if we have root/admin(obsolete) field field in rule compare only it
|
|
72
|
-
if (ruleHasRootDirective(rule)) {
|
|
73
|
-
return compareWithRoot(rule, root);
|
|
65
|
+
//no rule - no access
|
|
66
|
+
if (typeof rule === "undefined" || rule === null) {
|
|
67
|
+
return false;
|
|
74
68
|
} else {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
//posting message about obsolete options keys if found
|
|
70
|
+
postWarning(rule);
|
|
71
|
+
//start comparing from top tier flags
|
|
72
|
+
//if we have root/admin(obsolete) field field in rule compare only it
|
|
73
|
+
if (ruleHasRootDirective(rule)) {
|
|
74
|
+
return compareWithRoot(rule, root);
|
|
75
|
+
} else {
|
|
76
|
+
//if we have roles in rule, then using role based aproach
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(rule, "role")) {
|
|
78
|
+
return compareRuleRoles(rule, role, auth);
|
|
79
|
+
} else {
|
|
80
|
+
//if no then just
|
|
81
|
+
return compareAuthStatus(rule, auth);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
|
-
}
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
|
|
87
87
|
module.exports = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
checkCredentials,
|
|
89
|
+
compareAuthStatus,
|
|
90
|
+
roleRequireAuthState,
|
|
91
|
+
compareRuleRoles,
|
|
92
|
+
compareWithRoot,
|
|
93
|
+
ruleHasRootDirective,
|
|
94
94
|
};
|