soajs.controller 4.2.5 → 4.2.6
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/gotoService/redirectToService.js +39 -26
- package/mw/mt/urac.js +3 -0
- package/package.json +1 -1
|
@@ -13,11 +13,11 @@ const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
|
13
13
|
const request = require('request');
|
|
14
14
|
|
|
15
15
|
module.exports = (configuration) => {
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
let core = configuration.core;
|
|
18
18
|
let isRequestAuthorized = require("./lib/isRequestAuthorized.js");
|
|
19
19
|
let preRedirect = require("./lib/preRedirect.js");
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
*
|
|
23
23
|
* @param req
|
|
@@ -36,7 +36,7 @@ module.exports = (configuration) => {
|
|
|
36
36
|
if (obj.config.authorization) {
|
|
37
37
|
isRequestAuthorized(req, core, requestOptions);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
let restServiceParams = req.soajs.controller.serviceParams;
|
|
41
41
|
try {
|
|
42
42
|
let log_monitor = (doc) => {
|
|
@@ -46,7 +46,7 @@ module.exports = (configuration) => {
|
|
|
46
46
|
port = "4050";
|
|
47
47
|
}
|
|
48
48
|
let api = "/monitor/item";
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
req.soajs.awareness.getHost(soamonitor, function (host) {
|
|
51
51
|
if (!host) {
|
|
52
52
|
req.soajs.log.error('Unable to find any healthy host for service ' + soamonitor);
|
|
@@ -64,7 +64,7 @@ module.exports = (configuration) => {
|
|
|
64
64
|
"json": true
|
|
65
65
|
};
|
|
66
66
|
if (req.headers && req.headers.soajsinjectobj) {
|
|
67
|
-
requestOptions.headers = {"soajsinjectobj": req.headers.soajsinjectobj};
|
|
67
|
+
requestOptions.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
|
|
68
68
|
}
|
|
69
69
|
request.post(requestOptions, (error, response, body) => {
|
|
70
70
|
if (error) {
|
|
@@ -115,10 +115,10 @@ module.exports = (configuration) => {
|
|
|
115
115
|
if (monitor && !monitor_service_blacklist && monitor.req_query) {
|
|
116
116
|
monitoObj.query = req.query;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
// Trigger request
|
|
120
120
|
req.soajs.controller.redirectedRequest = request(requestOptions);
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
// Handle error event for both with monitor and without monitor
|
|
123
123
|
req.soajs.controller.redirectedRequest.on('error', (err) => {
|
|
124
124
|
req.soajs.log.error(err.message + ' with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
@@ -137,16 +137,20 @@ module.exports = (configuration) => {
|
|
|
137
137
|
//Handle body
|
|
138
138
|
if (req.method === 'POST' || req.method === 'PUT' || req.method === 'PATCH' || req.method === 'DELETE') {
|
|
139
139
|
if (monitor && !monitor_service_blacklist && monitor.req_body) {
|
|
140
|
+
let allowedContentType = false;
|
|
140
141
|
let isStream = false;
|
|
141
142
|
req.on("data", (chunk) => {
|
|
142
143
|
req.soajs.controller.redirectedRequest.write(chunk);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (
|
|
144
|
+
let resContentType = req.headers['content-type'];
|
|
145
|
+
if (resContentType) {
|
|
146
|
+
if (!allowedContentType) {
|
|
147
|
+
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
148
|
+
}
|
|
149
|
+
if (!isStream) {
|
|
146
150
|
isStream = resContentType.match(/stream/i);
|
|
147
151
|
}
|
|
148
152
|
}
|
|
149
|
-
if (!isStream) {
|
|
153
|
+
if (!isStream && allowedContentType) {
|
|
150
154
|
if (!monitoObj.body) {
|
|
151
155
|
monitoObj.time.req_body_start = new Date().getTime();
|
|
152
156
|
monitoObj.body = chunk;
|
|
@@ -154,18 +158,23 @@ module.exports = (configuration) => {
|
|
|
154
158
|
monitoObj.body += chunk;
|
|
155
159
|
}
|
|
156
160
|
} else {
|
|
157
|
-
monitoObj.body = "stream";
|
|
161
|
+
monitoObj.body = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
|
|
158
162
|
}
|
|
159
163
|
});
|
|
160
164
|
req.on("end", () => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
165
|
+
let resContentType = req.headers['content-length'];
|
|
166
|
+
if (resContentType) {
|
|
167
|
+
if (!allowedContentType) {
|
|
168
|
+
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
169
|
+
}
|
|
170
|
+
if (!isStream) {
|
|
164
171
|
isStream = resContentType.match(/stream/i);
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
if (!isStream) {
|
|
168
175
|
req.soajs.controller.redirectedRequest.end();
|
|
176
|
+
}
|
|
177
|
+
if (!isStream && allowedContentType) {
|
|
169
178
|
monitoObj.time.req_body_end = new Date().getTime();
|
|
170
179
|
}
|
|
171
180
|
});
|
|
@@ -175,6 +184,7 @@ module.exports = (configuration) => {
|
|
|
175
184
|
}
|
|
176
185
|
// Handle response
|
|
177
186
|
if (monitor && !monitor_service_blacklist && monitor.req_response) {
|
|
187
|
+
let allowedContentType = false;
|
|
178
188
|
let isStream = false;
|
|
179
189
|
req.soajs.controller.redirectedRequest.on("response", (response) => {
|
|
180
190
|
if (!res.headersSent) {
|
|
@@ -184,34 +194,37 @@ module.exports = (configuration) => {
|
|
|
184
194
|
});
|
|
185
195
|
req.soajs.controller.redirectedRequest.on("data", (chunk) => {
|
|
186
196
|
res.write(chunk);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
197
|
+
let resContentType = res.getHeader('content-type');
|
|
198
|
+
if (resContentType) {
|
|
199
|
+
if (!allowedContentType) {
|
|
200
|
+
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
201
|
+
}
|
|
202
|
+
if (!isStream) {
|
|
190
203
|
isStream = resContentType.match(/stream/i);
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
|
-
if (!isStream) {
|
|
206
|
+
if (!isStream && allowedContentType) {
|
|
194
207
|
if (!monitoObj.response) {
|
|
195
208
|
monitoObj.response = chunk;
|
|
196
209
|
} else {
|
|
197
210
|
monitoObj.response += chunk;
|
|
198
211
|
}
|
|
199
212
|
} else {
|
|
200
|
-
monitoObj.response = "stream";
|
|
213
|
+
monitoObj.response = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
|
|
201
214
|
}
|
|
202
215
|
});
|
|
203
216
|
req.soajs.controller.redirectedRequest.on("end", () => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
217
|
+
let resContentType = res.getHeader('content-type');
|
|
218
|
+
if (resContentType) {
|
|
219
|
+
if (!isStream) {
|
|
207
220
|
isStream = resContentType.match(/stream/i);
|
|
208
221
|
}
|
|
209
222
|
}
|
|
210
223
|
if (!isStream) {
|
|
211
224
|
res.end();
|
|
212
|
-
monitoObj.time.res_end = new Date().getTime();
|
|
213
|
-
log_monitor(monitoObj);
|
|
214
225
|
}
|
|
226
|
+
monitoObj.time.res_end = new Date().getTime();
|
|
227
|
+
log_monitor(monitoObj);
|
|
215
228
|
});
|
|
216
229
|
req.soajs.controller.redirectedRequest.on("abort", () => {
|
|
217
230
|
if (!req.soajs.controller.monitorEndingReq) {
|
|
@@ -223,7 +236,7 @@ module.exports = (configuration) => {
|
|
|
223
236
|
} else {
|
|
224
237
|
req.soajs.controller.redirectedRequest.pipe(res);
|
|
225
238
|
}
|
|
226
|
-
|
|
239
|
+
|
|
227
240
|
} catch (e) {
|
|
228
241
|
req.soajs.log.error(e.message + ' @catch with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
229
242
|
if (req.soajs.controller.redirectedRequest) {
|
package/mw/mt/urac.js
CHANGED
|
@@ -39,6 +39,9 @@ function Urac(param) {
|
|
|
39
39
|
if (!_self.soajs.tenant.roaming && (param.oauth.bearerToken.clientId === _self.soajs.tenant.id)) {
|
|
40
40
|
_self.userRecord = param.oauth.bearerToken.user;
|
|
41
41
|
}
|
|
42
|
+
if (_self.soajs.tenant.roaming) {
|
|
43
|
+
_self.userRecord = param.oauth.bearerToken.user;
|
|
44
|
+
}
|
|
42
45
|
} else {
|
|
43
46
|
if (_self.soajs.tenant.roaming) {
|
|
44
47
|
_self.userRecord = param.oauth.bearerToken.user;
|