【问题标题】:What is the best way to modify Claims at Relying Party when using Windows Identity Foundation使用 Windows Identity Foundation 时修改依赖方声明的最佳方法是什么
【发布时间】:2012-01-25 01:04:17
【问题描述】:

目前我这样做是为了修改我在依赖方 Global.asax 中的角色声明。

void Application_AuthenticateRequest(object sender, EventArgs e) {
 if (Request.IsAuthenticated) {

   string[] roleListArray = Roles.GetRolesForUser(User.Identity.Name);
   IClaimsPrincipal claimsPrincipal = HttpContext.Current.User as IClaimsPrincipal;
   IClaimsIdentity claimsIdentity = (IClaimsIdentity)claimsPrincipal.Identity;
   var roleclaims = claimsIdentity.Claims.FindAll(c => c.ClaimType == ClaimTypes.Role);
   foreach (Claim item in roleclaims)
   {
     claimsIdentity.Claims.Remove(item);
   }

   foreach(string role in roleListArray)
   {
     claimsIdentity.Claims.Add(new Claim(ClaimTypes.Role, role));
   }

   HttpContext.Current.User = claimsPrincipal;

  }
}

这是正确的方法还是有更好的方法在 STS 成功认证后修改依赖方的声明?

【问题讨论】:

  • 您尝试过使用 ClaimsAuthenticationManager 吗?

标签: asp.net asp.net-mvc wif claims-based-identity


【解决方案1】:

【讨论】:

  • 所以基本上我将我的代码从 global.asax 中的 Authenticate 移到了 CustomModule 中的 Authenticate。它像上面的代码一样工作。在 ClaimsAuthenticationManager 中使用它可以获得什么真正的区别或好处。我看到的一件事是更好的可管理性,因为我将它放在一个单独的库中,但即使是常规的 HttpModule 也是如此,对吗?
猜你喜欢
  • 2013-08-02
  • 2011-04-19
  • 1970-01-01
  • 1970-01-01
  • 2012-08-13
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多