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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: InfoCard.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
require_once 'Zend/Auth/Adapter/Interface.php';
/**
* @see Zend_Auth_Result
*/
require_once 'Zend/Auth/Result.php';
/**
* @see Zend_InfoCard
*/
require_once 'Zend/InfoCard.php';
/**
* A Zend_Auth Authentication Adapter allowing the use of Information Cards as an
* authentication mechanism
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_InfoCard implements Zend_Auth_Adapter_Interface
{
/**
* The XML Token being authenticated
*
* @var string
*/
protected $_xmlToken;
/**
* The instance of Zend_InfoCard
*
* @var Zend_InfoCard
*/
protected $_infoCard;
/**
* Constructor
*
* @param string $strXmlDocument The XML Token provided by the client
* @return void
*/
public function __construct($strXmlDocument)
{
$this->_xmlToken = $strXmlDocument;
$this->_infoCard = new Zend_InfoCard();
}
/**
* Sets the InfoCard component Adapter to use
*
* @param Zend_InfoCard_Adapter_Interface $a
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
*/
public function setAdapter(Zend_InfoCard_Adapter_Interface $a)
{
$this->_infoCard->setAdapter($a);
return $this;
}
/**
* Retrieves the InfoCard component adapter being used
*
* @return Zend_InfoCard_Adapter_Interface
*/
public function getAdapter()
{
return $this->_infoCard->getAdapter();
}
/**
* Retrieves the InfoCard public key cipher object being used
*
* @return Zend_InfoCard_Cipher_PKI_Interface
*/
public function getPKCipherObject()
{
return $this->_infoCard->getPKCipherObject();
}
/**
* Sets the InfoCard public key cipher object to use
*
* @param Zend_InfoCard_Cipher_PKI_Interface $cipherObj
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
*/
public function setPKICipherObject(Zend_InfoCard_Cipher_PKI_Interface $cipherObj)
{
$this->_infoCard->setPKICipherObject($cipherObj);
return $this;
}
/**
* Retrieves the Symmetric cipher object being used
*
* @return Zend_InfoCard_Cipher_Symmetric_Interface
*/
public function getSymCipherObject()
{
return $this->_infoCard->getSymCipherObject();
}
/**
* Sets the InfoCard symmetric cipher object to use
*
* @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
*/
public function setSymCipherObject(Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj)
{
$this->_infoCard->setSymCipherObject($cipherObj);
return $this;
}
/**
* Remove a Certificate Pair by Key ID from the search list
*
* @param string $key_id The Certificate Key ID returned from adding the certificate pair
* @throws Zend_InfoCard_Exception
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
*/
public function removeCertificatePair($key_id)
{
$this->_infoCard->removeCertificatePair($key_id);
return $this;
}
/**
* Add a Certificate Pair to the list of certificates searched by the component
*
* @param string $private_key_file The path to the private key file for the pair
* @param string $public_key_file The path to the certificate / public key for the pair
* @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding)
* @param string $password (optional) The password for the private key file if necessary
* @throws Zend_InfoCard_Exception
* @return string A key ID representing this key pair in the component
*/
public function addCertificatePair($private_key_file, $public_key_file, $type = Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null)
{
return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password);
}
/**
* Return a Certificate Pair from a key ID
*
* @param string $key_id The Key ID of the certificate pair in the component
* @throws Zend_InfoCard_Exception
* @return array An array containing the path to the private/public key files,
* the type URI and the password if provided
*/
public function getCertificatePair($key_id)
{
return $this->_infoCard->getCertificatePair($key_id);
}
/**
* Set the XML Token to be processed
*
* @param string $strXmlToken The XML token to process
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
*/
public function setXmlToken($strXmlToken)
{
$this->_xmlToken = $strXmlToken;
return $this;
}
/**
* Get the XML Token being processed
*
* @return string The XML token to be processed
*/
public function getXmlToken()
{
return $this->_xmlToken;
}
/**
* Authenticates the XML token
*
* @return Zend_Auth_Result The result of the authentication
*/
public function authenticate()
{
try {
$claims = $this->_infoCard->process($this->getXmlToken());
} catch(Exception $e) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE , null, array('Exception Thrown',
$e->getMessage(),
$e->getTraceAsString(),
serialize($e)));
}
if(!$claims->isValid()) {
switch($claims->getCode()) {
case Zend_infoCard_Claims::RESULT_PROCESSING_FAILURE:
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE,
$claims,
array(
'Processing Failure',
$claims->getErrorMsg()
)
);
break;
case Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE:
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
$claims,
array(
'Validation Failure',
$claims->getErrorMsg()
)
);
break;
default:
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE,
$claims,
array(
'Unknown Failure',
$claims->getErrorMsg()
)
);
break;
}
}
return new Zend_Auth_Result(
Zend_Auth_Result::SUCCESS,
$claims
);
}
}
|