*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Amf / Adobe / Auth.php
blob24188898ff9ca99ef696e039a4ca6ddb92cb47a4
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Amf
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';
25 /** Zend_Acl */
26 require_once 'Zend/Acl.php';
28 /** Zend_Auth_Result */
29 require_once 'Zend/Auth/Result.php';
31 /**
32 * This class implements authentication against XML file with roles for Flex Builder.
34 * @package Zend_Amf
35 * @subpackage Adobe
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
42 /**
43 * ACL for authorization
45 * @var Zend_Acl
47 protected $_acl;
49 /**
50 * Username/password array
52 * @var array
54 protected $_users = array();
56 /**
57 * Create auth adapter
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);
66 Roles file format:
67 <roles>
68 <role id=”admin”>
69 <user name=”user1” password=”pwd”/>
70 </role>
71 <role id=”hr”>
72 <user name=”user2” password=”pwd2”/>
73 </role>
74 </roles>
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"]);
85 /**
86 * Get ACL with roles from XML file
88 * @return Zend_Acl
90 public function getAcl()
92 return $this->_acl;
95 /**
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,
115 null,
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,
123 null,
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);