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.
17
* @subpackage Zend_Auth_Adapter
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: InfoCard.php 9094 2008-03-30 18:36:55Z thomas $
24
* @see Zend_Auth_Adapter_Interface
26
require_once 'Zend/Auth/Adapter/Interface.php';
29
* @see Zend_Auth_Result
31
require_once 'Zend/Auth/Result.php';
36
require_once 'Zend/InfoCard.php';
39
* A Zend_Auth Authentication Adapter allowing the use of Information Cards as an
40
* authentication mechanism
44
* @subpackage Zend_Auth_Adapter
45
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
46
* @license http://framework.zend.com/license/new-bsd New BSD License
48
class Zend_Auth_Adapter_InfoCard implements Zend_Auth_Adapter_Interface
51
* The XML Token being authenticated
58
* The instance of Zend_InfoCard
67
* @param string $strXmlDocument The XML Token provided by the client
70
public function __construct($strXmlDocument)
72
$this->_xmlToken = $strXmlDocument;
73
$this->_infoCard = new Zend_InfoCard();
77
* Sets the InfoCard component Adapter to use
79
* @param Zend_InfoCard_Adapter_Interface $a
80
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
82
public function setAdapter(Zend_InfoCard_Adapter_Interface $a)
84
$this->_infoCard->setAdapter($a);
89
* Retrieves the InfoCard component adapter being used
91
* @return Zend_InfoCard_Adapter_Interface
93
public function getAdapter()
95
return $this->_infoCard->getAdapter();
99
* Retrieves the InfoCard public key cipher object being used
101
* @return Zend_InfoCard_Cipher_PKI_Interface
103
public function getPKCipherObject()
105
return $this->_infoCard->getPKCipherObject();
109
* Sets the InfoCard public key cipher object to use
111
* @param Zend_InfoCard_Cipher_PKI_Interface $cipherObj
112
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
114
public function setPKICipherObject(Zend_InfoCard_Cipher_PKI_Interface $cipherObj)
116
$this->_infoCard->setPKICipherObject($cipherObj);
121
* Retrieves the Symmetric cipher object being used
123
* @return Zend_InfoCard_Cipher_Symmetric_Interface
125
public function getSymCipherObject()
127
return $this->_infoCard->getSymCipherObject();
131
* Sets the InfoCard symmetric cipher object to use
133
* @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj
134
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
136
public function setSymCipherObject(Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj)
138
$this->_infoCard->setSymCipherObject($cipherObj);
143
* Remove a Certificate Pair by Key ID from the search list
145
* @param string $key_id The Certificate Key ID returned from adding the certificate pair
146
* @throws Zend_InfoCard_Exception
147
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
149
public function removeCertificatePair($key_id)
151
$this->_infoCard->removeCertificatePair($key_id);
156
* Add a Certificate Pair to the list of certificates searched by the component
158
* @param string $private_key_file The path to the private key file for the pair
159
* @param string $public_key_file The path to the certificate / public key for the pair
160
* @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding)
161
* @param string $password (optional) The password for the private key file if necessary
162
* @throws Zend_InfoCard_Exception
163
* @return string A key ID representing this key pair in the component
165
public function addCertificatePair($private_key_file, $public_key_file, $type = Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null)
167
return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password);
171
* Return a Certificate Pair from a key ID
173
* @param string $key_id The Key ID of the certificate pair in the component
174
* @throws Zend_InfoCard_Exception
175
* @return array An array containing the path to the private/public key files,
176
* the type URI and the password if provided
178
public function getCertificatePair($key_id)
180
return $this->_infoCard->getCertificatePair($key_id);
184
* Set the XML Token to be processed
186
* @param string $strXmlToken The XML token to process
187
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
189
public function setXmlToken($strXmlToken)
191
$this->_xmlToken = $strXmlToken;
196
* Get the XML Token being processed
198
* @return string The XML token to be processed
200
public function getXmlToken()
202
return $this->_xmlToken;
206
* Authenticates the XML token
208
* @return Zend_Auth_Result The result of the authentication
210
public function authenticate()
213
$claims = $this->_infoCard->process($this->getXmlToken());
214
} catch(Exception $e) {
215
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE , null, array('Exception Thrown',
217
$e->getTraceAsString(),
221
if(!$claims->isValid()) {
222
switch($claims->getCode()) {
223
case Zend_infoCard_Claims::RESULT_PROCESSING_FAILURE:
224
return new Zend_Auth_Result(
225
Zend_Auth_Result::FAILURE,
228
'Processing Failure',
229
$claims->getErrorMsg()
233
case Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE:
234
return new Zend_Auth_Result(
235
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
238
'Validation Failure',
239
$claims->getErrorMsg()
244
return new Zend_Auth_Result(
245
Zend_Auth_Result::FAILURE,
249
$claims->getErrorMsg()
256
return new Zend_Auth_Result(
257
Zend_Auth_Result::SUCCESS,