cloudcms-server 3.3.1-beta.9 → 4.0.0-beta.1
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/LICENSE +1 -1
- package/README.md +1 -1
- package/broadcast/broadcast.js +6 -3
- package/broadcast/providers/redis.js +24 -49
- package/clients/nrp.js +117 -0
- package/clients/redis.js +64 -0
- package/d1/index.js +629 -0
- package/d1/index.js.works +203 -0
- package/d1/package.json +86 -0
- package/d1/package.json.works +14 -0
- package/duster/helpers/sample/nyt.js +2 -1
- package/framework/controllers.js +4 -4
- package/index.js +21 -14
- package/insight/insight.js +1 -1
- package/launchpad/index.js +203 -11
- package/launchpad/launchers/cluster.js +103 -110
- package/launchpad/launchers/redis.js +70 -0
- package/launchpad/launchers/single.js +36 -22
- package/locks/locks.js +63 -9
- package/locks/providers/cluster.js +3 -1
- package/locks/providers/memory.js +10 -7
- package/locks/providers/redis.js +62 -82
- package/middleware/admin/admin.js +3 -3
- package/middleware/authentication/adapters/session.js +11 -8
- package/middleware/authentication/authentication.js +28 -16
- package/middleware/authentication/authenticators/default.js +5 -2
- package/middleware/authentication/authenticators/session.js +5 -2
- package/middleware/authentication/providers/saml.js +1 -1
- package/middleware/authorization/authorization.js +11 -8
- package/middleware/awareness/awareness.js +55 -31
- package/middleware/awareness/plugins/editorial.js +4 -4
- package/middleware/awareness/providers/abstract-async.js +107 -84
- package/middleware/awareness/providers/abstract.js +1 -1
- package/middleware/awareness/providers/memory.js +0 -14
- package/middleware/awareness/providers/redis.js +186 -279
- package/middleware/cache/cache.js +4 -2
- package/middleware/cache/providers/redis.js +127 -89
- package/middleware/cache/providers/shared-memory.js +3 -3
- package/middleware/cloudcms/cloudcms.js +22 -16
- package/middleware/form/form.js +3 -3
- package/middleware/modules/modules.js +6 -3
- package/middleware/proxy/proxy.js +8 -21
- package/middleware/stores/stores.js +2 -2
- package/middleware/virtual-config/virtual-config.js +11 -8
- package/middleware/wcm/wcm.js +4 -4
- package/notifications/notifications.js +2 -2
- package/package.json +29 -25
- package/server/index.js +504 -415
- package/server/standalone.js +9 -0
- package/temp/clusterlock/index.js +3 -3
- package/temp/clusterlock/package.json +1 -1
- package/temp/passport-saml/LICENSE +23 -0
- package/temp/passport-saml/README.md +406 -0
- package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
- package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
- package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/index.js +6 -0
- package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
- package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
- package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
- package/temp/passport-saml/lib/node-saml/types.js +8 -0
- package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/utility.js +19 -0
- package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
- package/temp/passport-saml/lib/node-saml/xml.js +140 -0
- package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
- package/temp/passport-saml/lib/passport-saml/index.js +11 -0
- package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
- package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
- package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
- package/temp/passport-saml/lib/passport-saml/types.js +11 -0
- package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
- package/temp/passport-saml/package.json +96 -0
- package/util/auth.js +6 -6
- package/util/cloudcms.js +85 -88
- package/util/proxy-factory.js +159 -268
- package/util/redis.js +113 -0
- package/util/renditions.js +12 -6
- package/util/request.js +4 -4
- package/util/util.js +16 -2
- package/launchpad/launchers/sticky-cluster.js +0 -43
- package/temp/memored/.jshintrc +0 -4
- package/temp/memored/README.md +0 -240
- package/temp/memored/demo/demo1.js +0 -37
- package/temp/memored/demo/demo2.js +0 -32
- package/temp/memored/gulpfile.js +0 -8
- package/temp/memored/index.js +0 -343
- package/temp/memored/package.json +0 -54
- package/temp/memored/spec/memored.spec.js +0 -265
- package/web/cms/ice.js +0 -109
- package/web/cms/preview.js +0 -106
package/util/proxy-factory.js
CHANGED
|
@@ -2,8 +2,6 @@ var http = require("http");
|
|
|
2
2
|
var https = require("https");
|
|
3
3
|
var path = require("path");
|
|
4
4
|
|
|
5
|
-
var httpProxy = require("http-proxy");
|
|
6
|
-
|
|
7
5
|
var auth = require("./auth");
|
|
8
6
|
var util = require("./util");
|
|
9
7
|
|
|
@@ -17,7 +15,8 @@ var exports = module.exports;
|
|
|
17
15
|
|
|
18
16
|
var _LOCK = function(lockIdentifiers, workFunction)
|
|
19
17
|
{
|
|
20
|
-
|
|
18
|
+
var name = lockIdentifiers.join("_");
|
|
19
|
+
process.locks.lock(name, workFunction);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
var NAMED_PROXY_HANDLERS_CACHE = new LRUCache({
|
|
@@ -36,9 +35,17 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
|
|
|
36
35
|
{
|
|
37
36
|
return callback(null, _cachedHandler);
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
// take out a thread lock
|
|
41
|
-
_LOCK(["acquireProxyHandler", name], function(releaseLockFn) {
|
|
40
|
+
_LOCK(["acquireProxyHandler", name], function(err, releaseLockFn) {
|
|
41
|
+
|
|
42
|
+
if (err)
|
|
43
|
+
{
|
|
44
|
+
console.log("Failed to acquire proxy handler: " + name + ", err: ", err);
|
|
45
|
+
|
|
46
|
+
// failed to acquire lock
|
|
47
|
+
return callback(err);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
50
|
// second check to make sure another thread didn't create the handler in the meantime
|
|
44
51
|
_cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
|
|
@@ -49,8 +56,9 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
|
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
// create the proxy handler and cache it into LRU cache
|
|
59
|
+
//console.log("Acquiring proxy handler: " + name + ", for target: " + proxyTarget + " and prefix: " + pathPrefix);
|
|
52
60
|
_cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
|
|
53
|
-
|
|
61
|
+
|
|
54
62
|
// store back into LRU cache
|
|
55
63
|
NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
|
|
56
64
|
|
|
@@ -59,144 +67,75 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
|
|
|
59
67
|
});
|
|
60
68
|
};
|
|
61
69
|
|
|
62
|
-
var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
63
|
-
{
|
|
64
|
-
////////////////////////////////////////////////////////////////////////////
|
|
65
|
-
//
|
|
66
|
-
// HTTP/HTTPS Proxy Server to Cloud CMS
|
|
67
|
-
// Facilitates Cross-Domain communication between Browser and Cloud Server
|
|
68
|
-
// This must appear at the top of the app.js file (ahead of config) for things to work
|
|
69
|
-
//
|
|
70
|
-
////////////////////////////////////////////////////////////////////////////
|
|
71
|
-
|
|
72
|
-
// NOTE: changeOrigin must be true because of the way that we set host to host:port
|
|
73
|
-
// in http-proxy's common.js line 102, the host is only properly set up if changeOrigin is set to true
|
|
74
|
-
// this sets the "host" header and it has to match what is set at the network/transport level in a way
|
|
75
|
-
// (inner workings of Node http request)
|
|
76
|
-
//
|
|
77
|
-
var proxyConfig = {
|
|
78
|
-
"target": proxyTarget,
|
|
79
|
-
"agent": http.globalAgent,
|
|
80
|
-
"xfwd": false,
|
|
81
|
-
"proxyTimeout": process.defaultHttpTimeoutMs,
|
|
82
|
-
"changeOrigin": true
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// use https?
|
|
86
|
-
if (util.isHttps(proxyTarget))
|
|
87
|
-
{
|
|
88
|
-
// parse the target to get host
|
|
89
|
-
var proxyHost = urlTool.parse(proxyTarget).host;
|
|
90
|
-
|
|
91
|
-
proxyConfig = {
|
|
92
|
-
"target": proxyTarget,
|
|
93
|
-
"agent": https.globalAgent,
|
|
94
|
-
"headers": {
|
|
95
|
-
"host": proxyHost
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
70
|
|
|
100
|
-
// create proxy server instance
|
|
101
|
-
var proxyServer = new httpProxy.createProxyServer(proxyConfig);
|
|
102
71
|
|
|
103
|
-
// error handling
|
|
104
|
-
proxyServer.on("error", function(err, req, res) {
|
|
105
|
-
console.log("A proxy error was caught: " + err + ", json: " + JSON.stringify(err));
|
|
106
72
|
|
|
107
|
-
|
|
108
|
-
|
|
73
|
+
var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
74
|
+
{
|
|
75
|
+
const proxy = require("http2-proxy");
|
|
76
|
+
const finalhandler = require('finalhandler')
|
|
77
|
+
|
|
78
|
+
const defaultWebHandler = function(err, req, res) {
|
|
79
|
+
if (err)
|
|
109
80
|
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
81
|
+
console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
|
|
82
|
+
try { res.status(500); } catch (e) { }
|
|
83
|
+
try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
|
|
113
84
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
|
|
86
|
+
finalhandler(req, res)(err);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// const defaultWsHandler = function(err, req, socket, head) {
|
|
90
|
+
// if (err) {
|
|
91
|
+
// console.error('proxy error (ws)', err);
|
|
92
|
+
// socket.destroy();
|
|
93
|
+
// }
|
|
94
|
+
// };
|
|
95
|
+
|
|
96
|
+
//console.log("Proxy Target: " + proxyTarget);
|
|
97
|
+
|
|
98
|
+
var hostname = urlTool.parse(proxyTarget).hostname;
|
|
99
|
+
var port = urlTool.parse(proxyTarget).port;
|
|
100
|
+
var protocol = urlTool.parse(proxyTarget).protocol;
|
|
101
|
+
|
|
102
|
+
// web
|
|
103
|
+
var webConfig = {};
|
|
104
|
+
webConfig.hostname = hostname;
|
|
105
|
+
webConfig.port = port;
|
|
106
|
+
webConfig.protocol = protocol;
|
|
107
|
+
//webConfig.path = null;
|
|
108
|
+
webConfig.timeout = 120000;
|
|
109
|
+
webConfig.proxyTimeout = 120000;
|
|
110
|
+
webConfig.proxyName = "Cloud CMS UI Proxy";
|
|
111
|
+
webConfig.onReq = function(req, options) {
|
|
112
|
+
|
|
113
|
+
if (!options.headers) {
|
|
114
|
+
options.headers = {};
|
|
119
115
|
}
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
|
|
124
|
-
// and if we hear it, we automatically invalidate the SSO chain so that the next request
|
|
125
|
-
// will continue to work
|
|
126
|
-
proxyServer.on("proxyRes", function (proxyRes, req, res) {
|
|
127
|
-
|
|
128
|
-
if (req.gitana_user)
|
|
129
|
-
{
|
|
130
|
-
var chunks = [];
|
|
131
|
-
// triggers on data receive
|
|
132
|
-
proxyRes.on('data', function(chunk) {
|
|
133
|
-
// add received chunk to chunks array
|
|
134
|
-
chunks.push(chunk);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
proxyRes.on("end", function () {
|
|
138
|
-
|
|
139
|
-
if (proxyRes.statusCode === 401)
|
|
140
|
-
{
|
|
141
|
-
var text = "" + Buffer.concat(chunks);
|
|
142
|
-
if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
|
|
143
|
-
{
|
|
144
|
-
var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
145
|
-
|
|
146
|
-
_LOCK([identifier], function(releaseLockFn) {
|
|
147
|
-
|
|
148
|
-
var cleanup = function (full)
|
|
149
|
-
{
|
|
150
|
-
delete Gitana.APPS[req.identity_properties.token];
|
|
151
|
-
delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
|
|
116
|
+
var headers = options.headers;
|
|
152
117
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// null out the access token
|
|
159
|
-
// this will force the refresh token to be used to get a new one on the next request
|
|
160
|
-
req.gitana_user.getDriver().http.refresh(function (err) {
|
|
161
|
-
|
|
162
|
-
if (err) {
|
|
163
|
-
cleanup(true);
|
|
164
|
-
req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
165
|
-
releaseLockFn();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
170
|
-
cleanup(true);
|
|
171
|
-
req.log("Refreshed token for gitana user: " + req.identity_properties.token);
|
|
172
|
-
releaseLockFn();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
});
|
|
118
|
+
if (options.path && options.path.startsWith("/proxy")) {
|
|
119
|
+
options.path = options.path.substring(6);
|
|
180
120
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
121
|
+
|
|
122
|
+
if (pathPrefix) {
|
|
123
|
+
options.path = path.join(pathPrefix, options.path);
|
|
124
|
+
}
|
|
125
|
+
|
|
185
126
|
// used to auto-assign the client header for /oauth/token requests
|
|
186
127
|
oauth2.autoProxy(req);
|
|
187
|
-
|
|
128
|
+
|
|
188
129
|
// copy domain host into "x-cloudcms-domainhost"
|
|
189
|
-
if (req.domainHost)
|
|
190
|
-
|
|
191
|
-
req.headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
130
|
+
if (req.domainHost) {
|
|
131
|
+
headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
192
132
|
}
|
|
193
|
-
|
|
133
|
+
|
|
194
134
|
// copy virtual host into "x-cloudcms-virtualhost"
|
|
195
|
-
if (req.virtualHost)
|
|
196
|
-
|
|
197
|
-
req.headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
135
|
+
if (req.virtualHost) {
|
|
136
|
+
headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
198
137
|
}
|
|
199
|
-
|
|
138
|
+
|
|
200
139
|
// copy deployment descriptor info
|
|
201
140
|
if (req.descriptor)
|
|
202
141
|
{
|
|
@@ -204,29 +143,29 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
204
143
|
{
|
|
205
144
|
if (req.descriptor.tenant.id)
|
|
206
145
|
{
|
|
207
|
-
|
|
146
|
+
headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
208
147
|
}
|
|
209
|
-
|
|
148
|
+
|
|
210
149
|
if (req.descriptor.tenant.title)
|
|
211
150
|
{
|
|
212
|
-
|
|
151
|
+
headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
213
152
|
}
|
|
214
153
|
}
|
|
215
|
-
|
|
154
|
+
|
|
216
155
|
if (req.descriptor.application)
|
|
217
156
|
{
|
|
218
157
|
if (req.descriptor.application.id)
|
|
219
158
|
{
|
|
220
|
-
|
|
159
|
+
headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
221
160
|
}
|
|
222
|
-
|
|
161
|
+
|
|
223
162
|
if (req.descriptor.application.title)
|
|
224
163
|
{
|
|
225
|
-
|
|
164
|
+
headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
226
165
|
}
|
|
227
166
|
}
|
|
228
167
|
}
|
|
229
|
-
|
|
168
|
+
|
|
230
169
|
// set optional "x-cloudcms-origin" header
|
|
231
170
|
var cloudcmsOrigin = null;
|
|
232
171
|
if (req.virtualHost)
|
|
@@ -235,155 +174,107 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
235
174
|
}
|
|
236
175
|
if (cloudcmsOrigin)
|
|
237
176
|
{
|
|
238
|
-
|
|
177
|
+
headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
239
178
|
}
|
|
240
|
-
|
|
179
|
+
|
|
241
180
|
// set x-cloudcms-server-version header
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
// our algorithm here is pretty weak but suffices for the moment.
|
|
252
|
-
// if the req.headers["x-forwarded-host"] first entry is in the req.headers["referer"] then we consider
|
|
253
|
-
// things to have been CNAME forwarded
|
|
254
|
-
// and so we write cookies back to the req.headers["x-forwarded-host"] first entry domain
|
|
255
|
-
/*
|
|
256
|
-
var xForwardedHost = req.headers["x-forwarded-host"];
|
|
257
|
-
if (xForwardedHost)
|
|
181
|
+
headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
182
|
+
|
|
183
|
+
// keep alive
|
|
184
|
+
//req.headers["connection"] = "keep-alive";
|
|
185
|
+
|
|
186
|
+
// if the incoming request didn't have an "Authorization" header
|
|
187
|
+
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
188
|
+
if (!req.headers["authorization"])
|
|
258
189
|
{
|
|
259
|
-
|
|
260
|
-
if (xForwardedHost.length > 0)
|
|
190
|
+
if (req.gitana_user)
|
|
261
191
|
{
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
var referer = req.headers["referer"];
|
|
265
|
-
if (referer && referer.indexOf("://" + cnameCandidate) > -1)
|
|
266
|
-
{
|
|
267
|
-
req.log("Detected CNAME: " + cnameCandidate);
|
|
268
|
-
|
|
269
|
-
proxyHostHeader = cnameCandidate;
|
|
270
|
-
}
|
|
192
|
+
headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
271
193
|
}
|
|
272
|
-
|
|
273
|
-
*/
|
|
274
|
-
|
|
275
|
-
// we fall back to using http-node-proxy's xfwd support
|
|
276
|
-
// thus, spoof header here on request so that "x-forwarded-host" is set properly
|
|
277
|
-
//req.headers["host"] = proxyHostHeader;
|
|
278
|
-
|
|
279
|
-
// keep alive
|
|
280
|
-
req.headers["connection"] = "keep-alive";
|
|
281
|
-
|
|
282
|
-
// allow forced cookie domains
|
|
283
|
-
var forcedCookieDomain = req.headers["cloudcmscookiedomain"];
|
|
284
|
-
if (!forcedCookieDomain)
|
|
285
|
-
{
|
|
286
|
-
if (process.env.CLOUDCMS_FORCE_COOKIE_DOMAIN)
|
|
194
|
+
else if (req.gitana_proxy_access_token)
|
|
287
195
|
{
|
|
288
|
-
|
|
196
|
+
headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
289
197
|
}
|
|
290
198
|
}
|
|
291
|
-
|
|
199
|
+
};
|
|
200
|
+
webConfig.onRes = function(req, res, proxyRes) {
|
|
201
|
+
|
|
202
|
+
if (req.gitana_user)
|
|
292
203
|
{
|
|
293
|
-
|
|
294
|
-
|
|
204
|
+
var chunks = [];
|
|
205
|
+
|
|
206
|
+
// triggers on data receive
|
|
207
|
+
proxyRes.on('data', function(chunk) {
|
|
208
|
+
// add received chunk to chunks array
|
|
209
|
+
chunks.push(chunk);
|
|
210
|
+
});
|
|
295
211
|
|
|
296
|
-
|
|
297
|
-
{
|
|
298
|
-
// replace the domain with the host
|
|
299
|
-
var i = value.toLowerCase().indexOf("domain=");
|
|
300
|
-
if (i > -1)
|
|
301
|
-
{
|
|
302
|
-
var j = value.indexOf(";", i);
|
|
303
|
-
if (j === -1)
|
|
304
|
-
{
|
|
305
|
-
value = value.substring(0, i);
|
|
306
|
-
}
|
|
307
|
-
else
|
|
308
|
-
{
|
|
309
|
-
value = value.substring(0, i) + value.substring(j);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
212
|
+
proxyRes.on("end", function () {
|
|
312
213
|
|
|
313
|
-
|
|
314
|
-
if (!util.isSecure(req))
|
|
315
|
-
{
|
|
316
|
-
var i = value.toLowerCase().indexOf("; secure");
|
|
317
|
-
if (i > -1)
|
|
214
|
+
if (proxyRes.statusCode === 401)
|
|
318
215
|
{
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
216
|
+
var text = "" + Buffer.concat(chunks);
|
|
217
|
+
if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
|
|
218
|
+
{
|
|
219
|
+
var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
322
220
|
|
|
323
|
-
|
|
324
|
-
if (util.isSecure(req))
|
|
325
|
-
{
|
|
326
|
-
var i = value.toLowerCase().indexOf("; secure");
|
|
327
|
-
var j = value.toLowerCase().indexOf(";secure");
|
|
328
|
-
if (i === -1 && j === -1)
|
|
329
|
-
{
|
|
330
|
-
value += ";secure";
|
|
331
|
-
}
|
|
332
|
-
}
|
|
221
|
+
_LOCK([identifier], function(err, releaseLockFn) {
|
|
333
222
|
|
|
334
|
-
|
|
335
|
-
|
|
223
|
+
if (err)
|
|
224
|
+
{
|
|
225
|
+
// failed to acquire lock
|
|
226
|
+
console.log("FAILED TO ACQUIRE LOCK", err);
|
|
227
|
+
req.log("FAILED TO ACQUIRE LOCK", err);
|
|
228
|
+
try { releaseLockFn(); } catch (e) { }
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
336
231
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
res.setHeader = function(key, value)
|
|
342
|
-
{
|
|
343
|
-
var _key = key.toLowerCase();
|
|
232
|
+
var cleanup = function (full)
|
|
233
|
+
{
|
|
234
|
+
delete Gitana.APPS[req.identity_properties.token];
|
|
235
|
+
delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
|
|
344
236
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
else
|
|
350
|
-
{
|
|
351
|
-
if (_key === "set-cookie")
|
|
352
|
-
{
|
|
353
|
-
for (var x in value)
|
|
354
|
-
{
|
|
355
|
-
value[x] = updateSetCookieValue(value[x]);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
237
|
+
if (full) {
|
|
238
|
+
auth.removeUserCacheEntry(identifier);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
358
241
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
_setHeader.call(this, key, value);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
};
|
|
242
|
+
// null out the access token
|
|
243
|
+
// this will force the refresh token to be used to get a new one on the next request
|
|
244
|
+
req.gitana_user.getDriver().http.refresh(function (err) {
|
|
366
245
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
{
|
|
373
|
-
req.headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
374
|
-
}
|
|
375
|
-
else if (req.gitana_proxy_access_token)
|
|
376
|
-
{
|
|
377
|
-
req.headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
246
|
+
if (err) {
|
|
247
|
+
cleanup(true);
|
|
248
|
+
req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
249
|
+
return releaseLockFn();
|
|
250
|
+
}
|
|
380
251
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
252
|
+
req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
253
|
+
cleanup(true);
|
|
254
|
+
req.log("Refreshed token for gitana user: " + req.identity_properties.token);
|
|
255
|
+
releaseLockFn();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
384
260
|
|
|
385
|
-
|
|
386
|
-
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
//res.setHeader('x-powered-by', 'cloudcms');
|
|
266
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
267
|
+
proxyRes.pipe(res)
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
var proxyRequestHandler = function(req, res) {
|
|
271
|
+
proxy.web(req, res, webConfig, function(err, req, res) {
|
|
272
|
+
defaultWebHandler(err, req, res);
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// cookie domain rewrite?
|
|
277
|
+
// not needed - this is handled intrinsically by http2-proxy
|
|
387
278
|
|
|
388
|
-
return
|
|
279
|
+
return proxyRequestHandler;
|
|
389
280
|
};
|
package/util/redis.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var redis = require("redis");
|
|
2
|
+
const logFactory = require("./logger");
|
|
3
|
+
|
|
4
|
+
exports = module.exports;
|
|
5
|
+
|
|
6
|
+
var redisLogger = exports.redisLogger = function(name, prefix, defaultLevel)
|
|
7
|
+
{
|
|
8
|
+
if (!defaultLevel) {
|
|
9
|
+
defaultLevel = "error";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var level = null;
|
|
13
|
+
|
|
14
|
+
// allow for global redis default
|
|
15
|
+
// allow for prefix specific
|
|
16
|
+
if (typeof(process.env["CLOUDCMS_REDIS_DEBUG_LEVEL"]) !== "undefined") {
|
|
17
|
+
level = "" + process.env["CLOUDCMS_REDIS_DEBUG_LEVEL"].toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!level && prefix)
|
|
21
|
+
{
|
|
22
|
+
if (typeof(process.env[prefix + "REDIS_DEBUG_LEVEL"]) !== "undefined") {
|
|
23
|
+
level = "" + process.env[prefix + "REDIS_DEBUG_LEVEL"].toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!level) {
|
|
28
|
+
level = defaultLevel;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var logger = logFactory(name);
|
|
32
|
+
logger.setLevel(level);
|
|
33
|
+
|
|
34
|
+
return logger;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var redisOptions = exports.redisOptions = function(config, prefix)
|
|
38
|
+
{
|
|
39
|
+
if (!config) {
|
|
40
|
+
config = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// redis port
|
|
44
|
+
var redisPort = config.port;
|
|
45
|
+
if (prefix)
|
|
46
|
+
{
|
|
47
|
+
if (typeof(redisPort) === "undefined" || !redisPort)
|
|
48
|
+
{
|
|
49
|
+
// CLOUDCMS_LOCKS_REDIS_PORT;
|
|
50
|
+
redisPort = process.env[prefix + "_REDIS_PORT"];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (typeof(redisPort) === "undefined" || !redisPort)
|
|
54
|
+
{
|
|
55
|
+
redisPort = process.env.CLOUDCMS_REDIS_PORT;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// redis host
|
|
59
|
+
var redisEndpoint = config.endpoint;
|
|
60
|
+
if (prefix)
|
|
61
|
+
{
|
|
62
|
+
if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
|
|
63
|
+
{
|
|
64
|
+
redisEndpoint = process.env[prefix + "_REDIS_ENDPOINT"];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
|
|
68
|
+
{
|
|
69
|
+
redisEndpoint = process.env.CLOUDCMS_REDIS_ENDPOINT;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// redis url
|
|
73
|
+
var redisUrl = config.url;
|
|
74
|
+
if (prefix)
|
|
75
|
+
{
|
|
76
|
+
if (typeof(redisUrl) === "undefined" || !redisUrl)
|
|
77
|
+
{
|
|
78
|
+
redisUrl = process.env[prefix + "_REDIS_URL"];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (typeof(redisUrl) === "undefined" || !redisUrl)
|
|
82
|
+
{
|
|
83
|
+
redisUrl = process.env.CLOUDCMS_REDIS_URL;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// build redis URL from components if not otherwise provided
|
|
87
|
+
if (!redisUrl)
|
|
88
|
+
{
|
|
89
|
+
redisUrl = "redis://" + redisEndpoint + ":" + redisPort;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var redisOptions = {};
|
|
93
|
+
redisOptions.url = redisUrl;
|
|
94
|
+
|
|
95
|
+
return redisOptions;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var createAndConnect = exports.createAndConnect = async function(redisOptions, callback)
|
|
99
|
+
{
|
|
100
|
+
var client = redis.createClient(redisOptions);
|
|
101
|
+
|
|
102
|
+
var connectErr = null;
|
|
103
|
+
client.on('error', function(err) {
|
|
104
|
+
console.log('Redis Client Error', err);
|
|
105
|
+
connectErr = err;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// connect
|
|
109
|
+
await client.connect();
|
|
110
|
+
//console.log("Connected to redis, options: " + JSON.stringify(redisOptions, null, 2) + ", err: " + connectErr + ", client: " + client);
|
|
111
|
+
|
|
112
|
+
return callback(connectErr, client);
|
|
113
|
+
}
|
package/util/renditions.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var path = require('path');
|
|
2
|
-
var fs = require('fs');
|
|
1
|
+
// var path = require('path');
|
|
2
|
+
// var fs = require('fs');
|
|
3
3
|
var util = require("../util/util");
|
|
4
|
-
var async = require("async");
|
|
4
|
+
//var async = require("async");
|
|
5
5
|
|
|
6
|
-
var http = require("http");
|
|
7
|
-
var https = require("https");
|
|
6
|
+
// var http = require("http");
|
|
7
|
+
// var https = require("https");
|
|
8
8
|
|
|
9
9
|
var logFactory = require("./logger");
|
|
10
10
|
|
|
@@ -62,7 +62,13 @@ exports = module.exports = function()
|
|
|
62
62
|
|
|
63
63
|
var syncRows = function(rows, callback)
|
|
64
64
|
{
|
|
65
|
-
var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + "/bulk/pagerenditions";
|
|
65
|
+
var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + "/bulk/pagerenditions";
|
|
66
|
+
|
|
67
|
+
var agent = http.globalAgent;
|
|
68
|
+
if (process.env.GITANA_PROXY_SCHEME === "https")
|
|
69
|
+
{
|
|
70
|
+
agent = https.globalAgent;
|
|
71
|
+
}
|
|
66
72
|
|
|
67
73
|
// add "authorization" for OAuth2 bearer token
|
|
68
74
|
var headers = {};
|