Overview

Packages

  • None
  • Passwd

Classes

  • Passwd
  • Passwd_Driver
  • Passwd_Driver_Adsi
  • Passwd_Driver_Composite
  • Passwd_Driver_Expect
  • Passwd_Driver_Expectpecl
  • Passwd_Driver_Horde
  • Passwd_Driver_Http
  • Passwd_Driver_Kolab
  • Passwd_Driver_Ldap
  • Passwd_Driver_Pine
  • Passwd_Driver_Poppassd
  • Passwd_Driver_Procopen
  • Passwd_Driver_Pspasswd
  • Passwd_Driver_Servuftp
  • Passwd_Driver_Smbldap
  • Passwd_Driver_Smbpasswd
  • Passwd_Driver_Soap
  • Passwd_Driver_Sql
  • Passwd_Driver_Vmailmgr
  • Passwd_Driver_Vpopmail
  • Passwd_Exception
  • Passwd_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * A Horde_Injector based Passwd_Driver factory.
  4:  *
  5:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
  9:  *
 10:  * @author   Ralf Lang <lang@b1-systems.de>
 11:  * @category Horde
 12:  * @license  http://www.horde.org/licenses/gpl.php
 13:  * @package  Passwd
 14:  */
 15: class Passwd_Factory_Driver extends Horde_Core_Factory_Base
 16: {
 17:     /**
 18:      * Backend configurations.
 19:      *
 20:      * @var array
 21:      */
 22:     protected $_backends = array();
 23: 
 24:     /**
 25:      * Created Passwd_Driver instances.
 26:      *
 27:      * @var array
 28:      */
 29:     private $_instances = array();
 30: 
 31:     /**
 32:      * Returns the Passwd_Driver instance.
 33:      *
 34:      * @param string $name   A string containing the internal name of this
 35:      *                       backend.
 36:      * @param array $params  Any backend parameters if not the defaults.
 37:      *
 38:      * @return Passwd_Driver  The singleton instance.
 39:      * @throws Passwd_Exception
 40:      */
 41:     public function create($name, $params = array() )
 42:     {
 43:         if (!empty($params['is_subdriver'])) {
 44:             $backends = array($name => $params);
 45:         } else {
 46:             $backends = $this->getBackends();
 47:         }
 48: 
 49:         if (empty($backends[$name])) {
 50:             throw new Passwd_Exception(sprintf(_("The password backend \"%s\" does not exist."), $name));
 51:         }
 52:         $backend = $backends[$name];
 53: 
 54:         if (!isset($this->_instances[$name])) {
 55:             $class = 'Passwd_Driver_' . Horde_String::ucfirst(basename($backend['driver']));
 56:             if (!class_exists($class)) {
 57:                 throw new Passwd_Exception(sprintf(_("Unable to load the definition of %s."), $class));
 58:             }
 59: 
 60:             if (empty($backend['params'])) {
 61:                 $backend['params'] = array();
 62:             }
 63:             if (empty($backend['policy'])) {
 64:                 $backend['policy'] = array();
 65:             }
 66:             if (!empty($params)) {
 67:                 $backend['params'] = array_merge($backend['params'], $params);
 68:             }
 69: 
 70:             switch ($class) {
 71:             case 'Passwd_Driver_Ldap':
 72:             case 'Passwd_Driver_Smbldap':
 73:                 if (isset($backend['params']['admindn'])) {
 74:                     $backend['params']['binddn'] = $backend['params']['admindn'];
 75:                 }
 76:                 if (isset($backend['params']['adminpw'])) {
 77:                     $backend['params']['bindpw'] = $backend['params']['adminpw'];
 78:                 }
 79:                 if (isset($backend['params']['host'])) {
 80:                     $backend['params']['hostspec'] = $backend['params']['host'];
 81:                 }
 82: 
 83:                 try {
 84:                     $backend['params']['ldap'] = new Horde_Ldap($backend['params']);
 85:                 } catch (Horde_Ldap_Exception $e) {
 86:                     throw new Passwd_Exception($e);
 87:                 }
 88:                 break;
 89: 
 90:             case 'Passwd_Driver_Sql':
 91:             case 'Passwd_Driver_Vpopmail':
 92:                 if (!($backend['params']['db'] instanceof Horde_Db_Adapter)) {
 93:                     try {
 94:                         if (empty($backend['params'])) {
 95:                             $backend['params']['db'] = $this->_injector
 96:                                 ->getInstance('Horde_Db_Adapter');
 97:                         } else {
 98:                             $params = $backend['params'];
 99:                             unset($params['table'], $params['user_col'],
100:                                   $params['pass_col'], $params['encryption'],
101:                                   $params['show_encryption']);
102:                             $backend['params']['db'] = $this->_injector
103:                                 ->getInstance('Horde_Core_Factory_Db')
104:                                 ->create('passwd', $params);
105:                         }
106:                     } catch (Horde_Db_Exception $e) {
107:                         throw new Passwd_Exception($e);
108:                     }
109:                 }
110:                 break;
111: 
112:             case 'Passwd_Driver_Horde':
113:                 $backend['params']['auth'] = $this->_injector
114:                     ->getInstance('Horde_Core_Factory_Auth')
115:                     ->create();
116:                 break;
117: 
118:             case 'Passwd_Driver_Soap':
119:                 if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
120:                     $backend['params']['soap_params']['proxy_host'] = $GLOBALS['conf']['http']['proxy']['proxy_host'];
121:                     $backend['params']['soap_params']['proxy_port'] = $GLOBALS['conf']['http']['proxy']['proxy_port'];
122:                     $backend['params']['soap_params']['proxy_login'] = $GLOBALS['conf']['http']['proxy']['proxy_user'];
123:                     $backend['params']['soap_params']['proxy_password'] = $GLOBALS['conf']['http']['proxy']['proxy_pass'];
124:                 }
125:                 $backend['params']['soap_params']['encoding'] = 'UTF-8';
126:                 break;
127: 
128:             /* more to come later as drivers are upgraded to H4 / PHP5 */
129:             }
130: 
131:             try {
132:                 $driver = new $class($backend['params']);
133:             } catch (Passwd_Exception $e) {
134:                 throw $e;
135:             } catch (Exception $e) {
136:                 throw new Passwd_Exception($e);
137:             }
138: 
139:             /* Shouldn't we fetch policy from backend and inject some handler
140:              * class here? */
141: 
142:             if (!empty($backend['params']['is_subdriver'])) {
143:                 return $driver;
144:             }
145: 
146:             $this->_instances[$name] = $driver;
147:         }
148: 
149:         return $this->_instances[$name];
150:     }
151: 
152:     /**
153:      * Sets the backends available in this factory.
154:      *
155:      * @param array $backends  A list of backends in the format of backends.php.
156:      *
157:      * @return Passwd_Factory_Driver  The object itself for fluid interface.
158:      */
159:     public function setBackends(array $backends)
160:     {
161:         $this->_backends = $backends;
162:         return $this;
163:     }
164: 
165:     /**
166:      * Returns the backends available in this factory.
167:      *
168:      * @return array  A list of backends in the format of backends.php.
169:      * @throws Passwd_Exception if no backends have been set.
170:      */
171:     public function getBackends()
172:     {
173:         if (empty($this->_backends)) {
174:             throw new Passwd_Exception('No backends have been set before getBackends() was called');
175:         }
176:         return $this->_backends;
177:     }
178: }
179: 
API documentation generated by ApiGen