soajs.controller 4.2.33 → 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.
@@ -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/mt/urac.js CHANGED
@@ -21,12 +21,15 @@ function Urac(param) {
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
  }
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
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
 
@@ -126,17 +126,20 @@ module.exports = function (configuration) {
126
126
 
127
127
  return (req, res, next) => {
128
128
 
129
- let ip2ban = get(["soajs", "registry", "custom", "gateway", "value", "traffic", "ip2ban"], req);
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.33",
4
+ "version": "4.2.34",
5
5
  "author": {
6
6
  "name": "soajs team",
7
7
  "email": "team@soajs.org"
@@ -28,9 +28,9 @@
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.0",
32
- "soajs.core.modules": "5.2.12",
33
- "soajs.urac.driver": "3.2.9",
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": {
@@ -49,9 +49,9 @@
49
49
  "grunt-istanbul": "0.8.0",
50
50
  "grunt-jsdoc": "2.4.1",
51
51
  "grunt-mocha-test": "0.13.3",
52
- "mocha": "10.7.3",
53
- "nock": "13.5.6",
52
+ "mocha": "11.5.0",
53
+ "nock": "14.0.4",
54
54
  "request": "2.88.2",
55
- "sinon": "19.0.2"
55
+ "sinon": "20.0.0"
56
56
  }
57
57
  }
@@ -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
 
@@ -38,6 +38,7 @@ function logErrors(err, req, res, next) {
38
38
  return next(err);
39
39
  } else {
40
40
  req.soajs.log.error(err.message || err);
41
+ req.soajs.log.error(req.url);
41
42
  req.soajs.log.error(core.error.generate(164).message);
42
43
  }
43
44
  } else {