[英]Access WSO2IS XACML policy with API created in WSO2 API manager. Unable to access XACML policy
[英]REST API with WSO2 IS and XACML Policy
我們將WSO2 IS用作我們解決方案的身份總線。 我們使用WSO2 ESB和EI來實現集成,並使用OAuth中介程序將API從EI連接到IS。 在EI中一切正常,但是我們希望創建一個XACML策略來同時執行兩種限制。 首先,根據可以在XACML中進行硬編碼或另存為用戶聲明中的屬性的URI授權用戶。 其次,根據用戶的原始IP授權用戶,我的意思是想象每個用戶都將其IP保存在其聲明中,然后我們檢查調用者IP以匹配用戶IP。
我們在WSO2-ESB中創建REST API以實現我們的集成,並在其中使用OAuth中介程序來保護我們的API。 在WSO2-IS中,我們將服務提供者創建為sp1
並將XACML策略應用於該服務提供者。 我想創建XACML策略,以僅在client_ip is xxx.xxx.xxx.xxx
且request URI is http://wso2ESB.uri/sampleApi/app
且method is GET
時才允許傳入請求。
注意 :從索賠中讀取值並不是什么大問題!
請參閱WSO2文檔的“為服務提供者配置訪問控制策略”部分,以為服務提供者啟用基於XACML的訪問控制。 您需要在服務提供商的“本地和出站身份驗證配置”下啟用“啟用授權”,並配置XACML策略。
(在策略中,因為您希望將URI和IP作為用戶聲明,然后創建兩個新聲明。假設http://wso2.org/claims/uri和http://wso2.org/claims/ip )
然后更改提供的政策以檢查這些聲明,
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">APP_NAME</AttributeValue>
<AttributeDesignator AttributeId="http://wso2.org/identity/sp/sp-name" Category="http://wso2.org/identity/sp" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
</Match>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">authenticate</AttributeValue>
<AttributeDesignator AttributeId="http://wso2.org/identity/identity-action/action-name" Category="http://wso2.org/identity/identity-action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
</Target>
<Rule Effect="Permit" RuleId="permit_by_uri_and_ip">
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-is-in">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">URI</AttributeValue>
<AttributeDesignator AttributeId="http://wso2.org/claims/uri" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
</Apply>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-is-in">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">IP</AttributeValue>
<AttributeDesignator AttributeId="http://wso2.org/claims/ip" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
</Apply>
</Apply>
</Condition>
</Rule>
<Rule Effect="Deny" RuleId="deny_others"/>
</Policy>
然后發布策略。 您還可以參考“在WSO2 Identity Server中編寫XACML3策略”以了解有關編寫XACML策略的知識。
關於第二個需求,您可以通過在主題類別中指向IP地址來定義XACML策略(因為IP地址可以從用戶配置文件中檢索到)。 默認情況下,WSO2 Identity Server PIP(策略信息點)是下划線用戶存儲。 XACML請求僅包含用戶名,而XACML策略包含IP地址,因此PIP解析給定用戶的IP地址。
XACML政策
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="TestPolicy" 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">192.168.1.1</AttributeValue> <AttributeDesignator AttributeId="http://wso2.org/claims/ipAddress" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator> </Match> </AllOf> </AnyOf> </Target> <Rule Effect="Permit" RuleId="Rule-1"> <Target> <AnyOf> <AllOf> <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">test-resource</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"></AttributeDesignator> </Match> </AllOf> </AnyOf> <AnyOf> <AllOf> <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">POST</AttributeValue> <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"></AttributeDesignator> </Match> </AllOf> </AnyOf> </Target> </Rule> <Rule Effect="Deny" RuleId="Deny-Rule"></Rule> </Policy>
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false"> <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"> <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="false"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">test-resource</AttributeValue> </Attribute> </Attributes> <Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"> <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="false"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">gboss</AttributeValue> </Attribute> </Attributes> <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"> <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">POST</AttributeValue> </Attribute> </Attributes> </Request> [![enter image description here][1]][1]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.