Пример #1
0
	/**
	 * Class Constructor.
	 *
	 * @param   object  $configObj  An object of configuration variables.
	 *
	 * @since   2.0
	 */
	public function __construct($configObj = null)
	{
		if (is_null($configObj))
		{
			// Parameters will need setting later
			$configArr = array();
		}
		elseif ($configObj instanceof JRegistry)
		{
			// JRegistry object needs to be converted to an array
			$configArr = $configObj->toArray();
		}
		elseif (is_array($configObj))
		{
			// The parameter was an array already
			$configArr = $configObj;
		}
		else
		{
			// Unknown format
			throw new InvalidArgumentException(JText::_('LIB_SHLDAP_ERR_990'), 990);
		}

		// Assign the configuration to their respected class properties only if they exist
		foreach ($configArr as $k => $v)
		{
			if (property_exists($this, $k))
			{
				$this->$k = $v;
			}
			else
			{
				$this->extras[$k] = $v;
			}
		}

		// Check the Ldap extension is loaded
		if (!extension_loaded('ldap'))
		{
			// Ldap extension is not loaded
			throw new RunTimeException(JText::_('LIB_SHLDAP_ERR_991'), 991);
		}

		// Reset resource & debug
		$this->resource = null;
		$this->debug = array();

		// Unencrypt the proxy user if required
		if ($this->proxy_encryption && !empty($this->proxy_password))
		{
			if (!empty($this->encryption_options))
			{
				$this->encryption_options = (array) json_decode($this->encryption_options);
			}

			// There is password encryption lets decrypt (this is only basic)
			$crypt = SHFactory::getCrypt($this->encryption_options);
			$this->proxy_password = $crypt->decrypt($this->proxy_password);
		}
	}
Пример #2
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success, False on error.
  *
  * @since   11.1
  */
 public function save($data)
 {
     // Initialise variables;
     $table = $this->getTable();
     $key = $table->getKeyName();
     $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Unset some debug data
     unset($data['debug_full']);
     unset($data['debug_username']);
     unset($data['debug_password']);
     // Allow an exception to be thrown.
     try {
         // Load the row if saving an existing record.
         if ($pk > 0) {
             $table->load($pk);
             $isNew = false;
         }
         // Sets a default proxy encryption flag in the table
         $table->proxy_encryption = isset($table->proxy_encryption) ? $table->proxy_encryption : false;
         // Deal with the proxy encryption if the password has changed
         if (isset($data['proxy_encryption']) && $data['proxy_encryption'] && (!$table->proxy_encryption || $table->proxy_password != $data['proxy_password'])) {
             $crypt = SHFactory::getCrypt();
             $data['proxy_password'] = $crypt->encrypt($data['proxy_password']);
         }
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     return parent::save($data);
 }