Using IdentityModel: Some Samples
Here are some typical usage scenario of IdentityPrincipal in ASP.NET.
Simple IsInRole calls (checks for a status claim with a value of 'Gold'):
HttpContext.Current.User.IsInRole("Gold");
Retrieving the OrderHistory claim:
IdentityPrincipal ip = IdentityPrincipal.Current; Claim orderHistory = ip.ClaimSets.FindClaim( Constants.OrderHistoryClaimType, Constants.ApplicationIssuerIdentityClaim); var orders = orderHistory.Get<List<OrderDetail>>();
..or some authorization code from my CardSpace sample app - thanks to the unified authorization model, I can share this method across ASP.NET, ASMX and WCF:
public static IEnumerable<MessageBoard> GetBoardsForUser( AuthorizationContext context, bool includePublic) { List<MessageBoard> boards = new List<MessageBoard>();
foreach (Claim typeClaim in context.ClaimSets.FindClaims( AppClaims.UserTypeClaim, new ApplicationIssuerClaimSet())) { string type = typeClaim.Get<string>(); if ("Public".Equals(type) && includePublic == false) continue;
boards.AddRange(GetBoards(type)); }
return boards; }
I have updated the source download here to include a console, WCF and ASP.NET test app that share the same authorization model. ASP.NET | CardSpace | IdentityModel | WCF
3/22/2008 1:54:39 PM UTC
|