Discuss this help topic in SecureBlackbox Forum
SOAP: Add WS-Security token
To add new Username token to the WS-Security header you need to create an instance of TElXMLWSSEUsernameToken class, then add it using header's AddToken() method, and finally adjust the properties of the instance.
The sample code below adds WS-Security header and then adds Username token to it:
C#:
int k = SOAPMessage.AddSecurityHeader();
TElXMLWSSEUsernameToken UsernameToken = new TElXMLWSSEUsernameToken();
SOAPMessage.get_SecurityHeaders(k).AddToken(UsernameToken);
UsernameToken.CreateUsername();
UsernameToken.CreatePassword();
UsernameToken.CreateNonce();
UsernameToken.Username.Data = "user";
UsernameToken.Password.Data = "password";
UsernameToken.Password.PasswordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
UsernameToken.Nonce.Data = "base64 data";
UsernameToken.Nonce.EncodingType = SBXMLDefs.Unit.xmlWSSEncodingBase64Binary;
UsernameToken.CreatedUTC = DateTime.UtcNow;
Delphi:
var
k : integer;
UsernameToken : TElXMLWSSEUsernameToken;
...
k := SOAPMessage.AddSecurityHeader();
UsernameToken := TElXMLWSSEUsernameToken.Create();
SOAPMessage.SecurityHeaders[k].AddToken(UsernameToken);
UsernameToken.CreateUsername();
UsernameToken.CreatePassword();
UsernameToken.CreateNonce();
UsernameToken.Username.Data := 'user';
UsernameToken.Password.Data := 'password';
UsernameToken.Password.PasswordType := 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
UsernameToken.Nonce.Data := 'base64 data';
UsernameToken.Nonce.EncodingType := SBXMLDefs.Unit.xmlWSSEncodingBase64Binary;
UsernameToken.CreatedUTC := SBUtils.DateTimeUtcNow;
To add new Timestamp to the WS-Security header you need to create an instance of TElXMLWSUTimestamp class, then add it using header's AddToken() method, and finally adjust the properties of the instance.
The code below adds a Timestamp to the first WS-Security header:
C#:
TElXMLWSUTimestamp Timestamp = new TElXMLWSUTimestamp();
SOAPMessage.get_SecurityHeaders(0).AddToken(Timestamp);
Timestamp.CreatedUTC = DateTime.UTCNow;
Timestamp.ExpiresUTC = Timestamp.CreatedUTC.AddDays(1);
Timestamp.ID = "timestamp-id-1";
Delphi:
Timestamp := TElXMLWSUTimestamp.Create();
SOAPMessage.SecurityHeaders[0].AddToken(Timestamp);
Timestamp.CreatedUTC := SBUtils.DateTimeUTCNow;
Timestamp.ExpiresUTC := DateTimeAddDays(Timestamp.CreatedUTC, 1);
Timestamp.ID := 'timestamp-id-1';