Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit 81522e5

Browse files
author
jbooth1
committed
Fixes for HTTPS
1 parent c04fa51 commit 81522e5

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

digexp-wcm-design/lib/wcm-authenticated-request.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
88
* specific language governing permissions and limitations under the License.
99
*/
10-
var http = require('http');
10+
var http = null; // will use either http or https, depending on "secure" option
1111
var Q = require('q');
1212
var debugLogger = require('./utils').debugLogger('wcm-request');
1313
var currentRequestLevel = 0; // Track number of concurrent requests
@@ -18,7 +18,10 @@ var warnParallel = true;
1818
var httpGetHelper = function(options) {
1919
options.headers.Cookie = authCookie;
2020
var deferred = Q.defer(), body = '', doRequest = function(options) {
21-
debugLogger.trace('httpGetHelper:: options::' + options);
21+
debugLogger.trace('httpGetHelper:: options::', options);
22+
if (options.secure) {
23+
options.rejectUnauthorized = false;
24+
}
2225
var reqGet = http.request(options, function(response) {
2326
if(options.headers && options.headers.ContentType && options.headers.ContentType.indexOf('image') != -1)
2427
response.setEncoding('binary');
@@ -71,7 +74,10 @@ var httpGetHelper = function(options) {
7174
var httpPostHelper = function(options, postData) {
7275
options.headers.Cookie = authCookie;
7376
var deferred = Q.defer(), body = '', doRequest = function(options, postData) {
74-
debugLogger.trace('httpPostHelper:: options::' + options + ' postData::' + postData);
77+
debugLogger.trace('httpPostHelper:: options::', options, ' postData::' + postData);
78+
if (options.secure) {
79+
options.rejectUnauthorized = false;
80+
}
7581
var reqPost = http.request(options, function(response) {
7682
if (response.statusCode == 404) {
7783
var err = getErrorFromResponse(null, response);
@@ -140,9 +146,12 @@ var getLTPAToken = function(user, pass, options, postData) {
140146
};
141147

142148
var deferred = Q.defer(), doRequest = function(optionspost, options, postData) {
143-
debugLogger.trace('getLTPAToken:: user::' + user + ' pass::' + pass + ' options::' + options + ' postData::' + postData);
149+
debugLogger.trace('getLTPAToken:: user::' + user + ' options::', options, ' postData::' + postData);
144150
// todo use request instead of node http for cleaner error handling
145151
try {
152+
if (options.secure) {
153+
optionspost.rejectUnauthorized = false;
154+
}
146155
var reqPost = http.request(optionspost, function(response) {
147156
if (!response.headers["set-cookie"]) {
148157
var err = getErrorFromResponse("Authentication error");
@@ -238,7 +247,7 @@ var maxLtpaAge = 1000 * 60 * 30; // 30 minutes
238247

239248
var authenticatedRequest = function(user, pass, options, postData) {
240249
var deferred = Q.defer(), authenticate = function(user, pass, options, postData) {
241-
debugLogger.trace('authenticatedRequest:: user::' + user + ' pass::' + pass + ' options::' + options + ' postData::' + postData);
250+
debugLogger.trace('authenticatedRequest:: user::' + user + ' options::', options, ' postData::' + postData);
242251
// sometimes the content HandlerPath might be part of the uri already if not add
243252
if (options.path.lastIndexOf(options.contentHandlerPath, 0) != 0)
244253
options.path = options.contentHandlerPath + options.path;
@@ -347,6 +356,7 @@ var getJson = function(uri) {
347356
port : globalPort,
348357
contentHandlerPath : globalContentHandlerPath,
349358
path : uri,
359+
secure : globalSecure,
350360
method : 'GET',
351361
headers : {
352362
Accept : "application/json"
@@ -378,6 +388,7 @@ var setJson = function(uri, postData) {
378388
port : globalPort,
379389
contentHandlerPath : globalContentHandlerPath,
380390
path : uri,
391+
secure : globalSecure,
381392
method : 'Post',
382393
headers : {
383394
'Content-Type' : 'application/atom+xml',
@@ -412,6 +423,7 @@ var setContent = function(uri, contentType, data) {
412423
contentHandlerPath : globalContentHandlerPath,
413424
port : globalPort,
414425
path : uri,
426+
secure : globalSecure,
415427
method : 'Put',
416428
headers : {
417429
'ContentType' : contentType,
@@ -445,6 +457,7 @@ var getContent = function(uri, contentType) {
445457
port : globalPort,
446458
contentHandlerPath : globalContentHandlerPath,
447459
path : uri + '?mime-type=' + encodeURIComponent(contentType),
460+
secure : globalSecure,
448461
method : 'Get',
449462
headers : {
450463
'Content-Type' : contentType,
@@ -474,10 +487,12 @@ var globalPort = null;
474487
var globalContentHandlerPath = '/wps/mycontenthandler';
475488
var globalUser = '';
476489
var globalPassword = '';
490+
var globalSecure = false;
477491
var authCookie = null;
478492

479-
var init = function(host, port, user, password, contentHandlerPath) {
480-
debugLogger.trace('init:: host::' + host + ' port::' + port + ' user::' + user + ' contentHandlerPath::' + contentHandlerPath);
493+
var init = function(host, port, user, password, contentHandlerPath, secure) {
494+
http = secure ? require('https') : require('http');
495+
debugLogger.trace('init:: host::' + host + ' port::' + port + ' user::' + user + ' contentHandlerPath::' + contentHandlerPath + ' secure::' + secure);
481496
var deferred = Q.defer(), initialize = function(contentHandlerPath) {
482497
var pathComponents = contentHandlerPath.split('/');
483498
// for vitrula portals the last component is the portal context if
@@ -504,6 +519,7 @@ var init = function(host, port, user, password, contentHandlerPath) {
504519
};
505520
globalHost = host;
506521
globalPort = port;
522+
globalSecure = secure;
507523
if (contentHandlerPath != undefined)
508524
globalContentHandlerPath = contentHandlerPath;
509525
globalUser = user;

digexp-wcm-design/wcmHelper.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var authRequest = require('./lib/wcm-authenticated-request'),
4343
wcmCwd = '', curHost = '', curUser = '', curPassword = '',
4444
curPort = '',
4545
curContentPath = '',
46+
curSecure = false,
4647
curPullLibrary = undefined;
4748

4849
/**
@@ -54,16 +55,17 @@ var authRequest = require('./lib/wcm-authenticated-request'),
5455
* These will reset to 0 when the operation(s) is completed.
5556
*/
5657
var progCounter = 0, progGoal = 0;
57-
init = function(host, port, contentPath, user, password, wcmDir) {
58-
debugLogger.trace("init:: host::"+host +" port::" + port + "contentPath::" + contentPath + "user::" + user + "password::" + password + "wcmDir::" + wcmDir);
58+
init = function(host, port, contentPath, user, password, wcmDir, secure) {
59+
debugLogger.trace("init:: host::"+host +" port::" + port + " contentPath::" + contentPath + " user::" + user + " wcmDir::" + wcmDir + ' secure::' + secure);
5960
wcmRequests.clearFolderMap();
6061
wcmCwd = wcmDir + Path.sep;
6162
curUser = user;
6263
curPassword = password;
6364
curHost = host;
6465
curPort = port;
6566
curContentPath = contentPath;
66-
return authRequest.init(host, port, user, password, contentPath);
67+
curSecure = secure;
68+
return authRequest.init(host, port, user, password, contentPath, secure);
6769
}, getLibraries = function() {
6870
var libraries = [];
6971
return wcmRequests.getAllLibraries().then(function(items) {
@@ -157,6 +159,7 @@ init = function(host, port, contentPath, user, password, wcmDir) {
157159
libSettings.host = curHost;
158160
libSettings.port = curPort;
159161
libSettings.contenthandlerPath = curContentPath;
162+
libSettings.secure = curSecure;
160163
libSettings.title = libTitle;
161164
libSettings.serverPulled = curHost + curContentPath;
162165
libSettings.title = libTitle;

0 commit comments

Comments
 (0)