【发布时间】:2013-04-29 19:56:46
【问题描述】:
谁能告诉我有关如何为 WCF 数据服务定义 XACML 拦截器的信息?
【问题讨论】:
谁能告诉我有关如何为 WCF 数据服务定义 XACML 拦截器的信息?
【问题讨论】:
WCF 数据服务的拦截器本质上是 Expression<Func<T, bool>> 类型的 lambda 表达式,用于您的数据源 (more about interceptors) 中的每个实体,这将您限制为非常简单且几乎是静态的授权规则。另一方面,XACML 是非常灵活和动态的授权解决方案。我想不出可能的通用集成方式。同时非泛型集成非常简单:
[QueryInterceptor ("Customers")]
public Expression<Func<Customer, bool>> FilterCustomers()
{
// First of all you need to get all request attributes
// information could come from session, from cookies
// from request, in this example I will only use subjectId
// In XACML subjectId could be user name
var subjectId = GetSubjectId();
// After you have all data, build XACML request
// this code is specific to our XACML implementation
var xacmlRequest = new XacmlDecisionRequestContext()
.AddRequest(r => r
.AddResource(a => a.Add(XacmlConstants.ResourceAttributes.ResourceId, new Uri("Customer", UriKind.RelativeOrAbsolute)))
.AddSubject(a => a.Add(XacmlConstants.SubjectAttributes.SubjectId, subjectId ))
);
// Evaluate request
var result = PolicyDecisionPoint.Evaluate(xacmlRequest);
// Based on XACML decision result you can construct expression
// this example is simple true or false, but based on
// XACML Advices or XACML Attributes you can build much more
// sophisticated expression
if (result.Decisions.Single().Decision == XacmlDecision.Permit)
{
return () => true;
}
return () => false;
}
本示例假设您拦截了对客户实体的访问。它仅适用于查询。您应该将此方法放在您的 DataService 类中。
示例基于 Axiomatics PEP SDK for .NET(我正在开发此产品),但想法适用于任何 XACML 实现。
【讨论】:
Expression<Func<Customer, bool>>,它实际上代表了 XACML 策略。对于这种情况,我们建议拦截on lower level。简而言之,它将 SQL 查询更改为包含条件。理论上相同的想法适用于Expression<Func<T, bool>>。