Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - Web Services Enhancements 2.0: Security an...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Web Services Enhancements 2.0: Security and Policy (VB.NET)
By: MSDN Virtual Labs
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2006-07-13

    Table of Contents:
  • Web Services Enhancements 2.0: Security and Policy (VB.NET)
  • Creating User Accounts and Groups
  • Sending a UsernameToken
  • Requiring a UsernameToken
  • Implementing a UsernameTokenManager
  • Signing with a UsernameToken
  • Encrypting with a UsernameToken

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Web Services Enhancements 2.0: Security and Policy (VB.NET) - Implementing a UsernameTokenManager


    (Page 5 of 7 )

    In the previous examples, WSE 2.0 was able to automatically authenticate the supplied UsernameToken against local Windows accounts. WSE 2.0 can only do this when the password is sent in plain text (using PasswordOption.SendPlainText). This is not the most common approach in practice because of the obvious security risks. You should only send passwords in plain text when you're sending messages over a secure channel (e.g., HTTPS) or when you're simply not concerned about confidentiality in the application environment. Another approach is to send a hashed password (using PasswordOption.SendHashed) or no password at all. This technique requires you to implement a class that assists in the UsernameToken authentication process. In this step, you're going to write a custom UsernameTokenManager-derived class.

     

      1. Open WseSecurityHelpers.vb and define a new class named MyUsernameTokenManager. It should derive from UsernameTokenManager.
      2. Override the AuthenticateToken method as illustrated here:

        ...
        Public Class MyUsernameTokenManager
            Inherits UsernameTokenManager 
            Protected Overrides Function AuthenticateToken(ByVal token _ 
            As UsernameToken) As String
             ...
            End Function
        End Class ...


        Note: you can use Visual Studio.NET's Class View to automatically override the method. Navigate to the AuthenticateToken method, right click, and select Add | Override. 

      3. Within AuthenticateToken, you can inspect the supplied token to perform authentication. You must return the password for the supplied token, which WSE 2.0 will check against what was supplied in the message. For this example, simply return "password" for all tokens. You'll now need to provide "password" as the password when running the client application.

        Note: You would typically look up the password in a database or some other password store (e.g., an XML file).

      4. In addition, you need to manually set the token's Principal property. Do this by creating a new GenericPrincipal object and assign it to all of the roles that the supplied user belongs to (according to what we defined earlier). Here's an example of AuthenticateToken:

        ...
        Public Class MyUsernameTokenManager 
            Inherits UsernameTokenManager
            Protected Overrides Function
        AuthenticateToken(ByVal token _
               As UsernameToken) As String
               Dim roles As New ArrayList()
               Select Case token.Username
                   Case "admin" 
                       roles.Add(String.Format("{0}User",   
                     Dns.GetHostName()))
        roles.Add(String.Format("{0}Vendor",
                     Dns.GetHostName()))
        roles.Add(String.Format("{0}Manager", _
                     Dns.GetHostName()))
        roles.Add(String.Format("{0}Accounting", 
                     Dns.GetHostName()))
                  token.Principal = New
        GenericPrincipal(
                     New GenericIdentity(token.Username), 
                     roles.ToArray(GetType(String)))
              Case "aaron"
                  roles.Add(String.Format("{0}User",   
                    Dns.GetHostName()))
        roles.Add(String.Format("{0}Accounting", _  
                    Dns.GetHostName()))
                 token.Principal = New
        GenericPrincipal( _
                           New GenericIdentity(token.Username),   
                       roles.ToArray(GetType(String)))
                Case "mike" 
                    roles.Add(String.Format("{0}User",   
                     Dns.GetHostName()))
        roles.Add(String.Format("{0}Manager",
                     Dns.GetHostName()))
                  token.Principal = New
        GenericPrincipal( 
                     New GenericIdentity(token.Username), _ 
                     roles.ToArray(GetType(String)))
              Case "vick"
                  roles.Add(String.Format("{0}User", 
                    Dns.GetHostName()))
        roles.Add(String.Format("{0}Vendor", 
                    Dns.GetHostName()))
                 token.Principal = New
        GenericPrincipal( 
                    New GenericIdentity(token.Username), 
                    roles.ToArray(GetType(String)))
             Case Else  
                 MyBase.Authenticate
        Token(token)
             End Select
             Return "password"

          End Function 'AuthenticateToken
        End Class 'MyUsernameTokenManager

        ....

      5. To use this UsernameTokenManager, you need to configure it in the project's Web.config file. The easiest way to accomplish this is to open the WSE Settings 2.0 tool.
      6. Right-click on the SecureInvoiceServiceA project and click WSE Settings 2.0….
      7. Click the Security tab. 
      8. Click Add in the Security Tokens Managers section. The SecurityToken Manager dialog will then open. 
      9. In the Type field, type SecureInvoiceServiceA. MyUsernameTokenManager, SecureInvoiceServiceA
      10. In the Namespace field, enter http://docs.oasis-
        open.org/wss/2004/01/oasis-200401-wss-
        wssecurity-secext-1.0.xsd

      11. In the QName field, enter wsse:UsernameToken
      12. Click OK.
      13. Click OK
      14. Open the project's web.config file and confirm that it contains the following sections:

        <configuration>
            ...
            <configSections> 
                <section name="microsoft.web.services2" type="Microsoft.Web.Services2.
        Configuration.WebServices Configuration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        />
            </configSections>  
           <microsoft.web.services2> 
                  <security>   
                <securityTokenManager type="SecureInvoiceServiceA.My
        UsernameTokenManager, SecureInvoiceServiceA" xmlns:wsse="
        http://dovb.oasis-
        open.org/wss/2004/01/oasis-200401-wss-wssecurity
        -secext-1.0.xsd
        " qname="wsse:UsernameToken" />
                   </security>  
          </microsoft.web.services2>
          ...
         
      15. Build SecureInvoiceServiceA.
      16. Run the client again and verify that the security functionality has remained the same, even with our custom UsernameTokenManager class.

        Note: the client application is still sending the password in plain text at this point.
      17. In the Solution Explorer, in the SecureInvoiceClient project, right-click login.vb and click View Code.
      18. In the button1_Click method, replace PasswordOption.SendPlainText with PasswordOption.SendHashed
      19. Rebuild the project and test. Verify that everything still works as before.

    More Visual Basic.NET Articles
    More By MSDN Virtual Labs


       · This lab is excerpted from a larger document titled "Web Services Enhancement 2.0:...
       · I wonder that where I can find SecureInvoiceA.sln you mentioned in Web Services...
       · Please check our link to the Microsoft Virtual Labs website, ...
       · i havent got the SecureInvoiceA.sln...i checked in the link u provided...can u...
       · Microsoft must have moved a few things around -- try this:...
       · Web Services Enhancements 2.0: Security and Policy (VB.NET), The reason for going...
       · Can you specify the location of SecureInvoiceClient project.Urgent reply soon
     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway