|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
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. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_InfoCard |
|
17 * @subpackage Zend_InfoCard_Xml_Security |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Transform.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * A class to create a transform rule set based on XML URIs and then apply those rules |
|
25 * in the correct order to a given XML input |
|
26 * |
|
27 * @category Zend |
|
28 * @package Zend_InfoCard |
|
29 * @subpackage Zend_InfoCard_Xml_Security |
|
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
32 */ |
|
33 class Zend_InfoCard_Xml_Security_Transform |
|
34 { |
|
35 /** |
|
36 * A list of transforms to apply |
|
37 * |
|
38 * @var array |
|
39 */ |
|
40 protected $_transformList = array(); |
|
41 |
|
42 /** |
|
43 * Returns the name of the transform class based on a given URI |
|
44 * |
|
45 * @throws Zend_InfoCard_Xml_Security_Exception |
|
46 * @param string $uri The transform URI |
|
47 * @return string The transform implementation class name |
|
48 */ |
|
49 protected function _findClassbyURI($uri) |
|
50 { |
|
51 switch($uri) { |
|
52 case 'http://www.w3.org/2000/09/xmldsig#enveloped-signature': |
|
53 return 'Zend_InfoCard_Xml_Security_Transform_EnvelopedSignature'; |
|
54 case 'http://www.w3.org/2001/10/xml-exc-c14n#': |
|
55 return 'Zend_InfoCard_Xml_Security_Transform_XmlExcC14N'; |
|
56 default: |
|
57 require_once 'Zend/InfoCard/Xml/Security/Exception.php'; |
|
58 throw new Zend_InfoCard_Xml_Security_Exception("Unknown or Unsupported Transformation Requested"); |
|
59 } |
|
60 } |
|
61 |
|
62 /** |
|
63 * Add a Transform URI to the list of transforms to perform |
|
64 * |
|
65 * @param string $uri The Transform URI |
|
66 * @return Zend_InfoCard_Xml_Security_Transform |
|
67 */ |
|
68 public function addTransform($uri) |
|
69 { |
|
70 $class = $this->_findClassbyURI($uri); |
|
71 |
|
72 $this->_transformList[] = array('uri' => $uri, |
|
73 'class' => $class); |
|
74 return $this; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Return the list of transforms to perform |
|
79 * |
|
80 * @return array The list of transforms |
|
81 */ |
|
82 public function getTransformList() |
|
83 { |
|
84 return $this->_transformList; |
|
85 } |
|
86 |
|
87 /** |
|
88 * Apply the transforms in the transform list to the input XML document |
|
89 * |
|
90 * @param string $strXmlDocument The input XML |
|
91 * @return string The XML after the transformations have been applied |
|
92 */ |
|
93 public function applyTransforms($strXmlDocument) |
|
94 { |
|
95 foreach($this->_transformList as $transform) { |
|
96 if (!class_exists($transform['class'])) { |
|
97 require_once 'Zend/Loader.php'; |
|
98 Zend_Loader::loadClass($transform['class']); |
|
99 } |
|
100 |
|
101 $transformer = new $transform['class']; |
|
102 |
|
103 // We can't really test this check because it would require logic changes in the component itself |
|
104 // @codeCoverageIgnoreStart |
|
105 if(!($transformer instanceof Zend_InfoCard_Xml_Security_Transform_Interface)) { |
|
106 require_once 'Zend/InfoCard/Xml/Security/Exception.php'; |
|
107 throw new Zend_InfoCard_Xml_Security_Exception("Transforms must implement the Transform Interface"); |
|
108 } |
|
109 // @codeCoverageIgnoreEnd |
|
110 |
|
111 $strXmlDocument = $transformer->transform($strXmlDocument); |
|
112 } |
|
113 |
|
114 return $strXmlDocument; |
|
115 } |
|
116 } |