My favorites | Sign in
zym
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?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
*/

/**
* @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;
}
}

Change log

r628 by d...@hobodave.com on Jul 26, 2008   Diff
typos
Go to: 
Sign in to write a code review

Older revisions

r627 by potatobob on Jul 26, 2008   Diff
Auth adapter enhancements
r626 by d...@hobodave.com on Jul 26, 2008   Diff
Fixed typo.
r611 by potatobob on Jul 25, 2008   Diff
chain mod
All revisions of this file

File info

Size: 4212 bytes, 155 lines

File properties

svn:executable
*
Powered by Google Project Hosting