Version 1 by Geoffrey Tran
on Feb 12, 2009 14:43.

compared with
Version 2 by Geoffrey Tran
on Feb 12, 2009 14:52.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (27)

View Page History
{info:title=New Proposal Template}
This page has been created from a template that uses "zones." To proceed:

# Edit the page
# Replace sample content within each zone-data tag with your own content
# Remove this notice
# Save the page
# When you are ready for community review, move this page to the [Ready for Review] section on the edit page.

{note:title=No placeholders allowed!}
Please do not create placeholders. Wait until you have sufficient content to replace all sample data in the proposal template before creating your proposal document.
{note}
{info}

{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Magic Zend_Auth_Adapter_Chain
{zone-data}

{zone-data:proposer-list}
[My Name|mailto:noreply@zend.com]
[Geoffrey Tran| http://zym-project.com]
{zone-data}


{zone-data:overview}
Zend_Magic is a simple component that reads my mind and generates code dynamically to do what I want.
This adapter allows the chaining of other authentication adapters to authenticate from multiple sources.
{zone-data}

{zone-data:references}
* [Harry Houdini Wikipedia Entry|http://en.wikipedia.org/wiki/Harry_Houdini]
* [MagicTricks.com|http://www.magictricks.com/]
* [Zym_Auth_Adapter_Chain|http://code.google.com/p/zym/source/browse/trunk/incubator/library/Zym/Auth/Adapter/Chain.php]
{zone-data}

{zone-data:requirements}
Most requirements take the form of "foo will do ...." or "foo will not support ...", although different words and sentence structure might be used. Adding functionality to your proposal is requirements creep (bad), unless listed below. Discuss major changes with your team first, and then open a "feature improvement" issue against this component.

* This component *will* correctly reads a developers mind for intent and generate the right configuration file.
* The generated config file *will not* support XML, but will provide an extension point in the API.
* This component *will* return the successful authenticated adapter
* This component *will* use no more memory than twice the size of all data it contains.
* This component *will* include a factory method.
* This component *will not* allow subclassing. (i.e. when reviewed, we expect to see "final" keyword in code)
* This component *will* only generate data exports strictly complying with RFC 12345.
* This component *will* validate input data against formats supported by ZF component Foo.
* This component *will not* save any data using Zend_Cache or the filesystem. All transient data *will be* saved using Zend_Session.
{zone-data}

{zone-data:dependencies}
* Zend_Exception Zend_Auth_Result
* Zend_Auth_Adapter_Interface
{zone-data}

{zone-data:operation}
The component is instantiated with a mind-link that ...
Authentication adapter used for chaining other auth adapters to authenticate from multiple sources
* Adapters are processed in FIFO order.
{zone-data}

{zone-data:milestones}
Describe some intermediate state of this component in terms of design notes, additional material added to this page, and / code. Note any significant dependencies here, such as, "Milestone #3 can not be completed until feature Foo has been added to ZF component XYZ." Milestones will be required for acceptance of future proposals. They are not hard, and many times you will only need to think of the first three below.
* Milestone 1: [design notes will be published here|http://framework.zend.com/wiki/x/sg]
* Milestone 2: Working prototype checked into the incubator supporting use cases #1, #2, ...
* Milestone 3: Working prototype checked into the incubator supporting use cases #3 and #4.
* Milestone 1: [DONE] Working prototype
* Milestone 2: Unit tests, Documentation
* Milestone 4: Unit tests exist, work, and are checked into SVN.
* Milestone 5: Initial documentation exists.

If a milestone is already done, begin the description with "\[DONE\]", like this:
* Milestone #: \[DONE\] Unit tests ...
{zone-data}

{zone-data:class-list}
* Zend_Magic_Exception Zend_Auth_Adapter_Chain
* Zend_Magic (factory class)
* Zend_Magic_MindProbe
* Zend_Magic_MindProbe_Intent
* Zend_Magic_Action
* Zend_Magic_CodeGen
{zone-data}

||UC-01||

... (see good use cases book)
{code}
$auth = Zend_Auth::getInstance();

$ldap = new Zend_Auth_Adapter_Ldap();
$db = new Zend_Auth_Adapter_DbTable();

$chain->setAdapters(array($ldap, $db));

$result = $auth->authenticate($chain);
if ($result->isValid()) {
$adapter = $chain->getLastSuccessfulAdapter();
// do something with it...
}
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Magic_Exception extends Zend_Exception {}
<?php
/**
* Zym Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
*
* @category Zym
* @package Zym_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2008 Zym. (http://www.zym-project.com/)
* @license http://www.zym-project.com/license New BSD License
*/

class Zend_Magic {
... /**
* @see Zend_Auth_Adapter_Interface
*/
require_once 'Zend/Auth/Adapter/Interface.php';

/**
* @see Zend_Auth_Result
*/
require_once 'Zend/Auth/Result.php';

/**
* Authentication adapter used for chaining other auth adapters
* to authenticate from multiple sources
*
* Adapters are processed in FIFO order.
*
* @author Geoffrey Tran
* @license http://www.zym-project.com/license New BSD License
* @category Zym
* @package Zym_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2008 Zym. (http://www.zym-project.com/)
*/
class Zym_Auth_Adapter_Chain implements Zend_Auth_Adapter_Interface
{
/**
* Authentication adapter instances
*
* @var array Array of Zend_Auth_Adapters
*/
private $_adapters = array();

/**
* Get the last successfully authenticated adapter
*
* @var Zend_Auth_Adapter_Interface
*/
private $_lastSuccessfulAdapter;

/**
* authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to
* attempt an authenication. Previous to this call, this adapter would have already
* been configured with all nessissary information to successfully connect to a database
* table and attempt to find a record matching the provided identity.
*
* @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
* @return Zend_Auth_Result
*/
public function authenticate()
{
$adapters = $this->getAdapters();

$results = array();
$resultMessages = array();
foreach ($adapters as $adapter) {
// Validate adapter
if (!$adapter instanceof Zend_Auth_Adapter_Interface) {
/**
* @see Zym_Auth_Adapter_Exception
*/
require_once 'Zym/Auth/Adapter/Exception.php';
throw new Zym_Auth_Adapter_Exception(sprintf(
'Adapter "%s" is not an instance of Zend_Auth_Adapter_Interface',
get_class($adapter)));
}

$result = $adapter->authenticate();

// Success
if ($result->isValid()) {
$this->_lastSuccessfulAdapter = $adapter;

return $result;
}

// Failure
$results[] = $result;
$resultMessages[] = $result->getMessages();
}

$result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $resultMessages);

return $result;
}

/**
* Get array of authentication adapters
*
* @return array
*/
public function getAdapters()
{
return $this->_adapters;
}

/**
* Add adapter to the stack in FIFO order
*
* @param Zend_Auth_Adapter_Interface $adapter
* @return Zym_Auth_Adapter_Chain
*/
public function addAdapter(Zend_Auth_Adapter_Interface $adapter)
{
$this->_adapters[] = $adapter;
return $this;
}

/**
* Set array of authentication adapters
*
* @param array $adapters
* @return Zym_Auth_Adapter_Chain
*/
public function setAdapters(array $adapters)
{
$this->_adapters = $adapters;
return $this;
}

/**
* Get last successfully authenticated adapter instance
*
* @return Zend_Auth_Adapter_Interface
*/
public function getLastSuccessfulAdapter()
{
if (!$this->_lastSuccessfulAdapter instanceof Zend_Auth_Adapter_Interface) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception(
'No adapters have successfully authenticated'
);
}

return $this->_lastSuccessfulAdapter;
}
}

{code}
{zone-data}