【发布时间】:2011-03-31 22:57:48
【问题描述】:
我正在与Azure ACS Labs 合作,他们使用FederatedServiceCredentials 对Active Federation 的用户进行身份验证。现在我想从 WCF 服务中访问用户的声明。
根据this article,声明由请求线程访问...谁能解释或证明这是什么意思?
【问题讨论】:
标签: wcf azure claims-based-identity federated-identity wif
我正在与Azure ACS Labs 合作,他们使用FederatedServiceCredentials 对Active Federation 的用户进行身份验证。现在我想从 WCF 服务中访问用户的声明。
根据this article,声明由请求线程访问...谁能解释或证明这是什么意思?
【问题讨论】:
标签: wcf azure claims-based-identity federated-identity wif
请求线程是在服务器上执行服务 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;
}
}
【讨论】: