首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XACML策略-正确吗?

XACML策略-正确吗?
EN

Stack Overflow用户
提问于 2013-03-01 16:41:03
回答 2查看 1.7K关注 0票数 3

我有一个关于WSO2 Balana库使用的XACML策略的问题。

有一项政策:

代码语言:javascript
复制
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="Policy1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" Version="1.0">
    <Target>
        <AnyOf>
            <AllOf>
                <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                    <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">MyApp</AttributeValue>
                    <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 
                                    Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                </Match>            
            </AllOf>
        </AnyOf>
    </Target>
    <Rule Effect="Permit" RuleId="RuleFor_user1_myapp">
        <Target>
            <AnyOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">user1</AttributeValue>
                        <AttributeDesignator AttributeId="http://example.site.com/id/user" 
                                       Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" 
                                       DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                    </Match>
                </AllOf>           
            </AnyOf>
        </Target>
        <Apply  FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
            <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">READ</AttributeValue>                                
            </Apply>
            <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
        </Apply>
    </Rule>   
</Policy>   

它应该定义user1在MyApp上只有读权限。

我有一个评估请求,它询问user1是否具有读取权限,并且我在响应中得到了"Permit“,这是OK。

但是,当我请求评估user1是否具有写权限时,我得到的也是“许可”,而不是“不适用”。

谁能告诉我,这项政策是否正确,才能产生我刚才所描述的结果?

提前谢谢你!

致以最好的问候,尤里卡·克里扎尼克

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-02 12:34:17

您可以使用http://validator.xacml.eu/来验证您的XACML策略是否符合XACML2.0或XACML3.0。

此外,我建议您使用ALFA来编写策略-它更容易,而且它与Eclipse集成在一起。

ALFA代码如下所示:

代码语言:javascript
复制
namespace sample{
    // Import standard XACML attributes
    import Attributes.*

    /**
     * Define custom attributes here
     */
    attribute user{
        category = subjectCat
        id = "http://example.site.com/id/user"
        type = string
    }

    /**
     * MyApp Policy
     */
    policy Policy1{
        target clause resourceId=="MyApp"
        apply firstApplicable
        /**
         * This rule grants READ access for user 1
         */
        rule RuleFor_user1_myapp{
            target clause user=="user1" and actionId=="READ"
            permit
        }
    }
}

生成的XACML 3.0如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
 <!--This file was generated by the ALFA Plugin for Eclipse from Axiomatics AB (http://www.axiomatics.com). 
 Any modification to this file will be lost upon recompilation of the source ALFA file-->
<xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
    PolicyId="http://axiomatics.com/alfa/identifier/sample.Policy1"
    RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
    Version="1.0">
    <xacml3:Description>MyApp Policy</xacml3:Description>
    <xacml3:PolicyDefaults>
        <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion>
    </xacml3:PolicyDefaults>
    <xacml3:Target>
        <xacml3:AnyOf>
            <xacml3:AllOf>
                <xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                    <xacml3:AttributeValue
                        DataType="http://www.w3.org/2001/XMLSchema#string">MyApp</xacml3:AttributeValue>
                    <xacml3:AttributeDesignator 
                        AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
                        DataType="http://www.w3.org/2001/XMLSchema#string"
                        Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                        MustBePresent="false"
                    />
                </xacml3:Match>
            </xacml3:AllOf>
        </xacml3:AnyOf>
    </xacml3:Target>
    <xacml3:Rule 
            Effect="Permit"
            RuleId="http://axiomatics.com/alfa/identifier/sample.Policy1.RuleFor_user1_myapp">
        <xacml3:Description>This rule grants READ access for user 1</xacml3:Description>
        <xacml3:Target>
            <xacml3:AnyOf>
                <xacml3:AllOf>
                    <xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">user1</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator 
                            AttributeId="http://example.site.com/id/user"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                            MustBePresent="false"
                        />
                    </xacml3:Match>
                    <xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">READ</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator 
                            AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
                            MustBePresent="false"
                        />
                    </xacml3:Match>
                </xacml3:AllOf>
            </xacml3:AnyOf>
        </xacml3:Target>
    </xacml3:Rule>
</xacml3:Policy>
票数 3
EN

Stack Overflow用户

发布于 2013-03-01 20:03:45

首先,策略不是具有XACML3模式的有效策略。您需要在规则中包含由Apply元素包围的元素。规则基本上包含Target和Condition元素。Balana没有使用您的策略进行模式验证。它使用策略元素来构建对象模块。因为它在规则中找不到元素,所以它忽略了您的元素。因此,您的Rule实际上只有一个目标元素,该元素只计算subject属性。请按如下方式使用。此外,当您将策略上载到WSO2 Identity server时,它还会执行模式验证。您可以使用它轻松上传或创建策略。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15153654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档