Web Part to view a User’s Claims


As promised in my earlier video demo, here is a web part that I quickly wrote to view the claims of a user when they are authenticating to the SharePoint site using a Security Token Service such as Geneva Server. There are some important sections in the code. First is the check to see if a user is actually has a claims principal:

IClaimsPrincipal icp = null;
IClaimsIdentity claimsIdentity = null;

public ViewClaimsWebPart()
{
     try
     {
          icp = this.Context.User as IClaimsPrincipal;
          claimsIdentity = (IClaimsIdentity)icp.Identity;
     }
     catch
     {
     }
}

protected override void CreateChildControls()
{
       try
       {

           if (claimsIdentity != null)

 

And then just collecting the claims into a dataset:

ClaimsInfo oData = new ClaimsInfo();

foreach (Claim claim in claimsIdentity.Claims)
{
      oData.Claims.AddClaimsRow(claim.ClaimType, claim.Value);
}

Here is a link where you can download the sample. Just be mindful it is a sample.

http://cid-601cfa765e7a6fd3.skydrive.live.com/self.aspx/Public/ViewClaimsWP.zip

 

Just one note that this project was built using the new Visual Studio Extensions for WSS 1.3 March CTP. You can get that here if you haven’t tried it out. Much better than previous releases – so give it a try.

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=fb9d4b85-da2a-432e-91fb-d505199c49f6


Comments (1)
  1. There is an error in your code where it tries to split the Assigned To value apart.  The "parts" of assigned to are separated by the string ";#", not the the character ‘;’.  That means the following line is incorrect:

    Dim parts() As String = name.Split(CChar("#"))

    and needs to be changed to this:

    Dim parts() As String = Split(name, ";#", 2)

    — Your ‘favorite'(?) errata finder

    — Fred Morrison

Comments are closed.

Skip to main content