Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2005

Tip: Looking for answers? Try searching our database.

WSE 3 - Getting at the UsernameToken in the webservice?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul.evans.groups@googlemail.com - 31 Oct 2005 16:36 GMT
Hi all,
 I've been getting this warning:

Microsoft.Web.Services3.SoapContext.Security is obsolete:
SoapContext.Security is obsolete. Consider deriving from
SendSecurityFilter or ReceiveSecurityFilter and creating a custom
policy assertion that generates these filters.

So I'm guessing that it would be very bad form to use this to get at my
UsernameToken then, like WSE 2 samples would have you do.

I'm not sure that building a Filter would work in my case, as the
service will be calling in to something that authenticates user details
by function (to check that they are allowed to run the function) - and
not only requires the username and password from the UsernameToken, but
also two extra things encoded in the "any" element of the
UsernameToken.  By the time it gets down to the webservice, it seems
that only a SecurityToken is available, which only has the identity
username easily available in it.  Attempting to downcast to
UsernameToken fails.  Yet the custom UsernameTokenManager is in place
and seems to be working.

May be I'm missing the point somewhere, I'm getting a feeling that MS
push down this route for a good reason.

But is there anyway to get to the UsernameToken in a non-obsolete way
in the Webservice code?
Pablo Cibraro - 31 Oct 2005 18:28 GMT
Hi Paul,
You can get it from the web service using the method:

Microsoft.Web.Services3.SoapContext.Current.IdentityToken

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax

> Hi all,
>  I've been getting this warning:
[quoted text clipped - 23 lines]
> But is there anyway to get to the UsernameToken in a non-obsolete way
> in the Webservice code?
paul.evans.groups@googlemail.com - 01 Nov 2005 12:22 GMT
Microsoft.Web.Services3.SoapContext.Current is null in my [WebMethod],
so IdentityToken is inaccessible.
paul.evans.groups@googlemail.com - 01 Nov 2005 13:52 GMT
Okay, but you actually did give me something to think about:

[WebMethod]
       public string EchoTest(string message)
       {
           string echo;

           UsernameToken token = null;
           SecurityContextToken securityContextToken =
RequestSoapContext.Current.IdentityToken as SecurityContextToken;

           if (null != securityContextToken)
           {
               token = securityContextToken.BaseToken as
UsernameToken;
           }

           if (null == token)
           {
               echo = message + " - said goodness knows who.";
           }
           else
           {
               echo = message + " - said " + token.Username + " " +
token.Password + " " + KeyMaster.GetUserType(token) + " " +
KeyMaster.GetUserLocation(token);
           }

           return echo;
       }

Works!

I noticed though, when putting things to the Any property of the
UsernameToken (type of Microsoft.Web.Services3.Xml.ElementList) -
although on the client side you might have more then one thing in the
list, it seems that only the first element is ever serialised and gets
back to as far as the webservice.

I got around this by creating an XmlElement that has the things I want
as child nodes of the first thing in the ElementList (taken care of by
that KeyMaster class).

Anyway as far as I am aware all of the above doesn't use anything that
is obsolute.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.