【问题标题】:Accessing claims via the security principal attached to the request thread, versus AuthorizationContext通过附加到请求线程的安全主体访问声明,而不是 AuthorizationContext
【发布时间】:2011-03-31 22:57:48
【问题描述】:

我正在与Azure ACS Labs 合作,他们使用FederatedServiceCredentials 对Active Federation 的用户进行身份验证。现在我想从 WCF 服务中访问用户的声明。

根据this article,声明由请求线程访问...谁能解释或证明这是什么意思?

【问题讨论】:

    标签: wcf azure claims-based-identity federated-identity wif


    【解决方案1】:

    请求线程是在服务器上执行服务 API 的线程。从该线程(也就是在您的服务 api 中),您可以访问 Thread.CurrentPrincipal.Identity。这将是一个 ClaimsIdentity,其中包含 STS 授予您的声明。例如:

     class MyService:IService
     {
       // code running on wcf server
       bool AdminOnlyApi()
       {    
         var identity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
    
         // fail all non admin callers.
         if (!identity.Claims.Exists(c=>c.ClaimType=="role" && c.Value=="Admin"))
         {
            throw new SecurityException("Access is denied.");
         }
         return True;
       }  
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2014-01-29
      相关资源
      最近更新 更多