7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Auth.php 16971 2009-07-22 18:05:45Z mikaelkael $
22 /** Zend_Amf_Auth_Abstract */
23 require_once 'Zend/Amf/Auth/Abstract.php';
26 require_once 'Zend/Acl.php';
28 /** Zend_Auth_Result */
29 require_once 'Zend/Auth/Result.php';
32 * This class implements authentication against XML file with roles for Flex Builder.
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_Amf_Adobe_Auth
extends Zend_Amf_Auth_Abstract
43 * ACL for authorization
50 * Username/password array
54 protected $_users = array();
59 * @param string $rolefile File containing XML with users and roles
61 public function __construct($rolefile)
63 $this->_acl
= new Zend_Acl();
64 $xml = simplexml_load_file($rolefile);
69 <user name=”user1” password=”pwd”/>
72 <user name=”user2” password=”pwd2”/>
76 foreach($xml->role
as $role) {
77 $this->_acl
->addRole(new Zend_Acl_Role((string)$role["id"]));
78 foreach($role->user
as $user) {
79 $this->_users
[(string)$user["name"]] = array("password" => (string)$user["password"],
80 "role" => (string)$role["id"]);
86 * Get ACL with roles from XML file
90 public function getAcl()
96 * Perform authentication
98 * @throws Zend_Auth_Adapter_Exception
99 * @return Zend_Auth_Result
100 * @see Zend_Auth_Adapter_Interface#authenticate()
102 public function authenticate()
104 if (empty($this->_username
) ||
105 empty($this->_password
)) {
107 * @see Zend_Auth_Adapter_Exception
109 require_once 'Zend/Auth/Adapter/Exception.php';
110 throw new Zend_Auth_Adapter_Exception('Username/password should be set');
113 if(!isset($this->_users
[$this->_username
])) {
114 return new Zend_Auth_Result(Zend_Auth_Result
::FAILURE_IDENTITY_NOT_FOUND
,
116 array('Username not found')
120 $user = $this->_users
[$this->_username
];
121 if($user["password"] != $this->_password
) {
122 return new Zend_Auth_Result(Zend_Auth_Result
::FAILURE_CREDENTIAL_INVALID
,
124 array('Authentication failed')
128 $id = new stdClass();
129 $id->role
= $user["role"];
130 $id->name
= $this->_username
;
131 return new Zend_Auth_Result(Zend_Auth_Result
::SUCCESS
, $id);