Jump to navigation

Poupou's Corner of the Web

Looking for perfect security? Try a wireless brick.
Otherwise you may find some unperfect stuff here...


First WSE client for Mono

Today I got the Mono' implementation of WSE to send a SOAP request containing a WS-Security UsernameToken (based on the first sample of MSDN's WS-Security Authentication and Digital Signatures with Web Services Enhancements) and Timestamp. However this only works (right now) under Windows. Now I just got to make this works with the mono runtime, then make the web service runs under XSP.

What I really like about WSE it's that it doesn't requires much code to use. Here's the sample client code:

using System; using Microsoft.Web.Services.Security; class UsernameTokenTest { [STAThread] static void Main(string[] args) { Username proxy = new Username (); UsernameToken tok = new UsernameToken ("poupou", "password", PasswordOption.SendHashed); proxy.RequestSoapContext.Security.Tokens.Add (tok); try { Console.WriteLine (proxy.PersonnalHello ()); } catch (Exception e) { Console.WriteLine (e.ToString ()); } } }

And the service code:

[WebMethod] public string PersonnalHello () { string response = ""; SoapContext requestContext = HttpSoapContext.RequestContext; if (requestContext == null) throw new ApplicationException ("non SOAP request"); foreach (SecurityToken tok in requestContext.Security.Tokens) { if (tok is UsernameToken) response += "Hello " + ((UsernameToken)tok).Username; } if (response == "") response = "unauthenticated request"; return response; }

and, finally, the PasswordProvider:

public class PasswordProvider : IPasswordProvider { public string GetPassword (UsernameToken token) { return "password"; } }

Never been so excited to see Hello poupou written on the console ;-)

10/4/2003 16:16:13 | Comments

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.