Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Amf/Adobe/Auth.php
Go to the documentation of this file.
00001 <?php
00023 require_once 'Zend/Amf/Auth/Abstract.php';
00024 
00026 require_once 'Zend/Acl.php';
00027 
00029 require_once 'Zend/Auth/Result.php';
00030 
00039 class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
00040 {
00041 
00047     protected $_acl;
00048 
00054     protected $_users = array();
00055 
00061     public function __construct($rolefile)
00062     {
00063         $this->_acl = new Zend_Acl();
00064         $xml = simplexml_load_file($rolefile);
00065 /*
00066 Roles file format:
00067  <roles>
00068    <role id=”admin”>
00069         <user name=”user1” password=”pwd”/>
00070     </role>
00071    <role id=”hr”>
00072         <user name=”user2” password=”pwd2”/>
00073     </role>
00074 </roles>
00075 */
00076         foreach($xml->role as $role) {
00077             $this->_acl->addRole(new Zend_Acl_Role((string)$role["id"]));
00078             foreach($role->user as $user) {
00079                 $this->_users[(string)$user["name"]] = array("password" => (string)$user["password"],
00080                                                              "role" => (string)$role["id"]);
00081             }
00082         }
00083     }
00084 
00090     public function getAcl()
00091     {
00092         return $this->_acl;
00093     }
00094 
00102     public function authenticate()
00103     {
00104         if (empty($this->_username) ||
00105             empty($this->_password)) {
00109             require_once 'Zend/Auth/Adapter/Exception.php';
00110             throw new Zend_Auth_Adapter_Exception('Username/password should be set');
00111         }
00112 
00113         if(!isset($this->_users[$this->_username])) {
00114             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
00115                 null,
00116                 array('Username not found')
00117                 );
00118         }
00119 
00120         $user = $this->_users[$this->_username];
00121         if($user["password"] != $this->_password) {
00122             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
00123                 null,
00124                 array('Authentication failed')
00125                 );
00126         }
00127 
00128         $id = new stdClass();
00129         $id->role = $user["role"];
00130         $id->name = $this->_username;
00131         return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id);
00132     }
00133 }
 All Data Structures Namespaces Files Functions Variables Enumerations