2014-10-09 77 views

回答

3

你的用例很簡單。我建議你先寫英語ALFA:

  • 用戶可以對type==bank account資源做action==transfer當且僅當在amount transferred < the amount limit(如2000年的情況)==>許可證
  • 所有其他情況下==>否認

在ALFA,上述政策成爲

namespace policies{ 
    attribute actionId{ 
     category = actionCat 
     id = "actionId" 
     type = string 
    } 

    attribute resourceType{ 
     category = resourceCat 
     id = "resourceType" 
     type = string 
    } 

    attribute amount{ 
     category = resourceCat 
     id = "amount" 
     type = double 
    } 
    /** 
    * The limit could be a subject attribute in the case it's user-specific 
    */ 
    attribute limit{ 
     category = subjectCat 
     id = "limit" 
     type = double 
    } 

    /* 
    * A user can do the `action==transfer` on a resource of `type==bank account` if and only if the `amount transferred 
    * < the amount limit` (e.g. 2000 in your case) ==> **permit** 
    * 
    */ 
    policy transfer{ 
     target clause actionId == "transfer" and resourceType=="bank account" 
     apply firstApplicable 
     rule allow{ 
      condition amount <= limit 
      permit 
     } 
     rule denyTransfer{ 
      deny 
     } 
    } 
}