WSO2 XACML动态属性值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WSO2 XACML动态属性值相关的知识,希望对你有一定的参考价值。

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

User Country
1   India
2   US
3   UK
4   Australia

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

谢谢Priyanka Goel

答案

所以你说你试图访问一个页面,该页面属于一个国家。你是说:

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

如果这确实是正确的,则授权策略非常简单。以下是使用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>

以上是关于WSO2 XACML动态属性值的主要内容,如果未能解决你的问题,请参考以下文章

WSO2 身份服务器 XACML JSON 请求导致“不确定”[找不到 AttributeDesignator 属性]

是否可以使用 WSO2 API Manager 1.7.0 使用 PIP 点启用细粒度 XACML 授权

XACML 策略 - 获得“不确定”响应

WSO2 身份服务器 GUI 为策略和请求创建不同的属性 ID

XACML学习

XACML 政策 - 是不是正确?