Ticket #524: ticket524.patch
| File ticket524.patch, 72.5 kB (added by laurentj, 10 months ago) |
|---|
-
build/manifests/jelix-lib.mn
old new 23 23 jAclDbUserGroup.class.php 24 24 jAclDbManager.class.php 25 25 jAclDb.class.php 26 jAcl2.class.php 27 jAcl2DbUserGroup.class.php 28 jAcl2DbManager.class.php 29 jAcl2Db.class.php 26 30 27 31 cd lib/jelix/controllers 28 32 jControllerCmdLine.class.php … … 84 88 jaclusergroup.dao.xml 85 89 jaclgroupsofuser.dao.xml 86 90 jsession.dao.xml 91 jacl2group.dao.xml 92 jacl2rights.dao.xml 93 jacl2subject.dao.xml 94 jacl2usergroup.dao.xml 95 jacl2groupsofuser.dao.xml 87 96 cd lib/jelix/core-modules/jelix/install/sql 88 97 delete.mysql.sql 89 98 install_jacl.schema.mysql.sql 90 99 install_jacl.data.mysql.sql 100 install_jacl2.schema.mysql.sql 101 install_jacl2.data.mysql.sql 91 102 install_jsession.schema.mysql.sql 92 103 delete.pgsql.sql 93 104 install_jacl.schema.pgsql.sql 94 105 install_jacl.data.pgsql.sql 106 install_jacl2.schema.pgsql.sql 107 install_jacl2.data.pgsql.sql 95 108 install_jsession.schema.pgsql.sql 96 109 97 110 cd lib/jelix/core-modules/jelix/locales/en_US … … 304 317 events.xml 305 318 cd lib/jelix-modules/jacldb/classes 306 319 ! jacldb.listener.php 320 cd lib/jelix-modules/jacl2db 321 module.xml 322 events.xml 323 cd lib/jelix-modules/jacl2db/classes 324 ! jacl2db.listener.php 307 325 cd lib/jelix-modules/jauth 308 326 module.xml 309 327 events.xml … … 351 369 CREDITS 352 370 cd lib/jelix-plugins/auth/ 353 371 cd lib/jelix-plugins/acl/ 372 cd lib/jelix-plugins/acl2/ 354 373 cd lib/jelix-plugins/coord/ 355 374 cd lib/jelix-plugins/db/ 356 375 cd lib/jelix-plugins/urls/ … … 359 378 360 379 cd lib/jelix/plugins/acl/db 361 380 db.acl.php 381 cd lib/jelix/plugins/acl2/db 382 db.acl2.php 362 383 cd lib/jelix/plugins/auth/db 363 384 db.auth.php 364 385 cd lib/jelix/plugins/auth/class … … 385 406 plugin.xml 386 407 jacl.coord.ini.php.dist 387 408 409 cd lib/jelix/plugins/coord/jacl2 410 ! jacl2.coord.php 411 plugin.xml 412 jacl2.coord.ini.php.dist 413 388 414 cd lib/jelix/plugins/jforms/html 389 415 html.jformscompiler.php 390 416 html.jformsbuilder.php … … 420 446 cd lib/jelix/plugins/tpl/common 421 447 block.ifacl.php 422 448 block.ifnotacl.php 449 block.ifacl2.php 450 block.ifnotacl2.php 423 451 block.ifuserconnected.php 424 452 block.ifusernotconnected.php 425 453 block.stripws.php -
build/manifests/testapp.mn
old new 137 137 jacl.main_api.html_cli.php 138 138 jacl.manager.html_cli.php 139 139 jacl.users_and_groups.html_cli.php 140 jacl2.main_api.html_cli.php 141 jacl2.manager.html_cli.php 142 jacl2.users_and_groups.html_cli.php 140 143 jdao.conditions.html_cli.php 141 144 jdao.main_api.html_cli.php 142 145 jdao.main_api_with_pdo.html_cli.php -
testapp/install/install.mysql.sql
old new 82 82 ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 83 83 84 84 85 -- Liste des groupes 86 DROP TABLE IF EXISTS `jacl2_group`; 87 CREATE TABLE `jacl2_group` ( 88 `id_aclgrp` int(11) NOT NULL auto_increment, 89 `name` varchar(150) NOT NULL default '', 90 `grouptype` tinyint(4) NOT NULL default '0', 91 `ownerlogin` varchar(50) default NULL, 92 PRIMARY KEY (`id_aclgrp`) 93 ) TYPE=MyISAM AUTO_INCREMENT=1 ; 94 95 -- liste des groupes associés à chaque utilisateur 96 DROP TABLE IF EXISTS `jacl2_user_group`; 97 CREATE TABLE `jacl2_user_group` ( 98 `login` varchar(50) NOT NULL default '', 99 `id_aclgrp` int(11) NOT NULL default '0', 100 KEY `login` (`login`,`id_aclgrp`) 101 ) TYPE=MyISAM; 102 103 104 -- liste des sujets, avec leur appartenance à un groupe de valeurs de droits 105 DROP TABLE IF EXISTS `jacl2_subject`; 106 CREATE TABLE `jacl2_subject` ( 107 `id_aclsbj` varchar(100) NOT NULL default '', 108 `label_key` varchar(100) default NULL, 109 PRIMARY KEY (`id_aclsbj`) 110 ) TYPE=MyISAM; 111 112 -- table centrale 113 -- valeurs du droit pour chaque couple sujet/groupe ou triplet sujet/groupe/ressource 114 DROP TABLE IF EXISTS `jacl2_rights`; 115 CREATE TABLE `jacl2_rights` ( 116 `id_aclsbj` varchar(100) NOT NULL default '', 117 `id_aclgrp` int(11) NOT NULL default '0', 118 `id_aclres` varchar(100) NOT NULL default '', 119 PRIMARY KEY (`id_aclsbj`,`id_aclgrp`,`id_aclres`) 120 ) TYPE=MyISAM; 121 122 85 123 -- -------------------------------------------------------- 86 124 87 125 -- -
testapp/install/install.pgsql.sql
old new 156 156 157 157 158 158 159 CREATE TABLE jacl2_group ( 160 id_aclgrp serial NOT NULL, 161 name character varying(150) NOT NULL, 162 grouptype smallint NOT NULL, 163 ownerlogin character varying(50) 164 ); 159 165 166 SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('jacl2_group', 'id_aclgrp'), 1, false); 160 167 168 CREATE TABLE jacl2_rights ( 169 id_aclsbj character varying(255) NOT NULL, 170 id_aclgrp integer NOT NULL, 171 id_aclres character varying(100) NOT NULL 172 ); 161 173 174 CREATE TABLE jacl2_subject ( 175 id_aclsbj character varying(100) NOT NULL, 176 label_key character varying(100) 177 ); 162 178 179 CREATE TABLE jacl2_user_group ( 180 "login" character varying(50) NOT NULL, 181 id_aclgrp integer NOT NULL 182 ); 163 183 164 184 185 ALTER TABLE ONLY jacl2_group 186 ADD CONSTRAINT jacl2_group_pkey PRIMARY KEY (id_aclgrp); 165 187 188 ALTER TABLE ONLY jacl2_rights 189 ADD CONSTRAINT jacl2_rights_pkey PRIMARY KEY (id_aclsbj, id_aclgrp, id_aclres); 190 191 ALTER TABLE ONLY jacl2_subject 192 ADD CONSTRAINT jacl2_subject_pkey PRIMARY KEY (id_aclsbj); 193 194 ALTER TABLE ONLY jacl2_user_group 195 ADD CONSTRAINT jacl2_user_group_pkey PRIMARY KEY ("login", id_aclgrp); 196 197 ALTER TABLE ONLY jacl2_rights 198 ADD CONSTRAINT jacl2_rights_id_aclgrp_fkey FOREIGN KEY (id_aclgrp) REFERENCES jacl2_group(id_aclgrp); 199 200 ALTER TABLE ONLY jacl2_rights 201 ADD CONSTRAINT jacl2_rights_id_aclsbj_fkey FOREIGN KEY (id_aclsbj) REFERENCES jacl2_subject(id_aclsbj); 202 203 ALTER TABLE ONLY jacl2_user_group 204 ADD CONSTRAINT jacl2_user_group_id_aclgrp_fkey FOREIGN KEY (id_aclgrp) REFERENCES jacl2_group(id_aclgrp); 205 206 207 208 209 210 211 -
testapp/modules/jelix_tests/tests/jacl2.manager.html_cli.php
old new 1 <?php 2 /** 3 * @package testapp 4 * @subpackage jelix_tests module 5 * @author Jouanneau Laurent 6 * @contributor 7 * @copyright 2007-2008 Jouanneau laurent 8 * @link http://www.jelix.org 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 */ 11 12 class UTjacl2manager extends jUnitTestCaseDb { 13 14 15 public function testStart(){ 16 $this->dbProfil = jAcl2Db::getProfil(); 17 $this->emptyTable('jacl2_user_group'); 18 $this->emptyTable('jacl2_rights'); 19 $this->emptyTable('jacl2_subject'); 20 21 $groups= array(array('id_aclgrp'=>1, 'name'=>'group1', 'grouptype'=>0, 'ownerlogin'=>null)); 22 23 $this->insertRecordsIntoTable('jacl2_group', array('id_aclgrp','name','grouptype','ownerlogin'), $groups, true); 24 } 25 26 protected $subjects; 27 28 public function testAddSubject(){ 29 jAcl2DbManager::addSubject('super.cms' , 'cms~rights.super.cms'); 30 $this->subjects = array( 31 array('id_aclsbj'=>'super.cms', 'label_key'=>'cms~rights.super.cms'), 32 ); 33 $this->assertTableContainsRecords('jacl2_subject', $this->subjects); 34 35 jAcl2DbManager::addSubject('jxacl.groups.management', 'jxacl~db.sbj.groups.management'); 36 jAcl2DbManager::addSubject('admin.access', 'admin~rights.access'); 37 jAcl2DbManager::addSubject('admin.foo', 'admin~rights.foo'); 38 39 $this->subjects[] = array('id_aclsbj'=>'jxacl.groups.management', 'label_key'=>'jxacl~db.sbj.groups.management'); 40 $this->subjects[] = array('id_aclsbj'=>'admin.access', 'label_key'=>'admin~rights.access'); 41 $this->subjects[] = array('id_aclsbj'=>'admin.foo', 'label_key'=>'admin~rights.foo'); 42 43 $this->assertTableContainsRecords('jacl2_subject', $this->subjects); 44 } 45 46 public function testRemoveSubject(){ 47 jAcl2DbManager::removeSubject('admin.foo'); 48 array_pop($this->subjects); 49 $this->assertTableContainsRecords('jacl2_subject', $this->subjects); 50 } 51 52 protected $rights; 53 public function testAddRight(){ 54 jAcl2DbManager::addSubject('super.cms.list' , 'cms~rights.super.cms.list'); 55 jAcl2DbManager::addSubject('super.cms.update' , 'cms~rights.super.cms.update'); 56 $this->subjects[] = array('id_aclsbj'=>'super.cms.list', 'label_key'=>'cms~rights.super.cms.list'); 57 $this->subjects[] = array('id_aclsbj'=>'super.cms.update', 'label_key'=>'cms~rights.super.cms.update'); 58 $this->assertTableContainsRecords('jacl2_subject', $this->subjects); 59 60 $this->assertTrue(jAcl2DbManager::addRight(1, 'super.cms.list' )); 61 $this->rights = array(array('id_aclsbj'=>'super.cms.list' ,'id_aclgrp'=>1, 'id_aclres'=> null)); 62 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 63 64 $this->assertTrue(jAcl2DbManager::addRight(1, 'admin.access')); 65 $this->rights[] = array('id_aclsbj'=>'admin.access' ,'id_aclgrp'=>1, 'id_aclres'=> null); 66 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 67 68 $this->assertFalse(jAcl2DbManager::addRight(1, 'admin.access.bla')); 69 $this->assertFalse(jAcl2DbManager::addRight(1, 'admin.dont.exist')); 70 $this->assertTrue(jAcl2DbManager::addRight(1, 'super.cms.list' )); // on tente d'inserer le meme droit 71 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 72 } 73 74 public function testRemoveRight(){ 75 jAcl2DbManager::removeRight(1, 'admin.access' ); 76 $r = $this->rights; 77 array_pop($r); 78 $this->assertTableContainsRecords('jacl2_rights', $r); 79 $this->assertTrue(jAcl2DbManager::addRight(1, 'admin.access' )); 80 } 81 82 public function testAddResourceRight(){ 83 $this->assertTrue(jAcl2DbManager::addRight(1, 'super.cms.update', 154)); 84 $this->assertTrue(jAcl2DbManager::addRight(1, 'super.cms.update', 92)); 85 $this->rights[] = array('id_aclsbj'=>'super.cms.update' ,'id_aclgrp'=>1, 'id_aclres'=> '154'); 86 $this->rights[] = array('id_aclsbj'=>'super.cms.update' ,'id_aclgrp'=>1, 'id_aclres'=> '92'); 87 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 88 } 89 public function testRemoveResourceRight(){ 90 jAcl2DbManager::removeResourceRight('super.cms.update', 92); 91 array_pop($this->rights); 92 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 93 } 94 95 public function testRemoveSubject2(){ 96 // remove a subject when rights exists on it 97 jAcl2DbManager::removeSubject('super.cms.update'); 98 array_pop($this->subjects); 99 $this->assertTableContainsRecords('jacl2_subject', $this->subjects); 100 101 $this->rights= array( array('id_aclsbj'=>'super.cms.list' ,'id_aclgrp'=>1, 'id_aclres'=> null), 102 array('id_aclsbj'=>'admin.access' ,'id_aclgrp'=>1, 'id_aclres'=> null)); 103 $this->assertTableContainsRecords('jacl2_rights', $this->rights); 104 } 105 } 106 107 ?> -
testapp/modules/jelix_tests/tests/jacl2.main_api.html_cli.php
old new 1 <?php 2 /** 3 * @package testapp 4 * @subpackage jelix_tests module 5 * @author Jouanneau Laurent 6 * @contributor 7 * @copyright 2007-2008 Jouanneau laurent 8 * @link http://www.jelix.org 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 */ 11 12 13 if(!class_exists('jAuth',false)) { 14 class jAuth { 15 16 static public $connect = true; 17 18 static function isConnected() { 19 return self::$connect; 20 } 21 22 static function getUserSession() { 23 return $_SESSION['JELIX_USER']; 24 } 25 } 26 } 27 28 29 class userTest2 { 30 public $login; 31 } 32 33 34 class UTjacl2 extends jUnitTestCaseDb { 35 36 public function testStart(){ 37 $this->dbProfil = jAcl2Db::getProfil(); 38 $this->emptyTable('jacl2_rights'); 39 $this->emptyTable('jacl2_subject'); 40 41 $groups= array(array('id_aclgrp'=>1, 'name'=>'group1', 'grouptype'=>0, 'ownerlogin'=>null), 42 array('id_aclgrp'=>2, 'name'=>'group2', 'grouptype'=>0, 'ownerlogin'=>null)); 43 44 $this->insertRecordsIntoTable('jacl2_group', array('id_aclgrp','name','grouptype','ownerlogin'), $groups, true); 45 46 $_SESSION['JELIX_USER'] = new userTest2(); 47 $_SESSION['JELIX_USER']->login = 'laurent'; 48 49 $usergroups=array( 50 array('login'=>'laurent', 'id_aclgrp'=>1), 51 ); 52 $this->insertRecordsIntoTable('jacl2_user_group', array('login','id_aclgrp'), $usergroups, true); 53 } 54 55 public function testIsMemberOfGroup(){ 56 $this->assertTrue(jAcl2DbUserGroup::isMemberOfGroup (1)); 57 $this->assertFalse(jAcl2DbUserGroup::isMemberOfGroup (2)); 58 } 59 60 public function testCheckRight(){ 61 jAcl2DbManager::addSubject('super.cms.list', 'cms~rights.super.cms'); 62 jAcl2DbManager::addSubject('super.cms.update', 'cms~rights.super.cms'); 63 jAcl2DbManager::addSubject('super.cms.delete', 'cms~rights.super.cms'); 64 jAcl2DbManager::addSubject('admin.access',1 , 'admin~rights.access'); 65 jAcl2DbManager::addRight(1, 'super.cms.list' ); 66 jAcl2DbManager::addRight(1, 'super.cms.update' ); 67 jAcl2DbManager::addRight(1, 'super.cms.delete', 154); 68 69 $this->assertTrue(jAcl2::check('super.cms.list')); 70 $this->assertTrue(jAcl2::check('super.cms.update')); 71 $this->assertFalse(jAcl2::check('super.cms.delete')); 72 $this->assertFalse(jAcl2::check('super.cms.create')); // doesn't exist 73 $this->assertFalse(jAcl2::check('super.cms.read'));// doesn't exist 74 $this->assertFalse(jAcl2::check('super.cms.delete'));// doesn't exist 75 76 77 78 $this->assertFalse(jAcl2::check('admin.access')); 79 $this->assertTrue(jAcl2::check('super.cms.list',154)); // droit sur une ressource 80 $this->assertTrue(jAcl2::check('super.cms.update',154)); // droit sur une ressource 81 $this->assertTrue(jAcl2::check('super.cms.delete',154)); // droit sur une ressource 82 $this->assertTrue(jAcl2::check('super.cms.list',122)); // ressource non repertoriée 83 $this->assertTrue(jAcl2::check('super.cms.update',122)); // ressource non repertoriée 84 $this->assertFalse(jAcl2::check('super.cms.delete',122)); // ressource non repertoriée 85 86 jAcl2DbManager::addRight(1, 'admin.access'); 87 88 $this->assertTrue(jAcl2::check('admin.access')); 89 90 } 91 92 public function testGetRightDisconnect(){ 93 jAuth::$connect = false; 94 jAcl2::clearCache(); 95 $this->assertFalse(jAcl2::check('super.cms.list')); 96 $this->assertFalse(jAcl2::check('admin.access')); 97 jAuth::$connect = true; 98 jAcl2::clearCache(); 99 } 100 101 102 public function testEnd(){ 103 $_SESSION['JELIX_USER']=null; 104 } 105 106 } 107 108 ?> -
testapp/modules/jelix_tests/tests/jacl2.users_and_groups.html_cli.php
old new 1 <?php 2 /** 3 * @package testapp 4 * @subpackage jelix_tests module 5 * @author Jouanneau Laurent 6 * @contributor 7 * @copyright 2007 Jouanneau laurent 8 * @link http://www.jelix.org 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 */ 11 12 13 /** 14 * Tests on user and group management in jAcl 15 * CAREFULL ! DON'T CHANGE THE ORDER OF METHODS 16 */ 17 class UTjacl2usergroup extends jUnitTestCaseDb { 18 19 protected $groups; 20 protected $defaultGroupId; 21 22 protected $grpId1; 23 protected $grpId2; 24 protected $grpId3; 25 protected $grpId4; 26 protected $grpId5; 27 protected $grpId6; 28 protected $grpId7; 29 30 public function testStart(){ 31 $this->dbProfil = jAcl2Db::getProfil(); 32 33 $this->emptyTable('jacl2_user_group'); 34 $this->emptyTable('jacl2_group'); 35 } 36 37 public function testCreateGroup(){ 38 39 // creation d'un groupe 40 41 $this->grpId1 = jAcl2DbUserGroup::createGroup('group1'); 42 $this->assertTrue($this->grpId1 != '', 'jAcl2DbUserGroup::createGroup failed : id is empty'); 43 $this->groups = array(array('id_aclgrp'=>$this->grpId1, 44 'name'=>'group1', 45 'grouptype'=>0, 46 'ownerlogin'=>null)); 47 $this->assertTableContainsRecords('jacl2_group', $this->groups); 48 49 // creation de deux autres groupes 50 51 $this->grpId2 = jAcl2DbUserGroup::createGroup('group2'); 52 $this->grpId3 = jAcl2DbUserGroup::createGroup('group3'); 53 $this->groups[] = array('id_aclgrp'=>$this->grpId2, 54 'name'=>'group2', 55 'grouptype'=>0, 56 'ownerlogin'=>null); 57 $this->groups[] = array('id_aclgrp'=>$this->grpId3, 58 'name'=>'group3', 59 'grouptype'=>0, 60 'ownerlogin'=>null); 61 $this->assertTableContainsRecords('jacl2_group', $this->groups); 62 63 } 64 65 public function testDefaultGroup(){ 66 // on met un des groupes par defaut 67 jAcl2DbUserGroup::setDefaultGroup($this->grpId2,false); 68 $this->assertTableContainsRecords('jacl2_group', $this->groups); 69 jAcl2DbUserGroup::setDefaultGroup($this->grpId2,true); 70 $this->defaultGroupId = $this->grpId2; // for next test method 71 $this->groups[1]['grouptype']=1; 72 $this->assertTableContainsRecords('jacl2_group', $this->groups); 73 } 74 75 public function testRenameGroup(){ 76 // changement de nom d'un groupe 77 jAcl2DbUserGroup::updateGroup($this->grpId3, 'newgroup3'); 78 $this->groups[2]['name']='newgroup3'; 79 $this->assertTableContainsRecords('jacl2_group', $this->groups); 80 } 81 82 public function testGroupList(){ 83 // recuperation de la liste de tous les groupes 84 $list = jAcl2DbUserGroup::getGroupList()->fetchAll(); 85 86 $verif='<array> 87 <object> 88 <string property="id_aclgrp" value="'.$this->grpId1.'" /> 89 <string property="name" value="group1" /> 90 <string property="grouptype" value="0" /> 91 <null property="ownerlogin"/> 92 </object> 93 <object> 94 <string property="id_aclgrp" value="'.$this->grpId2.'" /> 95 <string property="name" value="group2" /> 96 <string property="grouptype" value="1" /> 97 <null property="ownerlogin"/> 98 </object> 99 <object> 100 <string property="id_aclgrp" value="'.$this->grpId3.'" /> 101 <string property="name" value="newgroup3" /> 102 <string property="grouptype" value="0" /> 103 <null property="ownerlogin"/> 104 </object> 105 </array>'; 106 107 $this->assertComplexIdenticalStr($list, $verif); 108 } 109 110 public function testRemoveGroup(){ 111 // creation d'un autre groupe 112 $this->grpId4 = jAcl2DbUserGroup::createGroup('group4'); 113 $records2 = $this->groups; 114 $records2[] = array('id_aclgrp'=>$this->grpId4, 115 'name'=>'group4', 116 'grouptype'=>0, 117 'ownerlogin'=>null); 118 $this->assertTableContainsRecords('jacl2_group', $records2); 119 120 // destruction d'un groupe (ici qui n'a pas de user) 121 jAcl2DbUserGroup::removeGroup($this->grpId4); 122 $this->assertTableContainsRecords('jacl2_group', $this->groups); 123 124 } 125 126 protected $usergroups=array(); 127 128 public function testCreateUser(){ 129 $this->assertTableIsEmpty('jacl2_user_group'); 130 131 // creation d'un user dans les acl, sans le mettre dans les groupes par defaut 132 jAcl2DbUserGroup::createUser('laurent',false); 133 $this->grpId5 = $this->getLastId('id_aclgrp', 'jacl2_group'); 134 135 $this->groups[] = array('id_aclgrp'=>$this->grpId5, 136 'name'=>'laurent', 137 'grouptype'=>2, 138 'ownerlogin'=>'laurent'); 139 $this->assertTableContainsRecords('jacl2_group', $this->groups); 140 141 $this->usergroups=array( 142 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 143 ); 144 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 145 } 146 147 public function testCreateUser2(){ 148 // creation d'un deuxième user dans les acl, en le mettant 149 // dans les groupes par defaut 150 jAcl2DbUserGroup::createUser('max'); 151 $this->grpId6 = $this->getLastId('id_aclgrp', 'jacl2_group'); 152 153 $this->groups[] = array('id_aclgrp'=>$this->grpId6, 154 'name'=>'max', 155 'grouptype'=>2, 156 'ownerlogin'=>'max'); 157 $this->assertTableContainsRecords('jacl2_group', $this->groups); 158 159 $this->usergroups=array( 160 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 161 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 162 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 163 ); 164 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 165 } 166 167 public function testAddUserIntoGroup(){ 168 // ajout d'un user dans un groupe 169 jAcl2DbUserGroup::createUser('robert'); 170 $this->grpId7 = $this->getLastId('id_aclgrp', 'jacl2_group'); 171 jAcl2DbUserGroup::addUserToGroup('robert', $this->grpId1); 172 173 $this->groups[] = array('id_aclgrp'=>$this->grpId7, 174 'name'=>'robert', 175 'grouptype'=>2, 176 'ownerlogin'=>'robert'); 177 $this->assertTableContainsRecords('jacl2_group', $this->groups); 178 179 $this->usergroups=array( 180 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 181 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 182 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 183 array('login'=>'robert', 'id_aclgrp'=>$this->grpId7), 184 array('login'=>'robert', 'id_aclgrp'=>$this->defaultGroupId), 185 array('login'=>'robert', 'id_aclgrp'=>$this->grpId1), 186 ); 187 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 188 } 189 190 public function testUsersList(){ 191 192 // récuperation de la liste des users 193 $list = jAcl2DbUserGroup::getUsersList($this->defaultGroupId)->fetchAll(); 194 $verif='<array> 195 <object> 196 <string property="id_aclgrp" value="'.$this->defaultGroupId.'" /> 197 <string property="login" value="max" /> 198 </object> 199 <object> 200 <string property="id_aclgrp" value="'.$this->defaultGroupId.'" /> 201 <string property="login" value="robert" /> 202 </object> 203 </array>'; 204 $this->assertComplexIdenticalStr($list, $verif); 205 } 206 207 public function testRemoveUserFromGroup(){ 208 209 // on enleve un user dans un groupe 210 jAcl2DbUserGroup::removeUserFromGroup('robert', $this->grpId1); 211 212 $this->usergroups=array( 213 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 214 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 215 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 216 array('login'=>'robert', 'id_aclgrp'=>$this->grpId7), 217 array('login'=>'robert', 'id_aclgrp'=>$this->defaultGroupId), 218 ); 219 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 220 221 } 222 223 public function testRemoveUser(){ 224 // on enleve un user 225 jAcl2DbUserGroup::removeUser('robert'); 226 $this->usergroups=array( 227 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 228 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 229 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 230 ); 231 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 232 array_pop($this->groups); 233 $this->assertTableContainsRecords('jacl2_group', $this->groups); 234 } 235 236 public function testRemoveUsedGroup(){ 237 // on detruit un groupe qui a des users 238 // on ajoute d'abord un user dans un groupe 239 jAcl2DbUserGroup::addUserToGroup('max', $this->grpId3); 240 241 $this->usergroups=array( 242 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 243 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 244 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 245 array('login'=>'max', 'id_aclgrp'=> $this->grpId3), 246 ); 247 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 248 249 // ok maintenant on supprime le groupe 250 251 jAcl2DbUserGroup::removeGroup($this->grpId3); 252 $this->usergroups=array( 253 array('login'=>'laurent', 'id_aclgrp'=>$this->grpId5), 254 array('login'=>'max', 'id_aclgrp'=>$this->grpId6), 255 array('login'=>'max', 'id_aclgrp'=>$this->defaultGroupId), 256 ); 257 $this->assertTableContainsRecords('jacl2_user_group', $this->usergroups); 258 unset($this->groups[2]); 259 $this->assertTableContainsRecords('jacl2_group', $this->groups); 260 261 262 } 263 } 264 265 ?> -
testapp/modules/jelix_tests/tests/jacl.main_api.html_cli.php
old new 9 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 10 */ 11 11 12 if(!class_exists('jAuth',false)) { 13 class jAuth { 12 14 13 class jAuth { 15 static public $connect = true; 14 16 15 static public $connect = true; 17 static function isConnected() { 18 return self::$connect; 19 } 16 20 17 static function isConnected() { 18 return self::$connect; 21 static function getUserSession() { 22 return $_SESSION['JELIX_USER']; 23 } 19 24 } 20 21 static function getUserSession() {22 return $_SESSION['JELIX_USER'];23 }24 25 } 25 26 27 26 28 class userTest { 27 29 public $login; 28 30 } -
lib/jelix-modules/jacl2db/events.xml
old new 1 <?xml version="1.0" encoding="UTF-8"?> 2 <events xmlns="http://jelix.org/ns/events/1.0"> 3 <listener name="jacl2db"> 4 <event name="AuthNewUser" /> 5 <event name="AuthRemoveUser" /> 6 </listener> 7 </events> -
lib/jelix-modules/jacl2db/module.xml
old new 1 <?xml version="1.0" encoding="UTF-8"?> 2 <module xmlns="http://jelix.org/ns/module/1.0"> 3 4 </module> -
lib/jelix-modules/jacl2db/classes/jacl2db.listener.php
old new 1 <?php 2 /** 3 * @package jelix-modules 4 * @subpackage jacl2db 5 * @author Jouanneau Laurent 6 * @contributor 7 * @copyright 2008 Jouanneau laurent 8 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 9 * @since 1.1 10 */ 11 12 /** 13 * @package jelix-modules 14 * @subpackage jacl2db 15 * @since 1.1 16 */ 17 class jacl2dbListener extends jEventListener{ 18 19 /** 20 * Called when a user is created : set up default rights on this user 21 * 22 * @param jEvent $event the event 23 */ 24 function onAuthNewUser($event){ 25 if($GLOBALS['gJConfig']->acl['enableAclDbEventListener']) { 26 $user = $event->getParam('user'); 27 jAcl2DbUserGroup::createUser($user->login); 28 } 29 } 30 31 /** 32 * Called when a user has been removed : delete rights about this user 33 * 34 * @param jEvent $event the event 35 */ 36 function onAuthRemoveUser($event){ 37 if($GLOBALS['gJConfig']->acl['enableAclDbEventListener']) { 38 $login = $event->getParam('login'); 39 jAcl2DbUserGroup::removeUser($login); 40 } 41 } 42 } -
lib/jelix/plugins/tpl/common/block.ifnotacl2.php
old new 1 <?php 2 /** 3 * @package jelix 4 * @subpackage jtpl_plugin 5 * @author Jouanneau Laurent 6 * @contributor Dominique Papin 7 * @copyright 2006-2008 Jouanneau laurent 8 * @copyright 2007 Dominique Papin 9 * @link http://www.jelix.org 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 11 */ 12 13 /** 14 * a special if block to test easily a right value 15 * 16 * <pre>{ifnotacl2 'subject',54} ..here generated content if the user has NOT the right {/ifnotacl2}</pre> 17 * @param jTplCompiler $compiler the template compiler 18 * @param boolean true if it is the begin of block, else false 19 * @param $params array 0=>subject 1=>optional resource 20 * @return string the php code corresponding to the begin or end of the block 21 */ 22 function jtpl_block_common_ifnotacl2($compiler, $begin, $params=array()) 23 { 24 if($begin){ 25 if(count($params) == 1){ 26 $content = ' if(!jAcl2::check('.$params[0].')):'; 27 }elseif(count($params) == 2){ 28 $content = ' if(!jAcl2::check('.$params[0].','.$params[1].')):'; 29 }else{ 30 $content=''; 31 $compiler->doError2('errors.tplplugin.block.bad.argument.number','ifnotacl2',1); 32 } 33 }else{ 34 $content = ' endif; '; 35 } 36 return $content; 37 } 38 39 ?> -
lib/jelix/plugins/tpl/common/block.ifacl2.php
old new 1 <?php 2 /** 3 * @package jelix 4 * @subpackage jtpl_plugin 5 * @author Jouanneau Laurent 6 * @contributor Dominique Papin 7 * @copyright 2006-2008 Jouanneau laurent 8 * @copyright 2007 Dominique Papin 9 * @link http://www.jelix.org 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 11 */ 12 13 /** 14 * a special if block to test easily a right value 15 * 16 * <pre>{ifacl2 'subject',54} ..here generated content if the user has the right {/ifacl2}</pre> 17 * @param jTplCompiler $compiler the template compiler 18 * @param boolean true if it is the begin of block, else false 19 * @param $param array 0=>subject 1=>optional resource 20 * @return string the php code corresponding to the begin or end of the block 21 */ 22 function jtpl_block_common_ifacl2($compiler, $begin, $param=array()) 23 { 24 if($begin){ 25 if(count($param) == 1){ 26 $content = ' if(jAcl2::check('.$param[0].')):'; 27 }elseif(count($param) == 3){ 28 $content = ' if(jAcl2::check('.$param[0].','.$param[1].')):'; 29 }else{ 30 $content=''; 31 $compiler->doError2('errors.tplplugin.block.bad.argument.number','ifacl2',1); 32 } 33 }else{ 34 $content = ' endif; '; 35 } 36 return $content; 37 } 38 39 ?> -
lib/jelix/plugins/tpl/common/block.ifacl.php
old new 13 13 /** 14 14 * a special if block to test easily a right value 15 15 * 16 * <pre>{ifacl 'subject', 54} ..here generated content if the user has the right {/ifacl}</pre>16 * <pre>{ifacl 'subject','value', 54} ..here generated content if the user has the right {/ifacl}</pre> 17 17 * @param jTplCompiler $compiler the template compiler 18 18 * @param boolean true if it is the begin of block, else false 19 19 * @param $param array 0=>subject 1=>right value 2=>optional resource -
lib/jelix/plugins/tpl/common/block.ifnotacl.php
old new 13 13 /** 14 14 * a special if block to test easily a right value 15 15 * 16 * <pre>{ifnotacl 'subject', 54} ..here generated content if the user has NOT the right {/ifnotacl}</pre>16 * <pre>{ifnotacl 'subject','value',54} ..here generated content if the user has NOT the right {/ifnotacl}</pre> 17 17 * @param jTplCompiler $compiler the template compiler 18 18 * @param boolean true if it is the begin of block, else false 19 19 * @param $params array 0=>subject 1=>right value 2=>optional resource -
lib/jelix/plugins/acl2/db/db.acl2.php
old new 1 <?php 2 /** 3 * @package jelix 4 * @subpackage acl_driver 5 * @author Laurent Jouanneau 6 * @copyright 2006-2008 Laurent Jouanneau 7 * @link http://www.jelix.org 8 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 9 */ 10 11 /** 12 * driver for jAcl2 based on a database 13 * @package jelix 14 * @subpackage acl_driver 15 */ 16 class dbAcl2Driver implements jIAcl2Driver { 17 18 /** 19 * 20 */ 21 function __construct (){ } 22 23 24 protected static $aclres = array(); 25 protected static $acl = array(); 26 27 /** 28 * return the value of the right on the given subject (and on the optional resource) 29 * @param string $subject the key of the subject 30 * @param string $resource the id of a resource 31 * @return boolean true if the right is ok 32 */ 33 public function getRight($subject, $resource=null){ 34 35 if($resource === null && isset(self::$acl[$subject])){ 36 return self::$acl[$subject]; 37 }elseif(isset(self::$aclres[$subject][$resource])){ 38 return self::$aclres[$subject][$resource]; 39 } 40 41 if(!jAuth::isConnected()) // not authicated == no rights 42 return false; 43 44 $groups = jAcl2DbUserGroup::getGroups(); 45 46 if (count($groups) == 0) { 47 self::$acl[$subject] = false; 48 self::$aclres[$subject][$resource] = false; 49 return false; 50 } 51 52 $hasRight = false; 53 $dao = jDao::get('jelix~jacl2rights', jAcl2Db::getProfil()); 54 $right = $dao->getRight($subject, $groups); 55 self::$acl[$subject] = $hasRight = ($right != false); 56 57 if($resource !== null){ 58 if($hasRight) { 59 self::$aclres[$subject][$resource] = true; 60 } 61 else { 62 $right = $dao->getRightWithRes($subject, $groups, $resource); 63 self::$aclres[$subject][$resource] = $hasRight = ($right != false); 64 } 65 } 66 67 return $hasRight; 68 } 69 70 /** 71 * clear right cache 72 * @since 1.0b2 73 */ 74 public function clearCache(){ 75 self::$acl = array(); 76 self::$aclres = array(); 77 } 78 79 } 80 81 ?> -
lib/jelix/plugins/coord/jacl2/jacl2.coord.php
old new 1 <?php 2 /** 3 * @package jelix 4 * @subpackage coord_plugin 5 * @author Laurent Jouanneau 6 * @contributor 7 * @copyright 2008 Laurent Jouanneau 8 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 9 * @since 1.1 10 */ 11 12 /** 13 * 14 */ 15 require(JELIX_LIB_PATH.'acl/jAcl2.class.php'); 16 17 /** 18 * @package jelix 19 * @subpackage coord_plugin 20 * @since 1.1 21 */ 22 class jAcl2CoordPlugin implements jICoordPlugin { 23 public $config; 24 25 function __construct($conf){ 26 $this->config = $conf; 27 } 28 29 /** 30 * @param array $params plugin parameters for the current action 31 * @return null or jSelectorAct if action should change 32 */ 33 public function beforeAction ($params){ 34 $selector = null; 35 $aclok = true; 36 37 if(isset($params['jacl2.right'])) { 38 $aclok = jAcl::check($params['jacl2.right']); 39 40 }elseif(isset($params['jacl2.rights.and'])) { 41 $aclok = true; 42 foreach($params['jacl2.rights.and'] as $right) { 43 if(!jAcl::check($right)) { 44 $aclok = false; 45 break; 46 } 47 } 48 }elseif(isset($params['jacl2.rights.or'])) { 49 $aclok = false; 50 foreach($params['jacl2.rights.or'] as $right) { 51 if(jAcl::check($right)) { 52 $aclok = true; 53 break; 54 } 55 } 56 } 57 58 if(!$aclok){ 59 if($this->config['on_error'] == 1 60 || !$GLOBALS['gJCoord']->request->isAllowedResponse('jResponseRedirect')){ 61 throw new jException($this->config['error_message']); 62 }else{ 63 $selector= new jSelectorAct($this->config['on_error_action']); 64 } 65 } 66 67 return $selector; 68 } 69 70 public function beforeOutput(){} 71 72 public function afterProcess (){} 73 74 } -
lib/jelix/plugins/coord/jacl2/jacl2.coord.ini.php.dist
old new 1 ;<?php die(''); ?> 2 ;for security reasons , don't remove or modify the first line 3 4 ; What to do if a right is required but the user has not this right 5 ; 1 = gene
