Просмотр исходного кода

ZF-11529: simplify ACL population in AMF server

- If an authentication adapter has a getAcl() method, populate the
  server ACL from it (if currently empty)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24205 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 14 лет назад
Родитель
Сommit
cfc6620a98
3 измененных файлов с 40 добавлено и 1 удалено
  1. 6 0
      library/Zend/Amf/Server.php
  2. 25 1
      tests/Zend/Amf/ServerTest.php
  3. 9 0
      tests/Zend/Amf/_files/acl.xml

+ 6 - 0
library/Zend/Amf/Server.php

@@ -142,12 +142,18 @@ class Zend_Amf_Server implements Zend_Server_Interface
     /**
      * Set authentication adapter
      *
+     * If the authentication adapter implements a "getAcl()" method, populate 
+     * the ACL of this instance with it (if none exists already).
+     *
      * @param  Zend_Amf_Auth_Abstract $auth
      * @return Zend_Amf_Server
      */
     public function setAuth(Zend_Amf_Auth_Abstract $auth)
     {
         $this->_auth = $auth;
+        if ((null === $this->getAcl()) && method_exists($auth, 'getAcl')) {
+            $this->setAcl($auth->getAcl());
+        }
         return $this;
     }
    /**

+ 25 - 1
tests/Zend/Amf/ServerTest.php

@@ -29,6 +29,8 @@ require_once 'Zend/Amf/Server.php';
 require_once 'Zend/Amf/Request.php';
 require_once 'Zend/Amf/Parse/TypeLoader.php';
 require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
+require_once 'Zend/Amf/Adobe/Auth.php';
+require_once 'Zend/Acl.php';
 require_once 'ServiceA.php';
 require_once 'ServiceB.php';
 require_once 'Zend/Session.php';
@@ -1110,6 +1112,29 @@ class Zend_Amf_ServerTest extends PHPUnit_Framework_TestCase
         $this->assertContains("Oops, exception!", $response[0]->getData()->faultString);
     }
 
+
+    /** @group ZF-11529 */
+    public function testSettingAuthAdapterWithAclSetsServerAcl()
+    {
+        $aclFile     = dirname(__FILE__) . '/_files/acl.xml';
+        $authAdapter = new Zend_Amf_Adobe_Auth($aclFile);
+        $this->_server->setAuth($authAdapter);
+        $this->assertSame($authAdapter->getAcl(), $this->_server->getAcl());
+    }
+
+    /** @group ZF-11529 */
+    public function testSettingAuthAdapterWithAclWhenServerAclAlreadyPopulatedWillNotChangeServerAcl()
+    {
+        $acl = new Zend_Acl();
+        $this->_server->setAcl($acl);
+
+        $aclFile     = dirname(__FILE__) . '/_files/acl.xml';
+        $authAdapter = new Zend_Amf_Adobe_Auth($aclFile);
+        $this->_server->setAuth($authAdapter);
+
+        $this->assertNotSame($authAdapter->getAcl(), $this->_server->getAcl());
+        $this->assertSame($acl, $this->_server->getAcl());
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == "Zend_Amf_ServerTest::main") {
@@ -1249,7 +1274,6 @@ class Zend_Amf_testclass
     {
         return array_merge($arrayOne, $arrayTwo);
     }
-
 }
 
 class Zend_Amf_testException

+ 9 - 0
tests/Zend/Amf/_files/acl.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<roles>
+    <role id="admin">
+        <user name="george" password="password" />
+    </role>
+    <role id="anonymous">
+        <user name="guest" password="" />
+    </role>
+</roles>