MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mpermsldap.class
Ir para a documentação deste ficheiro.
1<?php
2class MPermsLdap extends MPerms
3{
4 private $auth;
5 public $perms;
6
7 function __construct()
8 {
9 parent::__construct();
10 $this->auth = $this->manager->GetAuth();
11 $this->perms = array
12 (
13 A_ACCESS => "SELECT",
14 A_INSERT => "INSERT",
15 A_DELETE => "DELETE",
16 A_UPDATE => "UPDATE",
17 A_EXECUTE => "EXECUTE",
18 A_ADMIN => "SYSTEM"
19 );
20 }
21
22 function setAuth($auth)
23 {
24 $this->auth = $auth;
25 }
26
27 function CheckAccess($module, $action, $deny = false, $group = false)
28 {
29 if ($this->auth->IsLogged())
30 {
31 $login = $this->auth->GetLogin(); // MLogin object
32 $isAdmin = $login->IsAdmin(); // Is administrator?
33 $rights = $login->rights[$module]; // user rights
34 if( ! $rights )
35 {
36 $login->setRights( $this->getRights($login->id) );
37 }
38 $ok = @in_array($action, $login->rights[$module] );
39
40 if(!$ok && $group)
41 {
42 $groups = $this->GetGroupsAllowed($module, $action);
43 $ok = sizeof(array_intersect($groups, $login->groups)) > 0;
44 }
45 }
46
47 if (!$ok && $deny)
48 {
49
50 $msg = _M('Access Denied') . "<br><br>\n" .
51 '<center><big><i><font color=red>' . _M('Transaction: ') . "$transaction</font></i></big></center><br><br>\n" .
52 _M('Please inform a valid login/password to access this content.') . "<br>";
53
54 $users = $this->getUsersAllowed($module, $action);
55
56 if ($users)
57 {
58 $msg .= "<br><br>\n" . _M('Users with access rights') . ":<ul><li>" . implode('<li>', $users) . '</ul>';
59 }
60
61 $go = $this->manager->history->Back('action');
62 $error = Prompt::Error($msg, $go, $caption, '');
63 $error->AddButton(_M(' Login '), $this->manager->getActionURL($this->manager->getConf('login.module'),'login',null,array('return_to'=>urlencode($this->manager->history->Top()))), '');
64 $this->manager->Prompt($error,$deny);
65 //$this->manager->Error($msg, $go);
66 }
67 return $ok;
68 }
69
70 function GetTransactionRights($transaction, $login)
71 {
72 $user = $this->manager->GetBusinessMAD('user');
73 $user->GetByLogin($login);
74 return $user->GetTransactionRights($transaction);
75 }
76
77 function GetRights($login)
78 {
80 $base = $MIOLO->getConf('login.ldap.base');
81 $filter = "(&(objectClass=mioloUserPermission)(login=$login))";
82
83 $MIOLO->auth->connect();
84
85 $sr = ldap_search($MIOLO->auth->conn, $base, $filter, array('miolomodulename', 'miolomoduleaction') );
86 $info = ldap_get_entries($MIOLO->auth->conn, $sr);
87
88 $rights = array();
89 for($i=0; $i<$info['count']; $i++)
90 {
91 $module = $info[$i]['miolomodulename'][0];
92 $rights[$module] = array();
93 for($j=0; $j<$info[$i]['miolomoduleaction']['count']; $j++)
94 {
95 $rights[$module][] = $info[$i]['miolomoduleaction'][$j];
96 }
97 }
98 return $rights;
99 }
100
101 function GetGroups($login)
102 {
103 $user = $this->manager->GetBusinessMAD('user');
104 $user->GetByLogin($login);
105 return $user->GetArrayGroups();
106 }
107
108 function GetUsersAllowed($module, $action = A_ACCESS)
109 {
111 $base = $MIOLO->getConf('login.ldap.base');
112 $filter = "(&(objectClass=mioloUserPermission)(mioloModuleName=$module)(mioloModuleAction=$action))";
113 $sr = ldap_search($MIOLO->auth->conn, $base, $filter, array('login') );
114 $info = ldap_get_entries($MIOLO->auth->conn, $sr);
115
116 $users = array();
117 for($i=0; $i<$info['count']; $i++)
118 {
119 $users[] = $info[$i]['login'][0];
120 }
121 return $users;
122 }
123
124 function GetGroupsAllowed($module, $action = A_ACCESS)
125 {
127 $base = $MIOLO->getConf('login.ldap.base');
128 $filter = "(&(objectClass=mioloGroupPermission)(mioloModuleName=$module)(mioloModuleAction=$action))";
129 $sr = ldap_search($MIOLO->auth->conn, $base, $filter, array('miologroup') );
130 $info = ldap_get_entries($MIOLO->auth->conn, $sr);
131
132 $groups = array();
133 for($i=0; $i<$info['count']; $i++)
134 {
135 $groups[] = $info[$i]['miologroup'][0];
136 }
137 return $groups;
138 }
139}
140?>
CheckAccess($module, $action, $deny=false, $group=false)
GetUsersAllowed($module, $action=A_ACCESS)
GetRights($login)
GetGroupsAllowed($module, $action=A_ACCESS)
GetTransactionRights($transaction, $login)
GetGroups($login)
setAuth($auth)
static Error($msg='', $goto='', $caption='', $event='')
Definição mprompt.class:90
$action
Definição base.php:4