Complex classes like WsSecurityFilterRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WsSecurityFilterRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class WsSecurityFilterRequest extends AbstractWsSecurityFilter |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Web Services Security: SOAP Message Security 1.0 (WS-Security 2004) |
||
| 12 | */ |
||
| 13 | const NAME_WSS_SMS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Web Services Security UsernameToken Profile 1.0 |
||
| 17 | */ |
||
| 18 | const NAME_WSS_UTP = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Web Services Security X.509 Certificate Token Profile |
||
| 22 | */ |
||
| 23 | const NAME_WSS_X509 = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The date format to be used with {@link \DateTime} |
||
| 27 | */ |
||
| 28 | const DATETIME_FORMAT = 'Y-m-d\TH:i:s.000\Z'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * (X509 3.2.1) Reference to a Subject Key Identifier |
||
| 32 | */ |
||
| 33 | const TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER = 0; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * (X509 3.2.1) Reference to a Security Token |
||
| 37 | */ |
||
| 38 | const TOKEN_REFERENCE_SECURITY_TOKEN = 1; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * (SMS_1.1 7.3) Key Identifiers |
||
| 42 | */ |
||
| 43 | const TOKEN_REFERENCE_THUMBPRINT_SHA1 = 2; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * (SMS 10) Add security timestamp. |
||
| 47 | * |
||
| 48 | * @var boolean |
||
| 49 | */ |
||
| 50 | private $addTimestamp = true; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Encrypt the signature? |
||
| 54 | * |
||
| 55 | * @var boolean |
||
| 56 | */ |
||
| 57 | private $encryptSignature = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * (SMS 10) Security timestamp expires time in seconds. |
||
| 61 | * |
||
| 62 | * @var int |
||
| 63 | */ |
||
| 64 | private $expires = 300; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Sign all headers. |
||
| 68 | * |
||
| 69 | * @var boolean |
||
| 70 | */ |
||
| 71 | private $signAllHeaders = false; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var \DateTime |
||
| 75 | */ |
||
| 76 | private $initialTimestamp; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * (X509 3.2) Token reference type for encryption. |
||
| 80 | * |
||
| 81 | * @var int |
||
| 82 | */ |
||
| 83 | private $tokenReferenceEncryption = null; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * (X509 3.2) Token reference type for signature. |
||
| 87 | * |
||
| 88 | * @var int |
||
| 89 | */ |
||
| 90 | private $tokenReferenceSignature = null; |
||
| 91 | |||
| 92 | |||
| 93 | public function setTimestampOptions($addTimestamp = true, $expires = 300) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param \DateTime $initialTimestamp |
||
| 101 | */ |
||
| 102 | public function __construct(\DateTime $initialTimestamp = null) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Set security options. |
||
| 109 | * |
||
| 110 | * @param int $tokenReference self::TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | self::TOKEN_REFERENCE_SECURITY_TOKEN | self::TOKEN_REFERENCE_THUMBPRINT_SHA1 |
||
| 111 | * @param boolean $encryptSignature Encrypt signature |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | public function setSecurityOptionsEncryption($tokenReference, $encryptSignature = false) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Set security options. |
||
| 123 | * |
||
| 124 | * @param int $tokenReference self::TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | self::TOKEN_REFERENCE_SECURITY_TOKEN | self::TOKEN_REFERENCE_THUMBPRINT_SHA1 |
||
| 125 | * @param boolean $signAllHeaders Sign all headers? |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | public function setSecurityOptionsSignature($tokenReference, $signAllHeaders = false) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Adds the configured KeyInfo to the parentNode. |
||
| 137 | * |
||
| 138 | * @param \DOMDocument $dom |
||
| 139 | * @param int $tokenReference Token reference type |
||
| 140 | * @param string $guid Unique ID |
||
| 141 | * @param XmlSecurityKey $xmlSecurityKey XML security key |
||
| 142 | * |
||
| 143 | * @return \DOMElement |
||
| 144 | */ |
||
| 145 | private function createKeyInfo(\DOMDocument $dom, $tokenReference, $guid, XmlSecurityKey $xmlSecurityKey = null) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Create a list of \DOMNodes that should be encrypted. |
||
| 183 | * |
||
| 184 | * @param \DOMDocument $dom DOMDocument to query |
||
| 185 | * |
||
| 186 | * @return \DOMNodeList |
||
| 187 | */ |
||
| 188 | private function createNodeListForEncryption(\DOMDocument $dom) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Create a list of \DOMNodes that should be signed. |
||
| 204 | * |
||
| 205 | * @param \DOMDocument $dom DOMDocument to query |
||
| 206 | * @param \DOMElement $security Security element |
||
| 207 | * |
||
| 208 | * @return array(\DOMNode) |
||
|
|
|||
| 209 | */ |
||
| 210 | private function createNodeListForSigning(\DOMDocument $dom, \DOMElement $security) |
||
| 233 | |||
| 234 | |||
| 235 | /** |
||
| 236 | * Modify the given request XML. |
||
| 237 | * |
||
| 238 | * @param \DOMDocument $dom |
||
| 239 | * @param Security $securityData |
||
| 240 | * |
||
| 241 | * @return \DOMElement |
||
| 242 | */ |
||
| 243 | public function filterDom(\DOMDocument $dom, Security $securityData) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Generate a pseudo-random version 4 UUID. |
||
| 293 | * |
||
| 294 | * @see http://de.php.net/manual/en/function.uniqid.php#94959 |
||
| 295 | * |
||
| 296 | * @return string |
||
| 297 | */ |
||
| 298 | private static function generateUUID() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param \DOMElement $security |
||
| 320 | * @param \DateTime $dt |
||
| 321 | */ |
||
| 322 | private function handleTimestamp(\DOMElement $security, \DateTime $dt) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param \DOMElement $security |
||
| 340 | * @param $dt |
||
| 341 | * @param Security $securityData |
||
| 342 | */ |
||
| 343 | private function handleUsername(\DOMElement $security, $dt, Security $securityData) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param \DOMElement $security |
||
| 381 | * @return \DOMElement |
||
| 382 | */ |
||
| 383 | private function handleSignature(\DOMElement $security) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param \DOMElement $security |
||
| 423 | * @param \DOMElement $signature |
||
| 424 | */ |
||
| 425 | private function handleEncryption(\DOMElement $security, \DOMElement $signature) |
||
| 447 | } |
||
| 448 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.