I want to add some extra fields to my custom UsernameToken in addition to the
username, password etc. fields. Specifically I want to add two strings;
TerminalId and UserRoleId.
In my business logic (windows.forms) I request a WS method like this:
// cut to the chase..
token = new UsernameToken(clientSession.UserName, clientSession.Password,
PasswordOption.SendPlainText );
// Add custom credentials to SOAP authentication header.
XmlDocument doc = new XmlDocument();
XmlElement terminalIdXml = doc.CreateElement("TerminalId");
terminalIdXml.InnerText = clientSession.TerminalId;
token.AnyElements.Add(terminalIdXml);
XmlElement userRoleIdXml = doc.CreateElement("UserRoleId");
userRoleIdXml.InnerText = clientSession.UserRoleId;
token.AnyElements.Add(userRoleIdXml);
// ...
proxy.RequestSoapContext.Security.Tokens.Add( token );
proxy.RequestSoapContext.Security.Elements.Add( new MessageSignature( token
) );
// Call method
Then here is the manager:
protected override string AuthenticateToken(UsernameToken token){
//..
if(session.AuthenticateUser(token.AnyElements[0].InnerText, token.Username,
token.Password, token.AnyElements[1].InnerText)){ return token.Password;}
//..
When the business logic calls the webservice, the AnyElements contains the
two extra elements.
I trace the SOAP message and find them as I expect:
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-e0620cd1-a599-4899-aacb-e00857d0609c">
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1
.0#PasswordText">PASSWORD</wsse:Password>
<wsse:Nonce>k1llyCjkSOsQK9mJZ5PpRA==</wsse:Nonce>
<wsu:Created>2005-04-22T08:04:37Z</wsu:Created>
<TerminalId>aafajz+0000001000032</TerminalId>
<UserRoleId>aafafe+0000000000028</UserRoleId>
</wsse:UsernameToken>
But when I debug the UsernameTokenManager I find only the first of the two
additional elements, TerminalId. Isn't that weird?
I'm guessing there is something wrong in the way I add the XmlElements to
the AnyElement list, but I can't see what would be wrong..?
Any hints? I can't find much info about this around, and the documentation
is rather scarce..
Qpeg - 29 Apr 2005 09:16 GMT
My solution was to add a single XmlElement, and add the two extra fields to
this as attributes.
Still wondering what is going on here tho..
> I want to add some extra fields to my custom UsernameToken in addition to the
> username, password etc. fields. Specifically I want to add two strings;
[quoted text clipped - 52 lines]
> Any hints? I can't find much info about this around, and the documentation
> is rather scarce..