Show
Ignore:
Timestamp:
06/07/07 07:31:51 (19 months ago)
Author:
coolengineer
Message:

* Draft of ACL Components

#408
추후에 기존 소스를 계속 바꿔나가야함.
Teamblog의 path 기반 접근제한도 이것을 사용할 수 있을 듯.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/components/Textcube.Core.php

    r3383 r3413  
    1010    else 
    1111        return str_replace(array('%', ' ', '"', '#', '&', '\'', '<', '>', '?'), array('%25', '%20', '%22', '%23', '%26', '%27', '%3C', '%3E', '%3F'), $url); 
     12} 
     13 
     14/* Access Request Object: i.e. user */ 
     15class Aro { 
     16    var $_aro = array(  
     17        /* role => array( <available actions>, [<reference group>...] ) */ 
     18        'group.administrators' => array( 'blog-read', 'blog-write', 'blog-manage', 'comment-manage' ), 
     19        'group.blogwriters' => array( 'blog-read', 'blog-write' ), 
     20        'group.members' => array( 'comment-read', 'comment-writer' ), 
     21        'group.guests' => array( 'comment-read', 'comment-write' ) 
     22        ); 
     23 
     24    function Aro() { 
     25    } 
     26 
     27    function getCanonicalName( $userid ) { 
     28        return "textcube:$userid"; 
     29    } 
     30 
     31} 
     32 
     33/* Access Control Object: i.e. uri, component, function */ 
     34class Aco { 
     35    function Aco() { 
     36    } 
     37} 
     38 
     39class Acl { 
     40    function check($aco = null, $aco_action = '*') { 
     41        global $owner; 
     42 
     43        if( $aco == null ) { 
     44            if (empty($_SESSION['userid']) || ($_SESSION['userid'] != $owner)) 
     45                return false; 
     46            return true; 
     47        } 
     48 
     49        if( !Acl::isAvailable() )  { 
     50            return false; 
     51        } 
     52 
     53        if( !is_array( $aco ) ) { 
     54            $aco = array( $aco ); 
     55        } 
     56 
     57        foreach( $aco as $obj ) { 
     58            /*owner = blogid*/ 
     59            if( in_array( $obj, $_SESSION['acl'][$owner] ) ) { 
     60                return true; 
     61            } 
     62        } 
     63        return false; 
     64    } 
     65 
     66    function setCurrentAro( $blogid, $group, $user, $add = false ) { 
     67        if( !isset( $_SESSION['acl'] ) ) { 
     68            $_SESSION['acl'] = array(); 
     69        } 
     70        if( $add ) { 
     71            $_SESSION['acl'][$blogid] = array_merge( $_SESSION['acl'][$blogid], array( $group, $user ) ); 
     72        } else { 
     73            $_SESSION['acl'][$blogid] = array( $group, $user ); 
     74        } 
     75    } 
     76 
     77    function isAvailable() { 
     78        global $owner; /*blogid*/ 
     79 
     80        if( !isset( $_SESSION['acl'] ) ||  
     81            !is_array( $_SESSION['acl'] ) ||  
     82            !isset( $_SESSION['acl'][$owner] ) ) { 
     83            return false; 
     84        } 
     85 
     86        return true; 
     87    } 
    1288} 
    1389