Ejemplo n.º 1
0
 /**
  * add a new groupmember to the group
  *
  * @param int $_groupId
  * @param int $_accountId
  * @return unknown
  */
 public function addGroupMember($_groupId, $_accountId)
 {
     $dn = $this->_getDn($_groupId);
     $memberUidNumbers = $this->getGroupMembers($_groupId);
     $accountMetaData = $this->_getAccountMetaData($_accountId);
     if (in_array($accountMetaData['uidNumber'], $memberUidNumbers)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " skipp adding group member, as {$accountMetaData['uid']} is already in group {$dn}");
         }
         return;
     }
     $data = array('memberuid' => $accountMetaData['uid']);
     if ($this->_options['useRfc2307bis']) {
         if (count($memberUidNumbers) > 0) {
             $data['member'] = $accountMetaData['dn'];
         } else {
             // adding first member is handled by $this->_saveRfc2307GroupMembers
             $memberUidNumbers[] = $accountMetaData['uidNumber'];
             $this->_saveRfc2307GroupMembers($_groupId, $memberUidNumbers);
             return;
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  $dn: ' . $dn);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  $data: ' . print_r($data, true));
     }
     $this->_ldap->insertProperty($dn, $data);
 }
Ejemplo n.º 2
0
 /**
  * remove one member from the group in sync backend
  *
  * @param  mixed  $_groupId
  * @param  mixed  $_accountId
  */
 public function removeGroupMemberInSyncBackend($_groupId, $_accountId)
 {
     if ($this->_isReadOnlyBackend) {
         return;
     }
     $userId = Tinebase_Model_User::convertUserIdToInt($_accountId);
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $memberships = $this->getGroupMemberships($_accountId);
     if (!in_array($groupId, $memberships)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " skip removing group member, as {$userId} is not in group {$groupId} " . print_r($memberships, true));
         }
         return;
     }
     try {
         $groupDn = $this->_getDn($_groupId);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . " Failed to remove groupmember {$_accountId} from group {$_groupId}: " . $tenf->getMessage());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getTraceAsString());
         }
         return;
     }
     try {
         $accountMetaData = $this->_getAccountMetaData($_accountId);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' user not found in sync backend: ' . $_accountId);
         }
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " account meta data: " . print_r($accountMetaData, true));
     }
     $memberUidNumbers = $this->getGroupMembers($_groupId);
     $ldapData = array('memberuid' => $accountMetaData['uid']);
     if (isset($this->_options['useRfc2307bis']) && $this->_options['useRfc2307bis']) {
         if (count($memberUidNumbers) === 1) {
             // we need to add the group dn, as the member attribute is not allowed to be empty
             $dataAdd = array('member' => $groupDn);
             $this->_ldap->insertProperty($groupDn, $dataAdd);
         } else {
             $ldapData['member'] = $accountMetaData['dn'];
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  $dn: ' . $groupDn);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . '  $ldapData: ' . print_r($ldapData, true));
     }
     try {
         $this->_ldap->deleteProperty($groupDn, $ldapData);
     } catch (Zend_Ldap_Exception $zle) {
         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . " Failed to remove groupmember {$accountMetaData['dn']} from group {$groupDn}: " . $zle->getMessage());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $zle->getTraceAsString());
         }
     }
 }