PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/Amf/Adobe/Auth.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 133 lines | 50 code | 12 blank | 71 comment | 4 complexity | 1a0c0b9757af8826c7eacce0e0b26d8f MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Amf
  17. * @copyright Copyright (c) 2005-2011 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 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /** @see Zend_Amf_Auth_Abstract */
  22. require_once 'Zend/Amf/Auth/Abstract.php';
  23. /** @see Zend_Acl */
  24. require_once 'Zend/Acl.php';
  25. /** @see Zend_Auth_Result */
  26. require_once 'Zend/Auth/Result.php';
  27. /**
  28. * This class implements authentication against XML file with roles for Flex Builder.
  29. *
  30. * @package Zend_Amf
  31. * @subpackage Adobe
  32. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
  36. {
  37. /**
  38. * ACL for authorization
  39. *
  40. * @var Zend_Acl
  41. */
  42. protected $_acl;
  43. /**
  44. * Username/password array
  45. *
  46. * @var array
  47. */
  48. protected $_users = array();
  49. /**
  50. * Create auth adapter
  51. *
  52. * @param string $rolefile File containing XML with users and roles
  53. */
  54. public function __construct($rolefile)
  55. {
  56. $this->_acl = new Zend_Acl();
  57. $xml = simplexml_load_file($rolefile);
  58. /*
  59. Roles file format:
  60. <roles>
  61. <role id=”admin”>
  62. <user name=”user1” password=”pwd”/>
  63. </role>
  64. <role id=”hr”>
  65. <user name=”user2” password=”pwd2”/>
  66. </role>
  67. </roles>
  68. */
  69. foreach($xml->role as $role) {
  70. $this->_acl->addRole(new Zend_Acl_Role((string)$role["id"]));
  71. foreach($role->user as $user) {
  72. $this->_users[(string)$user["name"]] = array("password" => (string)$user["password"],
  73. "role" => (string)$role["id"]);
  74. }
  75. }
  76. }
  77. /**
  78. * Get ACL with roles from XML file
  79. *
  80. * @return Zend_Acl
  81. */
  82. public function getAcl()
  83. {
  84. return $this->_acl;
  85. }
  86. /**
  87. * Perform authentication
  88. *
  89. * @throws Zend_Auth_Adapter_Exception
  90. * @return Zend_Auth_Result
  91. * @see Zend_Auth_Adapter_Interface#authenticate()
  92. */
  93. public function authenticate()
  94. {
  95. if (empty($this->_username) ||
  96. empty($this->_password)) {
  97. /**
  98. * @see Zend_Auth_Adapter_Exception
  99. */
  100. require_once 'Zend/Auth/Adapter/Exception.php';
  101. throw new Zend_Auth_Adapter_Exception('Username/password should be set');
  102. }
  103. if(!isset($this->_users[$this->_username])) {
  104. return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
  105. null,
  106. array('Username not found')
  107. );
  108. }
  109. $user = $this->_users[$this->_username];
  110. if($user["password"] != $this->_password) {
  111. return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
  112. null,
  113. array('Authentication failed')
  114. );
  115. }
  116. $id = new stdClass();
  117. $id->role = $user["role"];
  118. $id->name = $this->_username;
  119. return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id);
  120. }
  121. }