Пример #1
0
 /**
  * @brief Get all groups a user belongs to
  * @param $uid Name of the user
  * @returns array with group names
  *
  * This function fetches all groups a user belongs to. It does not check
  * if the user exists at all.
  */
 public function getUserGroups($uid)
 {
     if (!$this->configured) {
         return array();
     }
     if (isset($this->_user_groups[$uid])) {
         return $this->_user_groups[$uid];
     }
     $userDN = OC_LDAP::username2dn($uid);
     if (!$userDN) {
         $this->_user_groups[$uid] = array();
         return array();
     }
     //uniqueMember takes DN, memberuid the uid, so we need to distinguish
     if (strtolower($this->ldapGroupMemberAssocAttr) == 'uniquemember' || strtolower($this->ldapGroupMemberAssocAttr) == 'member') {
         $uid = $userDN;
     } else {
         if (strtolower($this->ldapGroupMemberAssocAttr) == 'memberuid') {
             $result = OC_LDAP::readAttribute($userDN, 'uid');
             $uid = $result[0];
         } else {
             // just in case
             $uid = $userDN;
         }
     }
     $filter = OC_LDAP::combineFilterWithAnd(array($this->ldapGroupFilter, $this->ldapGroupMemberAssocAttr . '=' . $uid));
     $groups = OC_LDAP::fetchListOfGroups($filter, array(OC_LDAP::conf('ldapGroupDisplayName'), 'dn'));
     $this->_user_groups[$uid] = array_unique(OC_LDAP::ownCloudGroupNames($groups), SORT_LOCALE_STRING);
     return $this->_user_groups[$uid];
 }