【问题标题】:XACML interceptor for WCF Data Services用于 WCF 数据服务的 XACML 拦截器
【发布时间】:2013-04-29 19:56:46
【问题描述】:

谁能告诉我有关如何为 WCF 数据服务定义 XACML 拦截器的信息?

【问题讨论】:

    标签: wcf-data-services xacml


    【解决方案1】:

    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 实现。

    【讨论】:

    • 此级别的拦截器不提供基于属性的访问控制 (ABAC)。这意味着您可以限制对特定集合的访问,但不能限制对该集合中的实体的访问。
    • 你是对的,WCF 中没有扩展点提供单个位置来检查单个条目是否允许访问。这是一个很好的理由。它会很慢(选择 n+1 问题)。所以最后你应该有Expression&lt;Func&lt;Customer, bool&gt;&gt;,它实际上代表了 XACML 策略。对于这种情况,我们建议拦截on lower level。简而言之,它将 SQL 查询更改为包含条件。理论上相同的想法适用于Expression&lt;Func&lt;T, bool&gt;&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多