I have seen some posts on the web showing how to display session claims for the logged in user by iterating through the claims HttpContext.Current.User in a webpart. However it seemed a bit dull for SharePoint 2010 which has so much fire in its belly. I quite like the concept of Business Connectivity Services (BCS) and while investigating it for possible use i thought this might be the simplest implementation that anyone could ever try out. However there are some benefits to using BCS. For example you can create custom view from the UI without writing additional code, for example show all course role claims in alphabetical order. You can also connect it up with other lists using SharePoint WebPart connections to drive another webpart, for example based on the course role claims selected show course details web part. Again the examples are Academic institution related but i am sure you guys can think of examples that relate to your organization. So this is the code. SPCecil.Connect.MyClaimsDataModel is the namespace for my classes.
public partial class MyClaim
{
public string Identifier { get; set; }
public string ClaimType { get; set; }
public string Value { get; set; }
public string Issuer { get; set; }
public string OriginalIssuer { get; set; }
public string ValueType { get; set; }
}
public class MyClaimService
{
public static MyClaim ReadItem(string id)
{
IClaimsIdentity identity = GetClaimsIdentity();
string[] parts = id.Split(new string[] { "::" },
2, StringSplitOptions.RemoveEmptyEntries);
if (parts != null && parts.Length == 2)
{
var claimsOfType = (from c in identity.Claims
where c.ClaimType == parts[0]
select c).ToArray();
int index = Convert.ToInt32(parts[1]);
if (claimsOfType != null && claimsOfType.Length > index)
{
Claim selectedClaim = claimsOfType[index];
return new MyClaim()
{
Identifier = id,
Value = selectedClaim.Value,
ValueType = selectedClaim.ValueType,
ClaimType = selectedClaim.ClaimType,
Issuer = selectedClaim.Issuer,
OriginalIssuer = selectedClaim.OriginalIssuer
};
}
}
return null;
}
public static IEnumerable ReadList()
{
IClaimsIdentity identity = GetClaimsIdentity();
var claimTypes = (from c in identity.Claims select c.ClaimType).Distinct();
List myClaims = new List();
foreach (string claimType in claimTypes)
{
var claims = from c in identity.Claims
where c.ClaimType == claimType
select c;
int index = 0;
foreach (Claim c in claims)
{
myClaims.Add(new MyClaim()
{
Identifier = c.ClaimType + "::" + index,
Value = c.Value,
ValueType = c.ValueType,
ClaimType = c.ClaimType,
Issuer = c.Issuer,
OriginalIssuer = c.OriginalIssuer
});
index++;
}
}
return myClaims.ToArray();
}
private static IClaimsIdentity GetClaimsIdentity()
{
IClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as IClaimsPrincipal;
if (claimsPrincipal != null)
{
return (IClaimsIdentity)claimsPrincipal.Identity;
}
return new ClaimsIdentity();
}
}
And the model definition should look something like this…
<?xml version="1.0" encoding="utf-8"?>
<Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog" Name="MyClaimsDataModel">
<LobSystems>
<LobSystem Name="MyClaimsDataModel" Type="DotNetAssembly">
<LobSystemInstances>
<LobSystemInstance Name="MyClaimsDataModel" DefaultDisplayName="My Claims" />
</LobSystemInstances>
<Entities>
<Entity Name="MyClaim" Namespace="SPCecil.Connect.MyClaimsDataModel" EstimatedInstanceCount="1000" Version="1.0.0.31">
<Properties>
<Property Name="Class" Type="System.String">SPCecil.Connect.MyClaimsDataModel.MyClaimService, MyClaimsDataModel</Property>
</Properties>
<Identifiers>
<Identifier Name="Identifier" TypeName="System.String" />
<!-- TODO:change the name of the ID and if needed the TypeName of your identifier.-->
</Identifiers>
<Methods>
<!-- start finder method-->
<Method Name="ReadList">
<!-- TODO:change the name of the method if needed.-->
<Parameters>
<Parameter Direction="Return" Name="returnParameter">
<TypeDescriptor TypeName="System.Collections.Generic.IEnumerable`1[[SPCecil.Connect.MyClaimsDataModel.MyClaim, MyClaimsDataModel]]" IsCollection="true" Name="MyClaimList">
<TypeDescriptors>
<TypeDescriptor Name="MyClaim" TypeName="SPCecil.Connect.MyClaimsDataModel.MyClaim, MyClaimsDataModel">
<TypeDescriptors>
<TypeDescriptor Name="Identifier" TypeName="System.String" IdentifierName="Identifier" />
<TypeDescriptor Name="ClaimType" TypeName="System.String" DefaultDisplayName="Claim Type" />
<TypeDescriptor Name="Value" TypeName="System.String" />
<TypeDescriptor Name="ValueType" TypeName="System.String" DefaultDisplayName="Claim Value Type" />
<TypeDescriptor Name="Issuer" TypeName="System.String" />
<TypeDescriptor Name="OriginalIssuer" TypeName="System.String" DefaultDisplayName="Original Issuer" /></TypeDescriptors></TypeDescriptor></TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Type="Finder" ReturnParameterName="returnParameter" Default="true" Name="ReadList" DefaultDisplayName="All my claims" />
</MethodInstances>
</Method>
<!-- end finder method-->
<!-- start specific finder method-->
<Method Name="ReadItem">
<Parameters>
<Parameter Direction="In" Name="id">
<TypeDescriptor TypeName="System.String" IdentifierName="Identifier" Name="Identifier" />
</Parameter>
<Parameter Direction="Return" Name="returnParameter">
<TypeDescriptor TypeName="SPCecil.Connect.MyClaimsDataModel.MyClaim, MyClaimsDataModel" Name="MyClaim">
<TypeDescriptors>
<TypeDescriptor TypeName="System.String" IdentifierName="Identifier" Name="Identifier" />
<TypeDescriptor TypeName="System.String" Name="ClaimType" DefaultDisplayName="Claim Type" />
<!-- TODO: add typedescriptors when you add properties to entity1.-->
<TypeDescriptor Name="Value" TypeName="System.String" />
<TypeDescriptor Name="ValueType" TypeName="System.String" DefaultDisplayName="Claim Value Type" />
<TypeDescriptor Name="Issuer" TypeName="System.String" />
<TypeDescriptor Name="OriginalIssuer" TypeName="System.String" DefaultDisplayName="Original Issuer" /></TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Type="SpecificFinder" ReturnParameterName="returnParameter" Default="true" Name="ReadItem" DefaultDisplayName="Read my claim" />
</MethodInstances>
</Method>
<!-- end specific finder method-->
</Methods>
</Entity>
</Entities>
</LobSystem>
</LobSystems>
</Model>
After deploying a solution containing these artifacts, you should be able to see the model in Central Administration, if you provider the appropriate permissions to the model in Certral Administration the model should work just fine.

Trackback
by MAX
10 Dec 2011 at 09:27
doses@of.seroquel.xr.taken.too.close.together” rel=”nofollow”>.…
Buygeneric pills…
Trackback
by JEREMY
11 Dec 2011 at 16:17
best@medicare.plan.d.for.nexium.40.mg” rel=”nofollow”>..…
Buygeneric meds…
Trackback
by HARRY
11 Dec 2011 at 20:31
infant@prevacid.dose” rel=”nofollow”>.…
Buygeneric drugs…