Changeset 560
- Timestamp:
- 08/30/07 00:25:43 (1 year ago)
- Files:
-
- trunk/build/manifests/jelix-lib.mn (modified) (3 diffs)
- trunk/build/manifests/jelix-lib.mn (modified) (3 diffs)
- trunk/lib/jelix-scripts/commands/aclgroup.cmd.php (modified) (5 diffs)
- trunk/lib/jelix-scripts/commands/aclgroup.cmd.php (modified) (5 diffs)
- trunk/lib/jelix-scripts/commands/aclright.cmd.php (modified) (6 diffs)
- trunk/lib/jelix-scripts/commands/aclright.cmd.php (modified) (6 diffs)
- trunk/lib/jelix-scripts/commands/aclvalue.cmd.php (modified) (6 diffs)
- trunk/lib/jelix-scripts/commands/aclvalue.cmd.php (modified) (6 diffs)
- trunk/lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl (modified) (1 diff)
- trunk/lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl (modified) (1 diff)
- trunk/lib/jelix/acl/jAcl.class.php (modified) (6 diffs)
- trunk/lib/jelix/acl/jAcl.class.php (modified) (6 diffs)
- trunk/lib/jelix/acl/jAclDb.class.php (added)
- trunk/lib/jelix/acl/jAclDb.class.php (added)
- trunk/lib/jelix/acl/jAclManager.class.php (modified) (6 diffs)
- trunk/lib/jelix/acl/jAclManager.class.php (modified) (6 diffs)
- trunk/lib/jelix/acl/jAclUserGroup.class.php (modified) (12 diffs)
- trunk/lib/jelix/acl/jAclUserGroup.class.php (modified) (12 diffs)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/errors.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core/defaultconfig.ini.php (modified) (1 diff)
- trunk/lib/jelix/core/defaultconfig.ini.php (modified) (1 diff)
- trunk/lib/jelix/plugins/acl (added)
- trunk/lib/jelix/plugins/acl (added)
- trunk/lib/jelix/plugins/acl/db (added)
- trunk/lib/jelix/plugins/acl/db (added)
- trunk/lib/jelix/plugins/acl/db/db.acl.php (added)
- trunk/lib/jelix/plugins/acl/db/db.acl.php (added)
- trunk/myapp/var/config/defaultconfig.ini.php.dist (modified) (1 diff)
- trunk/myapp/var/config/defaultconfig.ini.php.dist (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jacl.main_api.html.php (modified) (2 diffs)
- trunk/testapp/modules/jelix_tests/tests/jacl.main_api.html.php (modified) (2 diffs)
- trunk/testapp/modules/jelix_tests/tests/jacl.manager.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jacl.manager.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jacl.users_and_groups.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jacl.users_and_groups.html.php (modified) (1 diff)
- trunk/testapp/var/config/defaultconfig.ini.php.dist (modified) (1 diff)
- trunk/testapp/var/config/defaultconfig.ini.php.dist (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/jelix-lib.mn
r557 r560 22 22 jAclUserGroup.class.php 23 23 jAclManager.class.php 24 jAclDb.class.php 24 25 25 26 cd lib/jelix/controllers … … 250 251 CREDITS 251 252 cd lib/jelix-plugins/auth/ 253 cd lib/jelix-plugins/acl/ 252 254 cd lib/jelix-plugins/coord/ 253 255 cd lib/jelix-plugins/db/ … … 256 258 cd lib/jelix-plugins/wr_rules/ 257 259 260 cd lib/jelix/plugins/acl/db 261 db.acl.php 258 262 cd lib/jelix/plugins/auth/db 259 263 db.auth.php trunk/build/manifests/jelix-lib.mn
r557 r560 22 22 jAclUserGroup.class.php 23 23 jAclManager.class.php 24 jAclDb.class.php 24 25 25 26 cd lib/jelix/controllers … … 250 251 CREDITS 251 252 cd lib/jelix-plugins/auth/ 253 cd lib/jelix-plugins/acl/ 252 254 cd lib/jelix-plugins/coord/ 253 255 cd lib/jelix-plugins/db/ … … 256 258 cd lib/jelix-plugins/wr_rules/ 257 259 260 cd lib/jelix/plugins/acl/db 261 db.acl.php 258 262 cd lib/jelix/plugins/auth/db 259 263 db.auth.php trunk/lib/jelix-scripts/commands/aclgroup.cmd.php
r414 r560 86 86 protected function cmd_list(){ 87 87 $sql="SELECT id_aclgrp, name, grouptype FROM jacl_group WHERE grouptype <2 ORDER BY name"; 88 $cnx = jDb::getConnection(jAcl ::getDbProfil());88 $cnx = jDb::getConnection(jAclDb::getProfil()); 89 89 $rs = $cnx->query($sql); 90 90 echo "id\tlabel name\t\tdefault\n--------------------------------------------------------\n"; … … 103 103 die("wrong parameter count\n"); 104 104 105 $cnx = jDb::getConnection(jAcl ::getDbProfil());105 $cnx = jDb::getConnection(jAclDb::getProfil()); 106 106 107 107 $sql="INSERT into jacl_group (name, grouptype, ownerlogin) VALUES ("; … … 122 122 die("wrong parameter count\n"); 123 123 124 $cnx = jDb::getConnection(jAcl ::getDbProfil());124 $cnx = jDb::getConnection(jAclDb::getProfil()); 125 125 126 126 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); … … 155 155 die("wrong parameter count\n"); 156 156 157 $cnx = jDb::getConnection(jAcl ::getDbProfil());157 $cnx = jDb::getConnection(jAclDb::getProfil()); 158 158 159 159 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); … … 186 186 die("wrong parameter count\n"); 187 187 188 $cnx = jDb::getConnection(jAcl ::getDbProfil());188 $cnx = jDb::getConnection(jAclDb::getProfil()); 189 189 190 190 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); trunk/lib/jelix-scripts/commands/aclgroup.cmd.php
r414 r560 86 86 protected function cmd_list(){ 87 87 $sql="SELECT id_aclgrp, name, grouptype FROM jacl_group WHERE grouptype <2 ORDER BY name"; 88 $cnx = jDb::getConnection(jAcl ::getDbProfil());88 $cnx = jDb::getConnection(jAclDb::getProfil()); 89 89 $rs = $cnx->query($sql); 90 90 echo "id\tlabel name\t\tdefault\n--------------------------------------------------------\n"; … … 103 103 die("wrong parameter count\n"); 104 104 105 $cnx = jDb::getConnection(jAcl ::getDbProfil());105 $cnx = jDb::getConnection(jAclDb::getProfil()); 106 106 107 107 $sql="INSERT into jacl_group (name, grouptype, ownerlogin) VALUES ("; … … 122 122 die("wrong parameter count\n"); 123 123 124 $cnx = jDb::getConnection(jAcl ::getDbProfil());124 $cnx = jDb::getConnection(jAclDb::getProfil()); 125 125 126 126 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); … … 155 155 die("wrong parameter count\n"); 156 156 157 $cnx = jDb::getConnection(jAcl ::getDbProfil());157 $cnx = jDb::getConnection(jAclDb::getProfil()); 158 158 159 159 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); … … 186 186 die("wrong parameter count\n"); 187 187 188 $cnx = jDb::getConnection(jAcl ::getDbProfil());188 $cnx = jDb::getConnection(jAclDb::getProfil()); 189 189 190 190 $sql="SELECT id_aclgrp, grouptype FROM jacl_group WHERE id_aclgrp=".intval($params[0]); trunk/lib/jelix-scripts/commands/aclright.cmd.php
r414 r560 81 81 AND r.id_aclsbj=s.id_aclsbj 82 82 ORDER BY name, subject, value,id_aclres "; 83 $cnx = jDb::getConnection(jAcl ::getDbProfil());83 $cnx = jDb::getConnection(jAclDb::getProfil()); 84 84 $rs = $cnx->query($sql); 85 85 echo "group\tsubject\tvalue\t\tresource\n---------------------------------------------------------------\n"; … … 106 106 die("wrong parameter count\n"); 107 107 108 $cnx = jDb::getConnection(jAcl ::getDbProfil());108 $cnx = jDb::getConnection(jAclDb::getProfil()); 109 109 110 110 $group = intval($params[0]); … … 160 160 die("wrong parameter count\n"); 161 161 162 $cnx = jDb::getConnection(jAcl ::getDbProfil());162 $cnx = jDb::getConnection(jAclDb::getProfil()); 163 163 164 164 $group = intval($params[0]); … … 196 196 197 197 $sql="SELECT id_aclsbj, id_aclvalgrp, label_key FROM jacl_subject ORDER BY id_aclsbj"; 198 $cnx = jDb::getConnection(jAcl ::getDbProfil());198 $cnx = jDb::getConnection(jAclDb::getProfil()); 199 199 $rs = $cnx->query($sql); 200 200 echo "id\t\t\tlabel key\n--------------------------------------------------------\n"; … … 216 216 die("wrong parameter count\n"); 217 217 218 $cnx = jDb::getConnection(jAcl ::getDbProfil());218 $cnx = jDb::getConnection(jAclDb::getProfil()); 219 219 220 220 $sql="SELECT id_aclsbj FROM jacl_subject WHERE id_aclsbj=".$cnx->quote($params[0]); … … 244 244 die("wrong parameter count\n"); 245 245 246 $cnx = jDb::getConnection(jAcl ::getDbProfil());246 $cnx = jDb::getConnection(jAclDb::getProfil()); 247 247 248 248 $sql="SELECT id_aclsbj FROM jacl_subject WHERE id_aclsbj=".$cnx->quote($params[0]); trunk/lib/jelix-scripts/commands/aclright.cmd.php
r414 r560 81 81 AND r.id_aclsbj=s.id_aclsbj 82 82 ORDER BY name, subject, value,id_aclres "; 83 $cnx = jDb::getConnection(jAcl ::getDbProfil());83 $cnx = jDb::getConnection(jAclDb::getProfil()); 84 84 $rs = $cnx->query($sql); 85 85 echo "group\tsubject\tvalue\t\tresource\n---------------------------------------------------------------\n"; … … 106 106 die("wrong parameter count\n"); 107 107 108 $cnx = jDb::getConnection(jAcl ::getDbProfil());108 $cnx = jDb::getConnection(jAclDb::getProfil()); 109 109 110 110 $group = intval($params[0]); … … 160 160 die("wrong parameter count\n"); 161 161 162 $cnx = jDb::getConnection(jAcl ::getDbProfil());162 $cnx = jDb::getConnection(jAclDb::getProfil()); 163 163 164 164 $group = intval($params[0]); … … 196 196 197 197 $sql="SELECT id_aclsbj, id_aclvalgrp, label_key FROM jacl_subject ORDER BY id_aclsbj"; 198 $cnx = jDb::getConnection(jAcl ::getDbProfil());198 $cnx = jDb::getConnection(jAclDb::getProfil()); 199 199 $rs = $cnx->query($sql); 200 200 echo "id\t\t\tlabel key\n--------------------------------------------------------\n"; … … 216 216 die("wrong parameter count\n"); 217 217 218 $cnx = jDb::getConnection(jAcl ::getDbProfil());218 $cnx = jDb::getConnection(jAclDb::getProfil()); 219 219 220 220 $sql="SELECT id_aclsbj FROM jacl_subject WHERE id_aclsbj=".$cnx->quote($params[0]); … … 244 244 die("wrong parameter count\n"); 245 245 246 $cnx = jDb::getConnection(jAcl ::getDbProfil());246 $cnx = jDb::getConnection(jAclDb::getProfil()); 247 247 248 248 $sql="SELECT id_aclsbj FROM jacl_subject WHERE id_aclsbj=".$cnx->quote($params[0]); trunk/lib/jelix-scripts/commands/aclvalue.cmd.php
r414 r560 96 96 protected function cmd_group_list(){ 97 97 $sql="SELECT id_aclvalgrp, label_key, type_aclvalgrp FROM jacl_right_values_group ORDER BY id_aclvalgrp"; 98 $cnx = jDb::getConnection(jAcl ::getDbProfil());98 $cnx = jDb::getConnection(jAclDb::getProfil()); 99 99 $rs = $cnx->query($sql); 100 100 echo "id\tlabel key\t\t\ttype\n--------------------------------------------------------\n"; … … 113 113 die("wrong parameter count\n"); 114 114 115 $cnx = jDb::getConnection(jAcl ::getDbProfil());115 $cnx = jDb::getConnection(jAclDb::getProfil()); 116 116 117 117 $sql="INSERT into jacl_right_values_group (id_aclvalgrp, label_key, type_aclvalgrp) VALUES ("; … … 129 129 die("wrong parameter count\n"); 130 130 131 $cnx = jDb::getConnection(jAcl ::getDbProfil());131 $cnx = jDb::getConnection(jAclDb::getProfil()); 132 132 133 133 $rs = $cnx->query('SELECT count(id_aclsbj) as n FROM jacl_subject WHERE id_aclvalgrp='.intval($params[0])); … … 168 168 } 169 169 170 $cnx = jDb::getConnection(jAcl ::getDbProfil());170 $cnx = jDb::getConnection(jAclDb::getProfil()); 171 171 $rs = $cnx->query($sql); 172 172 … … 197 197 die("wrong parameter count\n"); 198 198 199 $cnx = jDb::getConnection(jAcl ::getDbProfil());199 $cnx = jDb::getConnection(jAclDb::getProfil()); 200 200 201 201 $rs = $cnx->query('SELECT count(id_aclvalgrp) as n FROM jacl_right_values_group WHERE id_aclvalgrp='.intval($params[2])); … … 226 226 die("wrong parameter count\n"); 227 227 228 $cnx = jDb::getConnection(jAcl ::getDbProfil());228 $cnx = jDb::getConnection(jAclDb::getProfil()); 229 229 230 230 $rs = $cnx->query('SELECT count(*) as n FROM jacl_right_values WHERE id_aclvalgrp='.intval($params[1]).' AND value='.$cnx->quote($params[0])); trunk/lib/jelix-scripts/commands/aclvalue.cmd.php
r414 r560 96 96 protected function cmd_group_list(){ 97 97 $sql="SELECT id_aclvalgrp, label_key, type_aclvalgrp FROM jacl_right_values_group ORDER BY id_aclvalgrp"; 98 $cnx = jDb::getConnection(jAcl ::getDbProfil());98 $cnx = jDb::getConnection(jAclDb::getProfil()); 99 99 $rs = $cnx->query($sql); 100 100 echo "id\tlabel key\t\t\ttype\n--------------------------------------------------------\n"; … … 113 113 die("wrong parameter count\n"); 114 114 115 $cnx = jDb::getConnection(jAcl ::getDbProfil());115 $cnx = jDb::getConnection(jAclDb::getProfil()); 116 116 117 117 $sql="INSERT into jacl_right_values_group (id_aclvalgrp, label_key, type_aclvalgrp) VALUES ("; … … 129 129 die("wrong parameter count\n"); 130 130 131 $cnx = jDb::getConnection(jAcl ::getDbProfil());131 $cnx = jDb::getConnection(jAclDb::getProfil()); 132 132 133 133 $rs = $cnx->query('SELECT count(id_aclsbj) as n FROM jacl_subject WHERE id_aclvalgrp='.intval($params[0])); … … 168 168 } 169 169 170 $cnx = jDb::getConnection(jAcl ::getDbProfil());170 $cnx = jDb::getConnection(jAclDb::getProfil()); 171 171 $rs = $cnx->query($sql); 172 172 … … 197 197 die("wrong parameter count\n"); 198 198 199 $cnx = jDb::getConnection(jAcl ::getDbProfil());199 $cnx = jDb::getConnection(jAclDb::getProfil()); 200 200 201 201 $rs = $cnx->query('SELECT count(id_aclvalgrp) as n FROM jacl_right_values_group WHERE id_aclvalgrp='.intval($params[2])); … … 226 226 die("wrong parameter count\n"); 227 227 228 $cnx = jDb::getConnection(jAcl ::getDbProfil());228 $cnx = jDb::getConnection(jAclDb::getProfil()); 229 229 230 230 $rs = $cnx->query('SELECT count(*) as n FROM jacl_right_values WHERE id_aclvalgrp='.intval($params[1]).' AND value='.$cnx->quote($params[0])); trunk/lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl
r559 r560 129 129 ; SMTP server timeout in seconds 130 130 smtpTimeout = 10 131 132 133 [acl] 134 driver = db trunk/lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl
r559 r560 129 129 ; SMTP server timeout in seconds 130 130 smtpTimeout = 10 131 132 133 [acl] 134 driver = db trunk/lib/jelix/acl/jAcl.class.php
r412 r560 4 4 * @subpackage acl 5 5 * @author Laurent Jouanneau 6 * @copyright 2006 Laurent Jouanneau6 * @copyright 2006-2007 Laurent Jouanneau 7 7 * @link http://www.jelix.org 8 8 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file … … 11 11 12 12 /** 13 * interface for jAcl drivers 14 * @package jelix 15 * @subpackage acl 16 */ 17 interface jIAclDriver { 18 19 /** 20 * return the possible values of the right on the given subject (and on the optional resource) 21 * @param string $subject the key of the subject 22 * @param string $resource the id of a resource 23 * @return array list of values corresponding to the right 24 */ 25 public function getRight($subject, $resource=null); 26 27 /** 28 * clear some cached datas, it a cache exists in the driver.. 29 */ 30 public function clearCache(); 31 32 } 33 34 /** 13 35 * Main class to query the acl system, and to know value of a right 14 36 * 15 37 * you should call this class (all method are static) when you want to know if 16 * the current user have a right, or to know if he is a member of a group 17 * This class needs the acl module. 38 * the current user have a right 18 39 * @package jelix 19 40 * @subpackage acl … … 28 49 29 50 /** 30 * Says if the current user is a member of the given user group 31 * @param int $groupid The id of a group 32 * @return boolean true if it's ok 51 * load the acl driver 52 * @return jIAclDriver 33 53 */ 34 public static function isMemberOfGroup ($groupid){ 35 $groups = self::getGroups(); 36 return in_array($groupid, $groups); 54 protected static function _getDriver(){ 55 static $driver = null; 56 if($driver == null){ 57 global $gJConfig; 58 $db = strtolower($gJConfig->acl['driver']); 59 if(!isset($gJConfig->_pluginsPathList_acl) 60 || !isset($gJConfig->_pluginsPathList_acl[$db]) 61 || !file_exists($gJConfig->_pluginsPathList_acl[$db]) ){ 62 throw new jException('jelix~errors.acl.driver.notfound',$db); 63 } 64 require_once($gJConfig->_pluginsPathList_acl[$db].$db.'.acl.php'); 65 $dname = $gJConfig->acl['driver'].'AclDriver'; 66 $driver = new $dname($gJConfig->acl); 67 } 68 return $driver; 37 69 } 70 38 71 39 72 /** … … 44 77 * @return boolean true if yes 45 78 */ 46 public static function check($subject, $value , $resource=null){79 public static function check($subject, $value=true, $resource=null){ 47 80 $val = self::getRight($subject, $resource); 48 81 return in_array($value,$val); 49 82 } 83 50 84 51 52 protected static $aclres = array();53 protected static $acl = array();54 85 55 86 /** … … 60 91 */ 61 92 public static function getRight($subject, $resource=null){ 62 63 if($resource === null && isset(self::$acl[$subject])){ 64 return self::$acl[$subject]; 65 }elseif(isset(self::$aclres[$subject][$resource])){ 66 return self::$aclres[$subject][$resource]; 67 } 68 69 if(!jAuth::isConnected()) // not authificated = no rights 70 return array(); 71 72 $groups = self::getGroups(); 73 74 // recupère toutes les valeurs correspondant aux groupes auquel appartient le user, 75 // avec le sujet et ressource indiqué 76 $values= array(); 77 $dao = jDao::get('jelix~jaclrights', self::getDbProfil()); 78 $list = $dao->getAllGroupRights($subject, $groups); 79 foreach($list as $right){ 80 $values [] = $right->value; 81 } 82 self::$acl[$subject] = $values; 83 84 if($resource !== null){ 85 $list = $dao->getAllGroupRightsWithRes($subject, $groups, $resource); 86 foreach($list as $right){ 87 $values [] = $right->value; 88 } 89 self::$aclres[$subject][$resource] = $values = array_unique($values); 90 } 91 92 return $values; 93 $dr = self::_getDriver(); 94 return $dr->getRight($subject, $resource); 93 95 } 94 96 … … 98 100 */ 99 101 public static function clearCache(){ 100 self::$acl = array(); 101 self::$aclres = array(); 102 } 103 104 105 /** 106 * retrieve the list of group the current user is member of 107 * @return array list of group id 108 */ 109 protected static function getGroups(){ 110 static $groups = null; 111 112 if(!jAuth::isConnected()) 113 return array(); 114 115 // chargement des groupes 116 if($groups === null){ 117 $dao = jDao::get('jelix~jaclusergroup', self::getDbProfil()); 118 $gp = $dao->getGroupsUser($_SESSION['JELIX_USER']->login); 119 $groups = array(); 120 foreach($gp as $g){ 121 $groups[]=intval($g->id_aclgrp); 122 } 123 } 124 return $groups; 125 } 126 127 /** 128 * return the profil name used for jacl connection 129 * @return string profil name 130 * @since 1.0b2 131 */ 132 public static function getDbProfil(){ 133 static $profil=''; 134 if($profil== ''){ 135 try{ 136 $prof = jDb::getProfil ('jacl_profil', true); 137 }catch(Exception $e){ 138 $prof = jDb::getProfil (); 139 } 140 $profil = $prof['name']; 141 } 142 return $profil; 102 $dr = self::_getDriver(); 103 $dr->clearCache(); 143 104 } 144 105 } trunk/lib/jelix/acl/jAcl.class.php
r412 r560 4 4 * @subpackage acl 5 5 * @author Laurent Jouanneau 6 * @copyright 2006 Laurent Jouanneau6 * @copyright 2006-2007 Laurent Jouanneau 7 7 * @link http://www.jelix.org 8 8 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file … … 11 11 12 12 /** 13 * interface for jAcl drivers 14 * @package jelix 15 * @subpackage acl 16 */ 17 interface jIAclDriver { 18 19 /** 20 * return the possible values of the right on the given subject (and on the optional resource) 21 * @param string $subject the key of the subject 22 * @param string $resource the id of a resource 23 * @return array list of values corresponding to the right 24 */ 25 public function getRight($subject, $resource=null); 26 27 /** 28 * clear some cached datas, it a cache exists in the driver.. 29 */ 30 public function clearCache(); 31 32 } 33 34 /** 13 35 * Main class to query the acl system, and to know value of a right 14 36 * 15 37 * you should call this class (all method are static) when you want to know if 16 * the current user have a right, or to know if he is a member of a group 17 * This class needs the acl module. 38 * the current user have a right 18 39 * @package jelix 19 40 * @subpackage acl … … 28 49 29 50 /** 30 * Says if the current user is a member of the given user group 31 * @param int $groupid The id of a group 32 * @return boolean true if it's ok 51 * load the acl driver 52 * @return jIAclDriver 33 53 */ 34 public static function isMemberOfGroup ($groupid){ 35 $groups = self::getGroups(); 36 return in_array($groupid, $groups); 54 protected static function _getDriver(){ 55 static $driver = null; 56 if($driver == null){ 57 global $gJConfig; 58 $db = strtolower($gJConfig->acl['driver']); 59 if(!isset($gJConfig->_pluginsPathList_acl) 60 || !isset($gJConfig->_pluginsPathList_acl[$db]) 61 || !file_exists($gJConfig->_pluginsPathList_acl[$db]) ){ 62 throw new jException('jelix~errors.acl.driver.notfound',$db); 63 } 64 require_once($gJConfig->_pluginsPathList_acl[$db].$db.'.acl.php'); 65 $dname = $gJConfig->acl['driver'].'AclDriver'; 66 $driver = new $dname($gJConfig->acl); 67 } 68 return $driver; 37 69 } 70 38 71 39 72 /** … … 44 77 * @return boolean true if yes 45 78 */ 46 public static function check($subject, $value , $resource=null){79 public static function check($subject, $value=true, $resource=null){ 47 80 $val = self::getRight($subject, $resource); 48 81 return in_array($value,$val); 49 82 } 83 50 84 51 52 protected static $aclres = array();53 protected static $acl = array();54 85 55 86 /** … … 60 91 */ 61 92 public static function getRight($subject, $resource=null){ 62 63 if($resource === null && isset(self::$acl[$subject])){ 64 return self::$acl[$subject]; 65 }elseif(isset(self::$aclres[$subject][$resource])){ 66 return self::$aclres[$subject][$resource]; 67 } 68 69 if(!jAuth::isConnected()) // not authificated = no rights 70 return array(); 71 72 $groups = self::getGroups(); 73 74 // recupère toutes les valeurs correspondant aux groupes auquel appartient le user, 75 // avec le sujet et ressource indiqué 76 $values= array(); 77 $dao = jDao::get('jelix~jaclrights', self::getDbProfil()); 78 $list = $dao->getAllGroupRights($subject, $groups); 79 foreach($list as $right){ 80 $values [] = $right->value; 81 } 82 self::$acl[$subject] = $values; 83 84 if($resource !== null){ 85 $list = $dao->getAllGroupRightsWithRes($subject, $groups, $resource); 86 foreach($list as $right){ 87 $values [] = $right->value; 88 } 89 self::$aclres[$subject][$resource] = $values = array_unique($values); 90 } 91 92 return $values; 93 $dr = self::_getDriver(); 94 return $dr->getRight($subject, $resource); 93 95 } 94 96 … … 98 100 */ 99 101 public static function clearCache(){ 100 self::$acl = array(); 101 self::$aclres = array(); 102 } 103 104 105 /** 106 * retrieve the list of group the current user is member of 107 * @return array list of group id 108 */ 109 protected static function getGroups(){ 110 static $groups = null; 111 112 if(!jAuth::isConnected()) 113 return array(); 114 115 // chargement des groupes 116 if($groups === null){ 117 $dao = jDao::get('jelix~jaclusergroup', self::getDbProfil()); 118 $gp = $dao->getGroupsUser($_SESSION['JELIX_USER']->login); 119 $groups = array(); 120 foreach($gp as $g){ 121 $groups[]=intval($g->id_aclgrp); 122 } 123 } 124 return $groups; 125 } 126 127 /** 128 * return the profil name used for jacl connection 129 * @return string profil name 130 * @since 1.0b2 131 */ 132 public static function getDbProfil(){ 133 static $profil=''; 134 if($profil== ''){ 135 try{ 136 $prof = jDb::getProfil ('jacl_profil', true); 137 }catch(Exception $e){ 138 $prof = jDb::getProfil (); 139 } 140 $profil = $prof['name']; 141 } 142 return $profil; 102 $dr = self::_getDriver(); 103 $dr->clearCache(); 143 104 } 144 105 } trunk/lib/jelix/acl/jAclManager.class.php
r412 r560 13 13 /** 14 14 * This class is used to manage rights 15 * It needs the jxacl module.16 15 * @package jelix 17 16 * @subpackage acl … … 34 33 */ 35 34 public static function addRight($group, $subject, $value , $resource=''){ 36 $profil = jAcl ::getDbProfil();35 $profil = jAclDb::getProfil(); 37 36 $daosbj = jDao::get('jelix~jaclsubject', $profil); 38 37 $daorightval = jDao::get('jelix~jaclrightvalues', $profil); … … 79 78 */ 80 79 public static function removeRight($group, $subject, $value , $resource=''){ 81 $daoright = jDao::get('jelix~jaclrights', jAcl ::getDbProfil());80 $daoright = jDao::get('jelix~jaclrights', jAclDb::getProfil()); 82 81 if($resource === null) $resource=''; 83 82 $daoright->delete($subject,$group,$resource,$value); … … 93 92 */ 94 93 public static function removeResourceRight($subject, $resource){ 95 $daoright = jDao::get('jelix~jaclrights', jAcl ::getDbProfil());94 $daoright = jDao::get('jelix~jaclrights', jAclDb::getProfil()); 96 95 $daoright->deleteBySubjRes($subject, $resource); 97 96 jAcl::clearCache(); … … 106 105 public static function addSubject($subject, $id_aclvalgrp, $label_key){ 107 106 // ajoute un sujet dans la table jacl_subject 108 $p = jAcl ::getDbProfil();107 $p = jAclDb::getProfil(); 109 108 $daosbj = jDao::get('jelix~jaclsubject',$p); 110 109 $subj = jDao::createRecord('jelix~jaclsubject',$p); … … 124 123 // supprime dans jacl_rights 125 124 // supprime dans jacl_subject 126 $p = jAcl ::getDbProfil();125 $p = jAclDb::getProfil(); 127 126 $daoright = jDao::get('jelix~jaclrights',$p); 128 127 $daoright->deleteBySubject($subject); trunk/lib/jelix/acl/jAclManager.class.php
r412 r560 13 13 /** 14 14 * This class is used to manage rights 15 * It needs the jxacl module.16 15 * @package jelix 17 16 * @subpackage acl … … 34 33 */ 35 34 public static function addRight($group, $subject, $value , $resource=''){ 36 $profil = jAcl ::getDbProfil();35 $profil = jAclDb::getProfil(); 37 36 $daosbj = jDao::get('jelix~jaclsubject', $profil); 38 37 $daorightval = jDao::get('jelix~jaclrightvalues', $profil); … … 79 78 */ 80 79 public static function removeRight($group, $subject, $value , $resource=''){ 81 $daoright = jDao::get('jelix~jaclrights', jAcl ::getDbProfil());80 $daoright = jDao::get('jelix~jaclrights', jAclDb::getProfil()); 82 81 if($resource === null) $resource=''; 83 82 $daoright->delete($subject,$group,$resource,$value); … … 93 92 */ 94 93 public static function removeResourceRight($subject, $resource){ 95 $daoright = jDao::get('jelix~jaclrights', jAcl ::getDbProfil());94 $daoright = jDao::get('jelix~jaclrights', jAclDb::getProfil()); 96 95 $daoright->deleteBySubjRes($subject, $resource); 97 96 jAcl::clearCache(); … … 106 105 public static function addSubject($subject, $id_aclvalgrp, $label_key){ 107 106 // ajoute un sujet dans la table jacl_subject 108 $p = jAcl ::getDbProfil();107 $p = jAclDb::getProfil(); 109 108 $daosbj = jDao::get('jelix~jaclsubject',$p); 110 109 $subj = jDao::createRecord('jelix~jaclsubject',$p); … … 124 123 // supprime dans jacl_rights 125 124 // supprime dans jacl_subject 126 $p = jAcl ::getDbProfil();125 $p = jAclDb::getProfil(); 127 126 $daoright = jDao::get('jelix~jaclrights',$p); 128 127 $daoright->deleteBySubject($subject); trunk/lib/jelix/acl/jAclUserGroup.class.php
r412 r560 12 12 /** 13 13 * Use this class to register or unregister users in the acl system, and to manage user groups 14 * It needs the acl module.15 14 * @package jelix 16 15 * @subpackage acl … … 25 24 26 25 /** 26 * Says if the current user is a member of the given user group 27 * @param int $groupid The id of a group 28 * @return boolean true if it's ok 29 */ 30 public static function isMemberOfGroup ($groupid){ 31 $groups = self::getGroups(); 32 return in_array($groupid, $groups); 33 } 34 35 /** 36 * retrieve the list of group the current user is member of 37 * @return array list of group id 38 */ 39 public static function getGroups(){ 40 static $groups = null; 41 42 if(!jAuth::isConnected()) 43 return array(); 44 45 // chargement des groupes 46 if($groups === null){ 47 $dao = jDao::get('jelix~jaclusergroup', jAclDb::getProfil()); 48 $gp = $dao->getGroupsUser($_SESSION['JELIX_USER']->login); 49 $groups = array(); 50 foreach($gp as $g){ 51 $groups[]=intval($g->id_aclgrp); 52 } 53 } 54 return $groups; 55 } 56 57 58 /** 27 59 * get the list of the users of a group 28 60 * @param int $groupid id of the user group … … 30 62 */ 31 63 public static function getUsersList($groupid){ 32 $dao = jDao::get('jelix~jaclusergroup', jAcl ::getDbProfil());64 $dao = jDao::get('jelix~jaclusergroup', jAclDb::getProfil()); 33 65 return $dao->getUsersGroup($groupid); 34 66 } … … 44 76 */ 45 77 public static function createUser($login, $defaultGroup=true){ 46 $p = jAcl ::getDbProfil();78 $p = jAclDb::getProfil(); 47 79 $daousergroup = jDao::get('jelix~jaclusergroup',$p); 48 80 $daogroup = jDao::get('jelix~jaclgroup',$p); … … 78 110 */ 79
