2012-02-15 3 views
3

지금까지 SabreDAV에서 ACL (사용 권한)을 성공적으로 구현할 수 없었습니다.SabreDAV PHP 서버에서 CalDAV 용 사용자 지정 ACL을 구현하는 방법

필자는 Auth, Principal 및 CalDAV 백엔드를 사용하여 코드 이그니 터에서 SabreDAV를 구현했습니다. 컨트롤러에서이 실제 코드 :

구현 권한에서 나의 현재 시도 내 사용자 지정 ACL 플러그인을 완료 한
<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class CalDAV extends CI_Controller { 

    public function _remap() { 
     $this->load->library('SabreDAV'); 

     $authBackend = new SabreDAV_DAV_Auth_Backend_Tank_Auth; 
     $principalBackend = new Sabre_DAVACL_PrincipalBackend_Click4Time; 
     $calendarBackend = new Sabre_CalDAV_Backend_Click4Time; 

     // Directory tree 
     $tree = array(
      new Sabre_DAVACL_PrincipalCollection($principalBackend), 
      new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend) 
     );  

     // The object tree needs in turn to be passed to the server class 
     $server = new Sabre_DAV_Server($tree); 

     // You are highly encouraged to set your WebDAV server base url. Without it, 
     // SabreDAV will guess, but the guess is not always correct. Putting the 
     // server on the root of the domain will improve compatibility. 
     $server->setBaseUri('/caldav/'); 

     // Authentication plugin 
     $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend, 'SabreDAV'); 
     $server->addPlugin($authPlugin); 

     // CalDAV plugin 
     $caldavPlugin = new Sabre_CalDAV_Plugin(); 
     $server->addPlugin($caldavPlugin); 

     // ACL plugin 
     $aclPlugin = new Sabre_DAVACL_Custom; 
     $server->addPlugin($aclPlugin); 

     // Support for html frontend 
     $browser = new Sabre_DAV_Browser_Plugin(); 
     $server->addPlugin($browser); 

     $server->exec(); 
    } 
} 

: 사용자에게 권한을 부여해야 두 번째 검사를 제외하고

<?php 

class Sabre_DAVACL_Custom extends Sabre_DAVACL_Plugin { 

    public $allowAccessToNodesWithoutACL = false; 

    private function _getCurrentUserName() { 
     $authPlugin = $this->server->getPlugin('auth'); 
     if (is_null($authPlugin)) return null; 

     return $authPlugin->getCurrentUser(); 
    } 

    public function getACL($node) { 
     $user = $this->_getCurrentUserName(); 
     $path = $node->getName(); 

     if ($path == 'calendars' || $path == 'principals' || $path == 'root') { 
      return array(
       array(
        'privilege' => '{DAV:}read', 
        'principal' => 'principals/' . $user, 
        'protected' => true, 
       ) 
      ); 
     } 
     else if ($path == 'calendars/' . $user) { 
      return array(
       array(
        'privilege' => '{DAV:}read', 
        'principal' => 'principals/' . $user, 
        'protected' => true, 
       ) 
      ); 
     } 

     return array(); 
    } 
} 

이 코드는 꽤 많은 작품 자신의 캘린더를 볼 수 있습니다. $ 노드의 전체 경로 이름을 가져올 수 없습니다.

이것은 구현하는 데 잘못된 방법 일 수 있지만 ACL을 구현하는 방법임을 확인하기 위해 문서를 찾을 수 없습니다.

+0

http://code.google.com/p/sabredav/wiki/ACL#Setting_up ACL 지원에 따라 새로운이며 일하러 생성하는 사용자 정의 노드를 필요로한다. –

답변

3

나는 다른 시도를 사용하고 있습니다. 플러그인을 확장했는데, 그랬던 것처럼, 대신 getSupportedPrivilegeSet($node)을 교체했습니다. 이 내 전류가

class DavCalAcl extends \Sabre\DAVACL\Plugin { 

public function getSupportedPrivilegeSet($node) {  
    if (is_string($node)) { 
     $node = $this->server->tree->getNodeForPath($node); 
    } 

    if($node instanceof \Sabre\CalDAV\Calendar || $node instanceof \Sabre\CalDAV\CalendarObject) { 
     return array(
      array(
       'privilege' => '{DAV:}read', 
       'aggregates' => array(
        array(
         'privilege' => '{DAV:}read-acl', 
         'abstract' => true, 
        ), 
        array(
         'privilege' => '{DAV:}read-current-user-privilege-set', 
         'abstract' => true, 
        ), 
       ), 
      ) 
     ); 
    } 

    if ($node instanceof \Sabre\DAVACL\IACL) { 
     $result = $node->getSupportedPrivilegeSet(); 
     if ($result) 
      return $result; 
    } 

    return self::getDefaultSupportedPrivilegeSet(); 
} 

} 

입니다 :

public function getSupportedPrivilegeSet($node) { 

    if (is_string($node)) { 
     $node = $this->server->tree->getNodeForPath($node); 
    } 

    if ($node instanceof IACL) { 
     $result = $node->getSupportedPrivilegeSet(); 

     if ($result) 
      return $result; 
    } 

    return self::getDefaultSupportedPrivilegeSet(); 

} 

지금 당신 대신 내가 더 유용한 발견 경로, 즉의 클래스를 사용할 수 있습니다 sabredav에서

은 다음과 같습니다 1.8.6 읽기 전용으로 캘린더를 인식하도록 iCal을 시도하십시오. 아직 없습니다.하지만 이것은 객체를 더 잘 식별하는 데 도움이됩니다.

노드의 절대 경로를 원한다면 나는 당신이 항상 당신의 현재 노드에 대한 루트 검색을 할 수 있었고 거기에 당신을 데려다 준 경로를 기록함으로써 그렇게 할 수 있다고 생각합니다. 늘어나는만큼 sabredav에서 노드를 확인 부모 또는 루트 속성을 지원하지 않습니다.

은 [업데이트]를

가장 좋은 방법은 플러그인에 getACL을 재정의 할 것으로 보인다. 여기에서 노드의 클래스를 테스트하고 기본 객체에서 반환되는 내용 대신 실제로 원하는 내용을 반환 할 수 있습니다 (예를 들어 UserCalendars-> getACL()을 참조하십시오.)

읽기 전용 객체 유형에 따라 집행 :

class DavCalAcl extends \Sabre\DAVACL\Plugin { 

    /** 
    * Returns the full ACL list. 
    * 
    * Either a uri or a DAV\INode may be passed. 
    * 
    * null will be returned if the node doesn't support ACLs. 
    * 
    * @param string|DAV\INode $node 
    * @return array 
    */ 
    public function getACL($node) { 

     if (is_string($node)) { 
      $node = $this->server->tree->getNodeForPath($node); 
     } 
     if (!$node instanceof \Sabre\DAVACL\IACL) { 
      return null; 
     } 

     if($node instanceof \Sabre\CalDAV\Calendar || 
      $node instanceof \Sabre\CalDAV\CalendarObject || 
      $node instanceof \Sabre\CalDAV\UserCalendars 
     ) { 
      $acl = array(
       array(
        'privilege' => '{DAV:}read', 
        'principal' => $node->getOwner(), 
        'protected' => true, 
       ), 
      ); 
     } else { 
      $acl = $node->getACL();   
     } 

     foreach($this->adminPrincipals as $adminPrincipal) { 
      $acl[] = array(
       'principal' => $adminPrincipal, 
       'privilege' => '{DAV:}all', 
       'protected' => true, 
      ); 
     } 
     return $acl; 

    } 
} 
관련 문제