【问题标题】:WSO2 XACML dynamic attribute valueWSO2 XACML 动态属性值
【发布时间】:2018-08-14 03:51:12
【问题描述】:

我想在 Wso2 身份服务器中编写 XACML,如果用户属于该国家/地区http://localhost:8080/Country_name,我想授权用户访问国家/地区页面。

User Country
1   India
2   US
3   UK
4   Australia

并且用户国家映射是从(Web 应用程序的)UI 添加的。现在如果用户 2 登录它应该无法访问美国以外的其他国家/地区页面

谢谢 普里扬卡·戈埃尔

【问题讨论】:

    标签: authorization access-control xacml abac alfa


    【解决方案1】:

    所以您是说您正在尝试访问一个页面并且该页面属于一个国家/地区。你是说:

    • 如果用户与页面属于同一国家/地区,则用户可以查看该页面。

    如果这确实是正确的,那么授权策略就很简单了。这是使用ALFA 的样子:

     /**
      * Control access to webpage
      */
     policy accessPage{
         target clause action_id == "view" and com.axiomatics.examples.objectType == "page"
         apply firstApplicable
         /**
          * Users can view a page if they are in the same country
          */
         rule allowSameCountry{
             permit
             condition user.country == page.country
         }
     }
    

    XACML (XML) 中如下所示:

    <?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/so.accessPage"
        RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
        Version="1.0">
        <xacml3:Description>Control access to webpage</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">view</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:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">page</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator 
                            AttributeId="com.axiomatics.examples.objectType"
                            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/so.accessPage.allowSameCountry">
            <xacml3:Description>Users can view a page if they are in the same country</xacml3:Description>
            <xacml3:Target />
            <xacml3:Condition>
                <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                    <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                    <xacml3:AttributeDesignator 
                        AttributeId="com.axiomatics.examples.user.country"
                        DataType="http://www.w3.org/2001/XMLSchema#string"
                        Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                        MustBePresent="false"
                    />
                    <xacml3:AttributeDesignator 
                        AttributeId="com.axiomatics.examples.page.country"
                        DataType="http://www.w3.org/2001/XMLSchema#string"
                        Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                        MustBePresent="false"
                    />
                </xacml3:Apply>
            </xacml3:Condition>
        </xacml3:Rule>
    </xacml3:Policy>
    

    【讨论】:

    • 谢谢,但我有两个疑问...1。给属性值不是必须的吗?在条件下你没有任何值。 2.如何在wso2中创建自定义属性id。
    • 不,您不需要在策略中使用值
    • 谢谢。我需要阅读更多关于 XACML3 的信息,但它对我有很大帮助。如果我理解正确,也请纠正我,我们可以使用 XACML 针对动态值验证规则,以及我们可以创建自定义属性,如“com.axiomatics.examples.page.country”
    • 是的,您可以使用动态值,例如user.country==page.country 或静态值,例如user.country=="冰岛"。而且您绝对可以创建自己的属性。
    • 使用 REST API 测试策略 'curl --request POST --url localhost:9443/api/identity/entitlement/decision/by-attrib --header 'accept: application/json' --header 'authorization: Basic YWRtaW46YWRtaW4=' --header 'content -type: application/json' --data '{"action":"read","re​​source":"localhost:9000/country","subject" : "Bob"}' -k' 。仍然不确定如何传递国家的价值,因为价值是 json web request 。我认为其中一种方法是 Xpath,但是 Web 请求以 xml 发送数据或服务器代码应将 json 请求更改为 XML 请求。请建议。
    猜你喜欢
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多