• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/service/accessService.php

00001 <?php
00017 /* configuration
00018 <PluginService ...>
00019    <access-constraint>
00020      <view-collection>
00021        <view name="view1">
00022          <role name="admin"/>
00023          <role name="member"/>
00024        </view>
00025        <view name="reg_expr"/>
00026      </view-collection>
00027    </access-constraint>
00028 </PluginService ...>
00029 */
00030 
00039 class accessService
00040 {
00041     private $_configFile = "accessService.xml";
00042     private $_restrictedViewList;
00043 
00050     function __construct(&$xmlArr)
00051     {
00052         $this->readMetadata($xmlArr);
00053     }
00054 
00061     protected function readMetadata(&$xmlArr)
00062     {
00063         $viewCollection = $xmlArr["PLUGINSERVICE"]["ACCESS-CONSTRAINT"]["VIEW-COLLECTION"];
00064         $this->_restrictedViewList = new MetaIterator($xmlArr["PLUGINSERVICE"]["ACCESS-CONSTRAINT"]["VIEW-COLLECTION"]["VIEW"],"RestrictedView");
00065     }
00066 
00074     public function allowViewAccess($viewName, $role=null)
00075     {
00076         if (!$role)
00077             $role = "";
00078 
00079         $view = $this->getMatchView($viewName);
00080         if (!$view)
00081             return true;
00082 
00083         $roleList = $view->getRoleList();
00084         if (!$roleList)
00085             return true;
00086         if ($roleList->get($role))
00087             return true;
00088 
00089         return false;
00090     }
00091 
00098     protected function getMatchView($viewName)
00099     {
00100         /* @var $viewObj EasyView */
00101         $viewObj = $this->_restrictedViewList->get($viewName);
00102         if ($viewObj)
00103             return $viewObj;
00104         foreach ($this->_restrictedViewList as $view => $viewObj)
00105         {
00106             $preg_view = "/".$view."/";
00107             if (preg_match($preg_view, $viewName))
00108             {
00109                 return $viewObj;
00110             }
00111         }
00112         return null;
00113     }
00114 }
00115 
00124 class RestrictedView
00125 {
00131     public $m_Name;
00132 
00138     private $_roleList;
00139 
00140 
00147     public function __construct($xmlArr)
00148     {
00149         $this->m_Name = $xmlArr["ATTRIBUTES"]["NAME"];
00150         $this->_roleList = new MetaIterator($xmlArr["ROLE"],"RestrictedRole");
00151     }
00152 
00158     public function getViewName()
00159     {
00160         return $this->m_Name;
00161     }
00162 
00168     public function getRoleList()
00169     {
00170         return $this->_roleList;
00171     }
00172 }
00173 
00174 
00183 class RestrictedRole
00184 {
00190     public $m_Name;
00191 
00198     public function __construct($xmlArr)
00199     {
00200         $this->m_Name = $xmlArr["ATTRIBUTES"]["NAME"];
00201     }
00202 
00208     public function getRoleName()
00209     {
00210         return $this->m_Name;
00211     }
00212 }
00213 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2