WSO2 XACML 动态属性值
WSO2 XACML dynamic attribute value
我想在 Wso2 身份服务器中编写 XACML,如果用户属于该国家/地区,我想授权用户访问国家/地区页面 http://localhost:8080/Country_name。
User Country
1 India
2 US
3 UK
4 Australia
并且用户国家映射是从 UI(Web 应用程序的)添加的。现在,如果用户 2 登录,它应该无法访问除美国以外的其他国家/地区页面
谢谢
朴雅卡·戈尔
所以你是说你正在尝试访问一个页面,而该页面属于一个国家。你是说:
- 如果用户与页面属于同一国家/地区,则该用户可以查看该页面。
如果这确实是正确的,授权策略就很简单了。这是使用 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,如果用户属于该国家/地区,我想授权用户访问国家/地区页面 http://localhost:8080/Country_name。
User Country
1 India
2 US
3 UK
4 Australia
并且用户国家映射是从 UI(Web 应用程序的)添加的。现在,如果用户 2 登录,它应该无法访问除美国以外的其他国家/地区页面
谢谢 朴雅卡·戈尔
所以你是说你正在尝试访问一个页面,而该页面属于一个国家。你是说:
- 如果用户与页面属于同一国家/地区,则该用户可以查看该页面。
如果这确实是正确的,授权策略就很简单了。这是使用 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>