Changeset 3413

Show
Ignore:
Timestamp:
06/07/07 07:31:51 (3 years ago)
Author:
coolengineer
Message:

* Draft of ACL Components

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

Location:
trunk
Files:
2 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 
  • trunk/lib/auth.php

    r3376 r3413  
    2525            // 팀블로그 :: 로그인 인증 (팀원이 맞을 경우 admin 변수에 사용자의 userid 를 넣는다. 
    2626            $check = DBQuery::queryCell("SELECT teams FROM {$database['prefix']}Teamblog WHERE userid='{$session['userid']}' and teams='$owner'"); 
     27            if($owner == $session['userid']) { 
     28                Acl::setCurrentAro($owner, 'group.administrators', Aro::getCanonicalName($admin) ); 
     29            } else { 
     30                Acl::setCurrentAro($owner, 'group.members', Aro::getCanonicalName($admin) ); 
     31            } 
    2732            if(!empty($check)) authorizeSession($owner, $session['userid']); 
    2833            else return 2; 
     
    6368 
    6469function doesHaveMembership() { 
    65     return empty($_SESSION['userid']) ? false : true; 
     70    return Acl::check( "group.members" ); 
    6671} 
    6772 
     
    7984 
    8085function doesHaveOwnership() { 
    81     global $owner; 
    82     if (empty($_SESSION['userid']) || ($_SESSION['userid'] != $owner)) 
    83         return false; 
    84     return true; 
     86    return Acl::check( "group.administrators" ); 
    8587} 
    8688