2016-03-16 14 views
1

我想寫一條規則,使用條件語句構建一個 XACML函數:「urn:oasis:names:tc:xacml:2.0:function:time-in-範圍「使用ALFA語言語法。爲了方便義務處理,我寧願在條件函數中使用它,而不是在目標表達式中使用它。
這可能嗎?手冊中沒有提及它。XACML規則的時間範圍作爲條件

at @David Brossard。根據該協議在下面,我用下面的代碼ALFA測試的政策:

namespace com.ibm.XACML { 
import Attributes.* 
import attributes.* 
import com.ibm.XACML.Attributes.* 
    attribute currentTime { 
      id = "urn:oasis:names:tc:xacml:1.0:environment:current-time" 
      type = time 
      category = environmentCat 
     } 

function timeInRange = "urn:oasis:names:tc:xacml:2.0:function:time-in-range" : time time time -> boolean     
// lowerBound = "09:00:00-03:00" 
// upperBound = "18:00:00-03:00"  
// current-time = "02:00:00-03:00" decision permit 
// current-time = "10:00:00-03:00" decision permit 
// current-time = "22:00:00-03:00" decision permit  

policy checkTimeInRange{ 
    apply firstApplicable 
    rule allowWithinRange{ 
     permit 
     condition timeInRange(timeOneAndOnly(currentTime), timeOneAndOnly(timeBag("09:00:00-03:00":time)), timeOneAndOnly(timeBag("19:00:00-03:00":time))) 
     } 
    } 
} 

的語法驗證運行正常,但在評價結果從WSO2 PDP代碼返回一個錯誤,給人一種「證「對於所有三項測試,02:00:00,10:00:00和22:00:00。

我已經隔離了這個問題。 WSO2 Try-It工具默認生成「String」,而XACML需要時間數據類型。爲了解決這個問題,必須提供手動請求,@David Brossard顯示的邏輯完美運行。這裏有一個示例請求,生成一個「許可證」。

<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:environment"> 
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" IncludeInResult="false"> 
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">11:00:00-03:00</AttributeValue> 
</Attribute> 
</Attributes> 
</Request> 

將「TimeInRange」函數與條件語句相結合非常有用。

+0

你指的是什麼手冊? WSO2不支持ALFA ... –

+0

親愛的@David Brossard。參考.doc規範「用於ALFA語言的授權版本1.0的縮寫語言」,工作草案01.我正在ALFA eclipse代碼編輯器下重寫一些XACML策略。由於它支持常見的算法,比如布爾邏輯,條件的構建是有用的,它的程序員和代碼更友好。範圍函數中的時間將是有用的。 –

回答

1

XACML standard我可以讀

甕:綠洲:名稱:TC:XACML:2.0:功能:時間在範圍內

此功能應當採取數據 - 的三個參數請輸入time並返回boolean。如果第一個參數落在由第二個和第三個參數定義的範圍內,它將返回True。否則,它將返回「False」。

不管其值的,第三個參數將被解釋爲一個時間,該時間等於或晚於小於24小時,第二個參數。如果沒有爲第一個參數提供時區,則應在上下文處理程序中使用默認時區。如果第二個或第三個參數沒有提供時區,那麼他們應該使用第一個參數中的時區。

ALFA也具有該功能。它被定義爲

function timeInRange = "urn:oasis:names:tc:xacml:2.0:function:time-in-range" : time time time -> boolean 

要使用它,簡單地做:

policy checkTimeInRange{ 
    apply firstApplicable 
    rule allowWithinRange{ 
     permit 
     condition timeInRange(timeOneAndOnly(currentTime), timeOneAndOnly(lowerBound), timeOneAndOnly(upperBound)) 
    } 
} 

請注意,如果你缺少其中的任何值,則PDP將不確定回覆。

+0

以上發佈的ALFA代碼被認爲是有效的,但其仿真沒有返回WSO2 PDP下的預期結果。看到我的測試代碼發佈在初始部分。 –

+0

你得到了什麼錯誤?也許WSO2不支持時間 –