diff options
Diffstat (limited to 'lib/Auth/LDAP.php')
-rw-r--r-- | lib/Auth/LDAP.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php index dd41176..315bfe4 100644 --- a/lib/Auth/LDAP.php +++ b/lib/Auth/LDAP.php @@ -455,6 +455,29 @@ class LDAP return $users; } + public function list_roles($attributes = array(), $search = array(), $params = array()) + { + if (!empty($params['sort_by'])) { + if (!in_array($params['sort_by'], $attributes)) { + $attributes[] = $params['sort_by']; + } + } + + $roles = $this->roles_list($attributes, $search); + $roles = $this->normalize_result($roles); + + if (!empty($params['sort_by'])) { + $this->sort_result_key = $params['sort_by']; + uasort($roles, array($this, 'sort_result')); + + if ($params['sort_order'] == 'DESC') { + $roles = array_reverse($roles, true); + } + } + + return $roles; + } + static function normalize_result($__result) { $conf = Conf::get_instance(); @@ -663,6 +686,27 @@ class LDAP return $this->search($base_dn, $filter, $attributes); } + public function roles_list($attributes = array(), $search = array()) + { + $conf = Conf::get_instance(); + + // TODO: From config + $base_dn = "dc=klab,dc=cc"; + // TODO: From config + $filter = "(&(objectclass=ldapsubentry)(objectclass=nsroledefinition))"; + + if (empty($attributes) || !is_array($attributes)) { + $attributes = array('*'); + } + + if ($s_filter = $this->_search_filter($search)) { + // join search filter with objectClass filter + $filter = '(&' . $filter . $s_filter . ')'; + } + + return $this->search($base_dn, $filter, $attributes); + } + public function search($base_dn, $search_filter = '(objectClass=*)', $attributes = array('*')) { error_log("Searching $base_dn with filter '$search_filter'"); |