2013-03-01 70 views
3

我對使用WSO2 Balana庫的XACML策略有疑問。XACML策略 - 是否正確?

有一個政策:

<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是否具有讀取權限,並且我在響應中獲得「許可」,這是確定的。

但是,當我有一個請求來評估詢問user1是否具有寫權限時,我還獲得「許可」,而不是「不適用」。

有人可以告訴我是政策是正確的,以產生我剛剛描述的結果嗎?

預先感謝您!

最好的問候, 尤里察Krizanic

回答

3

您可以使用http://validator.xacml.eu/來驗證您的XACML策略是符合XACML 2.0還是符合XACML 3.0。

此外,我建議您使用ALFA來編寫策略 - 這很容易,它與Eclipse集成。

的ALFA代碼如下所示:

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看起來像這樣:

<?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> 
+0

XACML驗證器網站不再工作。有沒有其他我可以使用的驗證器? – Ozkan 2016-02-09 18:37:20

+1

只需使用XACML 3.0模式和一個標準的XML驗證工具,例如Notepad ++或XML Spy ... – 2016-02-10 00:08:23

3

第一件事是,政策是不是一個有效的與XACML3架構。您需要在規則中包含Apply元素所包含的元素。規則基本上包含目標和條件元素。 Balana沒有對您的策略進行模式驗證。它使用策略元素構建對象模塊。由於它無法在規則中找到元素,因此它忽略了您的元素。所以你的規則實際上只有只評估主題屬性的目標元素。請使用如下。另外,當您將策略上傳到WSO2 Identity Server時,它會進行模式驗證。您可以輕鬆上傳或創建策略。

+0

感謝您指出了這一點。 – 2013-03-01 12:51:37