soajs.controller 4.2.32 → 4.2.34
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/mw/ip2ban/index.js +52 -0
- package/mw/lastSeen/index.js +16 -13
- package/mw/mt/urac.js +15 -10
- package/mw/mt/utils.js +16 -2
- package/mw/traffic/index.js +13 -10
- package/package.json +11 -10
- package/server/controller.js +6 -1
- package/utilities/utils.js +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright SOAJS All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an Apache license that can be
|
|
8
|
+
* found in the LICENSE file at the root of this repository
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param configuration
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// let customRegistry.gateway = {
|
|
21
|
+
// "traffic": {
|
|
22
|
+
// "ip2ban": [
|
|
23
|
+
// "::1"
|
|
24
|
+
// ],
|
|
25
|
+
// "model": "mongo",
|
|
26
|
+
// "throttling": {
|
|
27
|
+
// "oauth": {
|
|
28
|
+
// "publicAPIStrategy": "test",
|
|
29
|
+
// "apis": [
|
|
30
|
+
// "/token"
|
|
31
|
+
// ]
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// },
|
|
35
|
+
// };
|
|
36
|
+
module.exports = function () {
|
|
37
|
+
|
|
38
|
+
return (req, res, next) => {
|
|
39
|
+
|
|
40
|
+
let ip2ban = get(["soajs", "registry", "custom", "gateway", "value", "traffic", "ip2ban"], req);
|
|
41
|
+
let clientIP = req.getClientIP();
|
|
42
|
+
|
|
43
|
+
if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
44
|
+
req.soajs.controllerResponse({
|
|
45
|
+
'status': 403,
|
|
46
|
+
'msg': 'banned'
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return next();
|
|
51
|
+
};
|
|
52
|
+
};
|
package/mw/lastSeen/index.js
CHANGED
|
@@ -56,20 +56,23 @@ module.exports = () => {
|
|
|
56
56
|
if (error) {
|
|
57
57
|
req.soajs.log.debug("lastSeen failed for [" + item.name + "@" + item.version + " " + item.api + "]");
|
|
58
58
|
req.soajs.log.debug("lastSeen " + error.message);
|
|
59
|
-
} else
|
|
60
|
-
|
|
61
|
-
if (body.errors && body.errors && body.errors.details && body.errors.details.length > 0) {
|
|
62
|
-
body.errors.details.forEach((detail) => {
|
|
63
|
-
if (errorMsg === "") {
|
|
64
|
-
errorMsg += detail.message;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
errorMsg += " - " + detail.message;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
req.soajs.log.debug("lastSeen", errorMsg);
|
|
59
|
+
} else {
|
|
60
|
+
req.soajs.log.debug("lastSeen ", body);
|
|
72
61
|
}
|
|
62
|
+
// else if (!body.result) {
|
|
63
|
+
// let errorMsg = "";
|
|
64
|
+
// if (body.errors && body.errors && body.errors.details && body.errors.details.length > 0) {
|
|
65
|
+
// body.errors.details.forEach((detail) => {
|
|
66
|
+
// if (errorMsg === "") {
|
|
67
|
+
// errorMsg += detail.message;
|
|
68
|
+
// }
|
|
69
|
+
// else {
|
|
70
|
+
// errorMsg += " - " + detail.message;
|
|
71
|
+
// }
|
|
72
|
+
// });
|
|
73
|
+
// }
|
|
74
|
+
// req.soajs.log.debug("lastSeen", errorMsg);
|
|
75
|
+
// }
|
|
73
76
|
});
|
|
74
77
|
|
|
75
78
|
// let options = {
|
package/mw/mt/urac.js
CHANGED
|
@@ -16,17 +16,20 @@ const lib = require("./lib.js");
|
|
|
16
16
|
|
|
17
17
|
function Urac(param) {
|
|
18
18
|
let _self = this;
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
_self.soajs = param.soajs;
|
|
21
21
|
_self.userRecord = null;
|
|
22
22
|
_self.user_ACL = null;
|
|
23
23
|
_self.id = null;
|
|
24
|
+
_self.bearerTokenUser = null;
|
|
25
|
+
|
|
24
26
|
if (param.oauth && 0 === param.oauth.type) {
|
|
25
27
|
_self.userRecord = param.oauth.bearerToken;
|
|
26
28
|
} else {
|
|
27
29
|
// if type === 2
|
|
28
30
|
if (param.oauth && param.oauth.bearerToken && param.oauth.bearerToken.user) {
|
|
29
31
|
_self.id = param.oauth.bearerToken.user.id;
|
|
32
|
+
_self.bearerTokenUser = param.oauth.bearerToken.user;
|
|
30
33
|
if (param.oauth.bearerToken.user.username) {
|
|
31
34
|
_self.username = param.oauth.bearerToken.user.username;
|
|
32
35
|
}
|
|
@@ -70,7 +73,7 @@ Urac.prototype.init = function (cb) {
|
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
else if (_self.id) {
|
|
73
|
-
uracDriver.getRecord(_self.soajs, {id: _self.id.toString(), username: _self.username}, function (err, record) {
|
|
76
|
+
uracDriver.getRecord(_self.soajs, { id: _self.id.toString(), username: _self.username }, function (err, record) {
|
|
74
77
|
if (record) {
|
|
75
78
|
_self.userRecord = record;
|
|
76
79
|
_self.resolveACL(() => {
|
|
@@ -78,7 +81,9 @@ Urac.prototype.init = function (cb) {
|
|
|
78
81
|
});
|
|
79
82
|
} else {
|
|
80
83
|
if (err && err.msg) {
|
|
84
|
+
const code = err.code;
|
|
81
85
|
err = new Error(err.msg);
|
|
86
|
+
err.code = code;
|
|
82
87
|
}
|
|
83
88
|
return cb(err, null);
|
|
84
89
|
}
|
|
@@ -141,19 +146,19 @@ Urac.prototype.getProfile = function (_ALL) {
|
|
|
141
146
|
"profile": _self.userRecord.profile,
|
|
142
147
|
"tenant": _self.userRecord.tenant
|
|
143
148
|
};
|
|
144
|
-
|
|
149
|
+
|
|
145
150
|
if (_self.userRecord.socialLogin) {
|
|
146
151
|
urac.socialLogin = {
|
|
147
152
|
"strategy": _self.userRecord.socialLogin.strategy,
|
|
148
153
|
"id": _self.userRecord.socialLogin.id
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
|
-
|
|
156
|
+
|
|
152
157
|
if (_ALL) {
|
|
153
158
|
if (_self.userRecord.socialLogin) {
|
|
154
159
|
urac.socialLogin.accessToken = _self.userRecord.socialLogin.accessToken;
|
|
155
160
|
}
|
|
156
|
-
|
|
161
|
+
|
|
157
162
|
urac.config = _self.userRecord.config;
|
|
158
163
|
urac.groupsConfig = _self.userRecord.groupsConfig;
|
|
159
164
|
}
|
|
@@ -162,7 +167,7 @@ Urac.prototype.getProfile = function (_ALL) {
|
|
|
162
167
|
urac = {
|
|
163
168
|
"_id": _self.userRecord._id,
|
|
164
169
|
"username": _self.userRecord.userId,
|
|
165
|
-
"tenant": {"id": _self.userRecord.tId}
|
|
170
|
+
"tenant": { "id": _self.userRecord.tId }
|
|
166
171
|
};
|
|
167
172
|
}
|
|
168
173
|
else if (_self.userRecord) {
|
|
@@ -182,7 +187,7 @@ Urac.prototype.getProfile = function (_ALL) {
|
|
|
182
187
|
*/
|
|
183
188
|
Urac.prototype.getAcl = function () {
|
|
184
189
|
let _self = this;
|
|
185
|
-
|
|
190
|
+
|
|
186
191
|
if (_self.user_ACL && _self.user_ACL.acl) {
|
|
187
192
|
return _self.user_ACL.acl;
|
|
188
193
|
} else {
|
|
@@ -195,7 +200,7 @@ Urac.prototype.getAcl = function () {
|
|
|
195
200
|
*/
|
|
196
201
|
Urac.prototype.getAclAllEnv = function () {
|
|
197
202
|
let _self = this;
|
|
198
|
-
|
|
203
|
+
|
|
199
204
|
if (_self.user_ACL && _self.user_ACL.acl_all_env) {
|
|
200
205
|
return _self.user_ACL.acl_all_env;
|
|
201
206
|
} else {
|
|
@@ -214,13 +219,13 @@ Urac.prototype.getConfig = function () {
|
|
|
214
219
|
return null;
|
|
215
220
|
}
|
|
216
221
|
let config = null;
|
|
217
|
-
|
|
222
|
+
|
|
218
223
|
if (_self.userRecord.config && _self.userRecord.config.keys) {
|
|
219
224
|
if (_self.userRecord.config.keys[key] && _self.userRecord.config.keys[key].config) {
|
|
220
225
|
config = _self.userRecord.config.keys[key].config;
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
|
-
|
|
228
|
+
|
|
224
229
|
return config;
|
|
225
230
|
};
|
|
226
231
|
|
package/mw/mt/utils.js
CHANGED
|
@@ -588,11 +588,25 @@ let utils = {
|
|
|
588
588
|
}
|
|
589
589
|
let callURACDriver = function (roaming) {
|
|
590
590
|
obj.req.soajs.uracDriver = new UracDriver({ "soajs": obj.req.soajs, "oauth": obj.req.oauth });
|
|
591
|
-
obj.req.soajs.uracDriver.init((error) => {
|
|
591
|
+
obj.req.soajs.uracDriver.init((error, record) => {
|
|
592
592
|
if (error && !roaming) {
|
|
593
|
-
obj.req.soajs.log.error(error.message);
|
|
593
|
+
obj.req.soajs.log.error(error.message, error.code);
|
|
594
594
|
return cb(146);
|
|
595
595
|
}
|
|
596
|
+
if (obj.keyObj.config && obj.keyObj.config.gateway && obj.keyObj.config.gateway.validateTokenAccount) {
|
|
597
|
+
if (obj.req.soajs.uracDriver.bearerTokenUser && record) {
|
|
598
|
+
if (obj.keyObj.config.gateway.validateTokenAccount.email && record.email) {
|
|
599
|
+
if (record.email !== obj.req.soajs.uracDriver.bearerTokenUser.email) {
|
|
600
|
+
return cb(146);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (obj.keyObj.config.gateway.validateTokenAccount.phone && record.phone) {
|
|
604
|
+
if (record.phone !== obj.req.soajs.uracDriver.bearerTokenUser.phone) {
|
|
605
|
+
return cb(146);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
596
610
|
let userServiceConf = obj.req.soajs.uracDriver.getConfig();
|
|
597
611
|
userServiceConf = userServiceConf || {};
|
|
598
612
|
|
package/mw/traffic/index.js
CHANGED
|
@@ -126,17 +126,20 @@ module.exports = function (configuration) {
|
|
|
126
126
|
|
|
127
127
|
return (req, res, next) => {
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
// NOTE: moved to ip2ban MW
|
|
130
|
+
//
|
|
131
|
+
// let ip2ban = get(["soajs", "registry", "custom", "gateway", "value", "traffic", "ip2ban"], req);
|
|
132
|
+
// let clientIP = req.getClientIP();
|
|
133
|
+
|
|
134
|
+
// if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
135
|
+
// req.soajs.controllerResponse({
|
|
136
|
+
// 'status': 403,
|
|
137
|
+
// 'msg': 'banned'
|
|
138
|
+
// });
|
|
139
|
+
// return;
|
|
140
|
+
// }
|
|
130
141
|
let clientIP = req.getClientIP();
|
|
131
|
-
|
|
132
|
-
if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
133
|
-
req.soajs.controllerResponse({
|
|
134
|
-
'status': 403,
|
|
135
|
-
'msg': 'banned'
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
142
|
+
|
|
140
143
|
if (req && req.soajs && req.soajs.registry && req.soajs.registry.serviceConfig && req.soajs.registry.serviceConfig.throttling && req.soajs.tenant && req.soajs.controller) {
|
|
141
144
|
|
|
142
145
|
let serviceName = req.soajs.controller.serviceParams.name;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.controller",
|
|
3
3
|
"description": "soajs multi tenant API gateway",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.34",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "soajs team",
|
|
7
7
|
"email": "team@soajs.org"
|
|
@@ -28,15 +28,16 @@
|
|
|
28
28
|
"netmask": "2.0.2",
|
|
29
29
|
"oauth2-server": "2.4.1",
|
|
30
30
|
"path-to-regexp": "6.2.2",
|
|
31
|
-
"soajs.core.libs": "1.2.
|
|
32
|
-
"soajs.core.modules": "5.2.
|
|
33
|
-
"soajs.urac.driver": "3.2.
|
|
31
|
+
"soajs.core.libs": "1.2.1",
|
|
32
|
+
"soajs.core.modules": "5.2.15",
|
|
33
|
+
"soajs.urac.driver": "3.2.12",
|
|
34
34
|
"useragent": "2.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/core": "7.
|
|
38
|
-
"@babel/plugin-transform-runtime": "7.
|
|
39
|
-
"@babel/preset-env": "7.
|
|
37
|
+
"@babel/core": "7.27.1",
|
|
38
|
+
"@babel/plugin-transform-runtime": "7.27.1",
|
|
39
|
+
"@babel/preset-env": "7.27.2",
|
|
40
|
+
"@babel/runtime": "7.27.1",
|
|
40
41
|
"express": "4.21.1",
|
|
41
42
|
"grunt": "1.6.1",
|
|
42
43
|
"grunt-babel": "8.0.0",
|
|
@@ -48,9 +49,9 @@
|
|
|
48
49
|
"grunt-istanbul": "0.8.0",
|
|
49
50
|
"grunt-jsdoc": "2.4.1",
|
|
50
51
|
"grunt-mocha-test": "0.13.3",
|
|
51
|
-
"mocha": "
|
|
52
|
-
"nock": "
|
|
52
|
+
"mocha": "11.5.0",
|
|
53
|
+
"nock": "14.0.4",
|
|
53
54
|
"request": "2.88.2",
|
|
54
|
-
"sinon": "
|
|
55
|
+
"sinon": "20.0.0"
|
|
55
56
|
}
|
|
56
57
|
}
|
package/server/controller.js
CHANGED
|
@@ -38,6 +38,7 @@ const gotoService_mw = require("../mw/gotoService/index");
|
|
|
38
38
|
const mt_mw = require("../mw/mt/index");
|
|
39
39
|
const traffic_mw = require("../mw/traffic/index");
|
|
40
40
|
const lastSeen_mw = require("../mw/lastSeen/index");
|
|
41
|
+
const ip2ban_mw = require("../mw/ip2ban/index");
|
|
41
42
|
|
|
42
43
|
const utils = require("../utilities/utils");
|
|
43
44
|
|
|
@@ -87,6 +88,10 @@ Controller.prototype.init = function (callback) {
|
|
|
87
88
|
app.use(cors_mw());
|
|
88
89
|
app.use(favicon_mw());
|
|
89
90
|
app.use(response_mw({ "controllerResponse": true }));
|
|
91
|
+
|
|
92
|
+
app.use(enhancer_mw());
|
|
93
|
+
|
|
94
|
+
app.use(ip2ban_mw());
|
|
90
95
|
app.use(maintenanceMode_mw()); //NOTE: this is for global maintenance mode
|
|
91
96
|
|
|
92
97
|
log.info("Loading Provision ...");
|
|
@@ -128,7 +133,7 @@ Controller.prototype.init = function (callback) {
|
|
|
128
133
|
}));
|
|
129
134
|
log.info("AwarenessEnv middleware initialization done.");
|
|
130
135
|
|
|
131
|
-
app.use(enhancer_mw());
|
|
136
|
+
// app.use(enhancer_mw());
|
|
132
137
|
|
|
133
138
|
app.use(url_mw({ "core": core }));
|
|
134
139
|
|