2014-09-07 2 views
1

내 응용 프로그램 계층에 대한 ACL을 필요로하고 나는 내 요구를 커버하는 것 젠드 ACL에 찾아 봤는데하지만 난 다음 [1]에 의해 혼동 해요 :젠드 ACL 및 특정 개체에 대한 액세스는

예를 들어 도시의 각 건물에 기본 규칙을 적용하려면 대신 각 건물에 동일한 규칙을 할당하는 대신 규칙을 도시에 할당하면됩니다. 그러나 일부 건물에서는 이러한 규칙에 대한 예외가 적용되어 예외가 필요할 수 있으며 이러한 예외 규칙을 이러한 예외가 필요한 각 건물에 할당하여 Zend\Permissions\Acl\Acl에서 수행 할 수 있습니다.

정확히 내가 필요로하는 것. 그러나, 어떻게 이것을 수행합니까?

Zend ACL에 대한 설명서를 읽었을 때부터 실제로이 예제를 찾을 수 없습니다. 따라서 CityBuilding 리소스가 있고 각각 ResourceInterface을 구현한다고 가정 해 보겠습니다. 다음과 같은 내용 :

class City implements ResourceInterface { 

    public function getResourceId() 
    { 
     return "city"; // Is this supposed to be the "type" or the "unique Id"? 
    } 

    public $buildings = array(); 

} 

class Building implements ResourceInterface { 

    public function getResourceId() 
    { 
     return "building"; // Again, the "type" or "unique Id"? 
    } 

} 

위 코드의 주석은 이미 명확하게 표시되어있을 수 있으므로 자원 ID는 무엇입니까? 이것이 도시 또는 건물 인 '유형'을 나타내는가, 아니면 고유 한 ID, 즉 '도시 1'등이되어야합니까?

대답이 "유형"이어야 할 경우 질문이됩니다. 독특한 건물을 어떻게 지정합니까? 그러나 ID가 고유해야한다고 대답하면 질문이됩니다. 문서의 인용문에 명시된 바와 같이 자원의 "유형"을 식별하고 각 건물에 "담요"권한을 부여하는 방법은 무엇입니까?

모든 통찰력을 주시면 감사하겠습니다.

[1] http://zf2.readthedocs.org/en/latest/modules/zend.permissions.acl.intro.html

+0

은 어쩌면 도움이 될 수 있습니다 충분한 샘플을 희망 : http://stackoverflow.com/questions/11668785/zend-acl-dynamic-assertion이 예를 들어 있습니다. –

답변

2

resource Id 요구 고유 값한다. 전역 규칙을 할당하려면 자원에 대해 상속을 사용해야합니다. 간단하게 city 리소스를 building 리소스의 부모로 전달해야합니다. 리소스를 acl에 추가 할 때 간단합니다. 아무것도 그것을 위해 정의되지 않은 경우

$acl = new Acl(); 

//the original Acl resource class takes a `resourceId` as constructor parameter 
$mycity1 = new Resource('mycity1'); 
$acl->addResource($mycity1); 

$mybuiding1 = new Resource('mybulding1'); 
//city is the buildings parent 
$acl->addResource($mybuiding1,$mycity1); 

//you dont even have to create a class just define the resource as string 
$acl->addResource('secure_buildings',$mycity1); 

$acl->addRole('myrole1'); 
//roles have inheritance too 
$acl->addRole('myrole2','myrole1'); 

//myrole1 and myrole2 has access to city and all its building 
$acl->allow('myrole1','mycity1'); 
//myrole2 has access to city and all its building except 'secure_buildings' 
$acl->deny('myrole2','secure_buildings'); 

자식 자원 bulding 부모 city에서 규칙을 상속 : 여기

는 샘플입니다. 코멘트

UPDATE :

ACL 모르는 그들 고유 자원 식별자, ACL 위협 동일한 모든 자원을 가지고 만 resourceId 및 상속을 찾습니다 당신이 오랫동안 가지고있는 자원 유형에 상관하지 않는다. 당신이 규칙을 정의 할 때

당신이 아니라, 그들이 자원으로 정의하고, ACL의 스택에 추가로 그들이 한 어떤 유형의 문제가되지 않습니다 allowdeny에 대한 resourceId를 제공해야합니다.

은 당신이 $acl->inAllowed 할 때 당신은 단지 그들이 그들이 부모가 없거나하는 자원 ABD로 정의 된 경우에만 것으로, 자신의 유형에 대해 상관하지 않는다 ACL 다시 roleIdresourceId 필요 ...

샘플 :이

$acl = new Acl(); 
$acl->addResource('City'); //all the cities 
$acl->addResource('myCity1', 'City'); //city1 inherits City 
$acl->addResource('Building', 'City'); //all the buildings in all the cities 
$acl->addResource('normal_buildings', 'Building'); 
$acl->addResource('secure_buildings', 'Building'); 
$acl->addResource('top_secure_buildings', 'secure_buildings'); 

$acl->addRole('Civilian'); 
$acl->addRole('High_Level_Security', 'Civilian'); 

$acl->allow('Civilian', 'City'); 
$acl->deny('Civilian', 'secure_buildings'); 

$acl->allow('High_Level_Security', 'secure_buildings'); 
$acl->deny('High_Level_Security', 'top_secure_buildings'); 

var_dump($acl->isAllowed('Civilian', 'City'));//true -> direct allow rule 
var_dump($acl->isAllowed('Civilian', 'myCity1'));//true -> inherited from City allow rule 
var_dump($acl->isAllowed('Civilian', 'Building'));//true -> inherited from City allow rule 
var_dump($acl->isAllowed('Civilian', 'normal_buildings'));//true -> inherited from City allow rule 
var_dump($acl->isAllowed('Civilian', 'secure_buildings'));//false -> direct deny rule 
var_dump($acl->isAllowed('Civilian', 'top_secure_buildings'));//false -> inherited from secure_building deny rule 

var_dump($acl->isAllowed('High_Level_Security', 'City'));//true -> inherited from Civilian->City allow rule 
var_dump($acl->isAllowed('High_Level_Security', 'myCity1'));//true -> inherited from Civilian->City allow rule 
var_dump($acl->isAllowed('High_Level_Security', 'Building'));//true -> inherited from Civilian->City allow rule 
var_dump($acl->isAllowed('High_Level_Security', 'normal_buildings'));//true -> inherited from Civilian->City allow rule 
var_dump($acl->isAllowed('High_Level_Security', 'secure_buildings'));//true -> direct allow rule 
var_dump($acl->isAllowed('High_Level_Security', 'top_secure_buildings'));//false -> direct deny rule 
+0

이 샘플을 사용하여 답변을 업데이트했으며 오픈 소스에서 Zend가 실제로 소스 코드를 확인하여 무슨 일이 일어 났는지 알 수 있습니까? 권리 ? 코드를 확인하면 acl이 어떤 유형의 리소스인지 알 수 없으며 리소스에 직접 규칙이없는 경우 부모를 확인하는 등의 작업을 수행합니다 ... – Exlord

+0

마지막 업데이트가 이제 합리적입니다. . 당신의 도움을 주셔서 감사합니다. – Luke