@@ -27,6 +27,9 @@ var Logger = require('./log').Logger;
27
27
var util = require ( './util' ) ;
28
28
var WSTrustResponse = require ( './wstrust-response' ) ;
29
29
30
+ var USERNAME_PLACEHOLDER = '{UsernamePlaceHolder}' ;
31
+ var PASSWORD_PLACEHOLDER = '{PasswordPlaceHolder}' ;
32
+
30
33
/**
31
34
* Creates a new instance of WSTrustRequest
32
35
* @constructor
@@ -42,22 +45,6 @@ function WSTrustRequest(callContext, wstrustEndpointUrl, appliesTo) {
42
45
this . _appliesTo = appliesTo ;
43
46
}
44
47
45
- /**
46
- * Builds the UsernameToken XML that will carry the user creds in the RST.
47
- * @param {string } username A username
48
- * @param {string } password The password that corresponds to the username parameter.
49
- * @returns {string } A string containing the UsernameToken XML
50
- */
51
- WSTrustRequest . prototype . _buildSoapMessageCredentials = function ( username , password ) {
52
- var usernameTokenXml =
53
- '<wsse:UsernameToken wsu:Id=\'ADALUsernameToken\'>\
54
- <wsse:Username>' + username + '</wsse:Username>\
55
- <wsse:Password>' + password + '</wsse:Password>\
56
- </wsse:UsernameToken>' ;
57
-
58
- return usernameTokenXml ;
59
- } ;
60
-
61
48
/**
62
49
* Given a Date object adds the minutes parameter and returns a new Date object.
63
50
* @private
@@ -80,7 +67,7 @@ function _datePlusMinutes(date, minutes) {
80
67
* @param {string } password The passowrd that corresponds to the username parameter.
81
68
* @returns {string } A string that contains the soap security header.
82
69
*/
83
- WSTrustRequest . prototype . _buildSecurityHeader = function ( username , password ) {
70
+ WSTrustRequest . prototype . _buildSecurityHeader = function ( ) {
84
71
var timeNow = new Date ( ) ;
85
72
var expireTime =
86
73
_datePlusMinutes ( timeNow , 10 ) ;
@@ -92,13 +79,30 @@ _datePlusMinutes(timeNow, 10);
92
79
<wsu:Timestamp wsu:Id=\'_0\'>\
93
80
<wsu:Created>' + timeNowString + '</wsu:Created>\
94
81
<wsu:Expires>' + expireTimeString + '</wsu:Expires>\
95
- </wsu:Timestamp>' +
96
- this . _buildSoapMessageCredentials ( username , password ) +
97
- '</wsse:Security>' ;
82
+ </wsu:Timestamp>\
83
+ <wsse:UsernameToken wsu:Id=\'ADALUsernameToken\'>\
84
+ <wsse:Username>' + USERNAME_PLACEHOLDER + '</wsse:Username>\
85
+ <wsse:Password>' + PASSWORD_PLACEHOLDER + '</wsse:Password>\
86
+ </wsse:UsernameToken>\
87
+ </wsse:Security>' ;
98
88
99
89
return securityHeaderXml ;
100
90
} ;
101
91
92
+ /**
93
+ * Replaces the placeholders in the RST template with the actual username and password values.
94
+ * @private
95
+ * @param {string } RSTTemplate An RST with placeholders for username and password.
96
+ * @param {string } username A username
97
+ * @param {string } password The passowrd that corresponds to the username parameter.
98
+ * @returns {string } A string containing a complete RST soap message.
99
+ */
100
+
101
+ WSTrustRequest . prototype . _populateRSTUsernamePassword = function ( RSTTemplate , username , password ) {
102
+ var RST = RSTTemplate . replace ( USERNAME_PLACEHOLDER , username ) . replace ( PASSWORD_PLACEHOLDER , password ) ;
103
+ return RST ;
104
+ } ;
105
+
102
106
/**
103
107
* Builds a WS-Trust RequestSecurityToken (RST) message using username password authentication.
104
108
* @private
@@ -109,7 +113,9 @@ _datePlusMinutes(timeNow, 10);
109
113
WSTrustRequest . prototype . _buildRST = function ( username , password ) {
110
114
var messageID = uuid . v4 ( ) ;
111
115
112
- var RST =
116
+ // Create a template RST with placeholders for the username and password so the
117
+ // the RST can be logged without the sensitive information.
118
+ var RSTTemplate =
113
119
'<s:Envelope xmlns:s=\'http://www.w3.org/2003/05/soap-envelope\' xmlns:wsa=\'http://www.w3.org/2005/08/addressing\' xmlns:wsu=\'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\'>\
114
120
<s:Header>\
115
121
<wsa:Action s:mustUnderstand=\'1\'>http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</wsa:Action>\
@@ -118,7 +124,7 @@ WSTrustRequest.prototype._buildRST = function(username, password) {
118
124
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>\
119
125
</wsa:ReplyTo>\
120
126
<wsa:To s:mustUnderstand=\'1\'>' + this . _wstrustEndpointUrl + '</wsa:To>\
121
- ' + this . _buildSecurityHeader ( username , password ) + '\
127
+ ' + this . _buildSecurityHeader ( ) + '\
122
128
</s:Header>\
123
129
<s:Body>\
124
130
<wst:RequestSecurityToken xmlns:wst=\'http://docs.oasis-open.org/ws-sx/ws-trust/200512\'>\
@@ -133,6 +139,9 @@ WSTrustRequest.prototype._buildRST = function(username, password) {
133
139
</s:Body>\
134
140
</s:Envelope>' ;
135
141
142
+ this . _log . verbose ( 'Created RST: \n' + RSTTemplate ) ;
143
+
144
+ var RST = this . _populateRSTUsernamePassword ( RSTTemplate , username , password ) ;
136
145
return RST ;
137
146
} ;
138
147
@@ -176,7 +185,7 @@ WSTrustRequest.prototype.acquireToken = function(username, password, callback) {
176
185
}
177
186
) ;
178
187
179
- this . _log . verbose ( 'Sending RST to: ' + this . _wstrustEndpointUrl + '\n' + RST ) ;
188
+ this . _log . verbose ( 'Sending RST to: ' + this . _wstrustEndpointUrl ) ;
180
189
181
190
request . post ( this . _wstrustEndpointUrl , options , util . createRequestHandler ( 'WS-Trust RST' , this . _log , callback ,
182
191
function ( response , body ) {
0 commit comments