| Total Complexity | 45 |
| Total Lines | 548 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AuthnRequest 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.
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 AuthnRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class AuthnRequest extends AbstractRequest |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @var \SimpleSAML\SAML2\XML\saml\Subject|null |
||
| 34 | */ |
||
| 35 | protected ?Subject $subject = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var \SimpleSAML\SAML2\XML\samlp\Scoping|null |
||
| 39 | */ |
||
| 40 | protected ?Scoping $scoping = null; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The options for what type of name identifier should be returned. |
||
| 44 | * |
||
| 45 | * @var \SimpleSAML\SAML2\XML\samlp\NameIDPolicy|null |
||
| 46 | */ |
||
| 47 | protected ?NameIDPolicy $nameIdPolicy = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Whether the Identity Provider must authenticate the user again. |
||
| 51 | * |
||
| 52 | * @var bool|null |
||
| 53 | */ |
||
| 54 | protected ?bool $forceAuthn = false; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Optional ProviderID attribute |
||
| 58 | * |
||
| 59 | * @var string|null |
||
| 60 | */ |
||
| 61 | protected ?string $ProviderName = null; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Set to true if this request is passive. |
||
| 65 | * |
||
| 66 | * @var bool|null |
||
| 67 | */ |
||
| 68 | protected ?bool $isPassive = false; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The URL of the assertion consumer service where the response should be delivered. |
||
| 72 | * |
||
| 73 | * @var string|null |
||
| 74 | */ |
||
| 75 | protected ?string $assertionConsumerServiceURL; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * What binding should be used when sending the response. |
||
| 79 | * |
||
| 80 | * @var string|null |
||
| 81 | */ |
||
| 82 | protected ?string $protocolBinding; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The index of the AttributeConsumingService. |
||
| 86 | * |
||
| 87 | * @var int|null |
||
| 88 | */ |
||
| 89 | protected ?int $attributeConsumingServiceIndex; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * The index of the AssertionConsumerService. |
||
| 93 | * |
||
| 94 | * @var int|null |
||
| 95 | */ |
||
| 96 | protected ?int $assertionConsumerServiceIndex = null; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * What authentication context was requested. |
||
| 100 | * |
||
| 101 | * @var \SimpleSAML\SAML2\XML\samlp\RequestedAuthnContext|null |
||
| 102 | */ |
||
| 103 | protected ?RequestedAuthnContext $requestedAuthnContext; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var \SimpleSAML\SAML2\XML\saml\Conditions|null |
||
| 107 | */ |
||
| 108 | protected ?Conditions $conditions = null; |
||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * Constructor for SAML 2 AuthnRequest |
||
| 113 | * |
||
| 114 | * @param \SimpleSAML\SAML2\XML\samlp\RequestedAuthnContext $requestedAuthnContext |
||
| 115 | * @param \SimpleSAML\SAML2\XML\saml\Subject $subject |
||
| 116 | * @param \SimpleSAML\SAML2\XML\samlp\NameIDPolicy $nameIdPolicy |
||
| 117 | * @param \SimpleSAML\SAML2\XML\saml\Conditions $conditions |
||
| 118 | * @param bool $forceAuthn |
||
| 119 | * @param bool $isPassive |
||
| 120 | * @param string|null $assertionConsumerServiceUrl |
||
| 121 | * @param int|null $assertionConsumerServiceIndex |
||
| 122 | * @param string|null $protocolBinding |
||
| 123 | * @param int|null $attributeConsumingServiceIndex |
||
| 124 | * @param string|null $providerName |
||
| 125 | * @param \SimpleSAML\SAML2\XML\saml\Issuer|null $issuer |
||
| 126 | * @param string|null $id |
||
| 127 | * @param int|null $issueInstant |
||
| 128 | * @param string|null $destination |
||
| 129 | * @param string|null $consent |
||
| 130 | * @param \SimpleSAML\SAML2\XML\samlp\Extensions|null $extensions |
||
| 131 | * @param \SimpleSAML\SAML2\XML\samlp\Scoping|null $scoping |
||
| 132 | * @throws \Exception |
||
| 133 | */ |
||
| 134 | public function __construct( |
||
| 135 | ?RequestedAuthnContext $requestedAuthnContext = null, |
||
| 136 | ?Subject $subject = null, |
||
| 137 | ?NameIDPolicy $nameIdPolicy = null, |
||
| 138 | Conditions $conditions = null, |
||
| 139 | ?bool $forceAuthn = null, |
||
| 140 | ?bool $isPassive = null, |
||
| 141 | ?string $assertionConsumerServiceUrl = null, |
||
| 142 | ?int $assertionConsumerServiceIndex = null, |
||
| 143 | ?string $protocolBinding = null, |
||
| 144 | ?int $attributeConsumingServiceIndex = null, |
||
| 145 | ?string $providerName = null, |
||
| 146 | ?Issuer $issuer = null, |
||
| 147 | ?string $id = null, |
||
| 148 | ?int $issueInstant = null, |
||
| 149 | ?string $destination = null, |
||
| 150 | ?string $consent = null, |
||
| 151 | ?Extensions $extensions = null, |
||
| 152 | ?Scoping $scoping = null |
||
| 153 | ) { |
||
| 154 | parent::__construct($issuer, $id, $issueInstant, $destination, $consent, $extensions); |
||
| 155 | |||
| 156 | $this->setRequestedAuthnContext($requestedAuthnContext); |
||
| 157 | $this->setSubject($subject); |
||
| 158 | $this->setNameIdPolicy($nameIdPolicy); |
||
| 159 | $this->setConditions($conditions); |
||
| 160 | |||
| 161 | $this->setForceAuthn($forceAuthn); |
||
| 162 | $this->setIsPassive($isPassive); |
||
| 163 | $this->setAssertionConsumerServiceUrl($assertionConsumerServiceUrl); |
||
| 164 | $this->setAssertionConsumerServiceIndex($assertionConsumerServiceIndex); |
||
| 165 | $this->setProtocolBinding($protocolBinding); |
||
| 166 | $this->setAttributeConsumingServiceIndex($attributeConsumingServiceIndex); |
||
| 167 | $this->setProviderName($providerName); |
||
| 168 | $this->setScoping($scoping); |
||
| 169 | } |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * @param \SimpleSAML\SAML2\XML\saml\Subject|null $subject |
||
| 174 | */ |
||
| 175 | private function setSubject(?Subject $subject): void |
||
| 176 | { |
||
| 177 | $this->subject = $subject; |
||
| 178 | } |
||
| 179 | |||
| 180 | |||
| 181 | /** |
||
| 182 | * @return \SimpleSAML\SAML2\XML\saml\Subject|null |
||
| 183 | */ |
||
| 184 | public function getSubject(): ?Subject |
||
| 185 | { |
||
| 186 | return $this->subject; |
||
| 187 | } |
||
| 188 | |||
| 189 | |||
| 190 | /** |
||
| 191 | * @param \SimpleSAML\SAML2\XML\samlp\Scoping|null $scoping |
||
| 192 | */ |
||
| 193 | private function setScoping(?Scoping $scoping): void |
||
| 194 | { |
||
| 195 | $this->scoping = $scoping; |
||
| 196 | } |
||
| 197 | |||
| 198 | |||
| 199 | /** |
||
| 200 | * @return \SimpleSAML\SAML2\XML\samlp\Scoping|null |
||
| 201 | */ |
||
| 202 | public function getScoping(): ?Scoping |
||
| 203 | { |
||
| 204 | return $this->scoping; |
||
| 205 | } |
||
| 206 | |||
| 207 | |||
| 208 | /** |
||
| 209 | * @param \SimpleSAML\SAML2\XML\saml\Conditions|null $conditions |
||
| 210 | */ |
||
| 211 | private function setConditions(?Conditions $conditions): void |
||
| 212 | { |
||
| 213 | $this->conditions = $conditions; |
||
| 214 | } |
||
| 215 | |||
| 216 | |||
| 217 | /** |
||
| 218 | * @return \SimpleSAML\SAML2\XML\saml\Conditions|null |
||
| 219 | */ |
||
| 220 | public function getConditions(): ?Conditions |
||
| 221 | { |
||
| 222 | return $this->conditions; |
||
| 223 | } |
||
| 224 | |||
| 225 | |||
| 226 | /** |
||
| 227 | * Retrieve the NameIdPolicy. |
||
| 228 | * |
||
| 229 | * @see \SimpleSAML\SAML2\AuthnRequest::setNameIdPolicy() |
||
| 230 | * @return \SimpleSAML\SAML2\XML\samlp\NameIDPolicy|null The NameIdPolicy. |
||
| 231 | */ |
||
| 232 | public function getNameIdPolicy(): ?NameIDPolicy |
||
| 233 | { |
||
| 234 | return $this->nameIdPolicy; |
||
| 235 | } |
||
| 236 | |||
| 237 | |||
| 238 | /** |
||
| 239 | * Set the NameIDPolicy. |
||
| 240 | * |
||
| 241 | * @param \SimpleSAML\SAML2\XML\samlp\NameIDPolicy|null $nameIdPolicy The NameIDPolicy. |
||
| 242 | */ |
||
| 243 | private function setNameIdPolicy(?NameIDPolicy $nameIdPolicy): void |
||
| 244 | { |
||
| 245 | $this->nameIdPolicy = $nameIdPolicy; |
||
| 246 | } |
||
| 247 | |||
| 248 | |||
| 249 | /** |
||
| 250 | * Retrieve the value of the ForceAuthn attribute. |
||
| 251 | * |
||
| 252 | * @return bool|null The ForceAuthn attribute. |
||
| 253 | */ |
||
| 254 | public function getForceAuthn(): ?bool |
||
| 255 | { |
||
| 256 | return $this->forceAuthn; |
||
| 257 | } |
||
| 258 | |||
| 259 | |||
| 260 | /** |
||
| 261 | * Set the value of the ForceAuthn attribute. |
||
| 262 | * |
||
| 263 | * @param bool $forceAuthn The ForceAuthn attribute. |
||
| 264 | */ |
||
| 265 | private function setForceAuthn(?bool $forceAuthn): void |
||
| 266 | { |
||
| 267 | $this->forceAuthn = $forceAuthn; |
||
| 268 | } |
||
| 269 | |||
| 270 | |||
| 271 | /** |
||
| 272 | * Retrieve the value of the ProviderName attribute. |
||
| 273 | * |
||
| 274 | * @return string|null The ProviderName attribute. |
||
| 275 | */ |
||
| 276 | public function getProviderName(): ?string |
||
| 279 | } |
||
| 280 | |||
| 281 | |||
| 282 | /** |
||
| 283 | * Set the value of the ProviderName attribute. |
||
| 284 | * |
||
| 285 | * @param string|null $ProviderName The ProviderName attribute. |
||
| 286 | */ |
||
| 287 | private function setProviderName(?string $ProviderName): void |
||
| 288 | { |
||
| 289 | Assert::nullOrNotWhitespaceOnly($ProviderName); |
||
| 290 | $this->ProviderName = $ProviderName; |
||
| 291 | } |
||
| 292 | |||
| 293 | |||
| 294 | /** |
||
| 295 | * Retrieve the value of the IsPassive attribute. |
||
| 296 | * |
||
| 297 | * @return bool|null The IsPassive attribute. |
||
| 298 | */ |
||
| 299 | public function getIsPassive(): ?bool |
||
| 302 | } |
||
| 303 | |||
| 304 | |||
| 305 | /** |
||
| 306 | * Set the value of the IsPassive attribute. |
||
| 307 | * |
||
| 308 | * @param bool|null $isPassive The IsPassive attribute. |
||
| 309 | */ |
||
| 310 | private function setIsPassive(?bool $isPassive): void |
||
| 311 | { |
||
| 312 | $this->isPassive = $isPassive; |
||
| 313 | } |
||
| 314 | |||
| 315 | |||
| 316 | /** |
||
| 317 | * Retrieve the value of the AssertionConsumerServiceURL attribute. |
||
| 318 | * |
||
| 319 | * @return string|null The AssertionConsumerServiceURL attribute. |
||
| 320 | */ |
||
| 321 | public function getAssertionConsumerServiceURL(): ?string |
||
| 322 | { |
||
| 323 | return $this->assertionConsumerServiceURL; |
||
| 324 | } |
||
| 325 | |||
| 326 | |||
| 327 | /** |
||
| 328 | * Set the value of the AssertionConsumerServiceURL attribute. |
||
| 329 | * |
||
| 330 | * @param string|null $assertionConsumerServiceURL The AssertionConsumerServiceURL attribute. |
||
| 331 | */ |
||
| 332 | private function setAssertionConsumerServiceURL(string $assertionConsumerServiceURL = null): void |
||
| 339 | } |
||
| 340 | |||
| 341 | |||
| 342 | /** |
||
| 343 | * Retrieve the value of the ProtocolBinding attribute. |
||
| 344 | * |
||
| 345 | * @return string|null The ProtocolBinding attribute. |
||
| 346 | */ |
||
| 347 | public function getProtocolBinding(): ?string |
||
| 348 | { |
||
| 349 | return $this->protocolBinding; |
||
| 350 | } |
||
| 351 | |||
| 352 | |||
| 353 | /** |
||
| 354 | * Set the value of the ProtocolBinding attribute. |
||
| 355 | * |
||
| 356 | * @param string|null $protocolBinding The ProtocolBinding attribute. |
||
| 357 | */ |
||
| 358 | private function setProtocolBinding(?string $protocolBinding): void |
||
| 359 | { |
||
| 360 | Assert::nullOrNotWhitespaceOnly($protocolBinding); |
||
| 361 | |||
| 362 | $this->protocolBinding = $protocolBinding; |
||
| 363 | } |
||
| 364 | |||
| 365 | |||
| 366 | /** |
||
| 367 | * Retrieve the value of the AttributeConsumingServiceIndex attribute. |
||
| 368 | * |
||
| 369 | * @return int|null The AttributeConsumingServiceIndex attribute. |
||
| 370 | */ |
||
| 371 | public function getAttributeConsumingServiceIndex(): ?int |
||
| 374 | } |
||
| 375 | |||
| 376 | |||
| 377 | /** |
||
| 378 | * Set the value of the AttributeConsumingServiceIndex attribute. |
||
| 379 | * |
||
| 380 | * @param int|null $attributeConsumingServiceIndex The AttributeConsumingServiceIndex attribute. |
||
| 381 | */ |
||
| 382 | private function setAttributeConsumingServiceIndex(?int $attributeConsumingServiceIndex): void |
||
| 383 | { |
||
| 384 | Assert::nullOrRange($attributeConsumingServiceIndex, 0, 65535); |
||
| 385 | $this->attributeConsumingServiceIndex = $attributeConsumingServiceIndex; |
||
| 386 | } |
||
| 387 | |||
| 388 | |||
| 389 | /** |
||
| 390 | * Retrieve the value of the AssertionConsumerServiceIndex attribute. |
||
| 391 | * |
||
| 392 | * @return int|null The AssertionConsumerServiceIndex attribute. |
||
| 393 | */ |
||
| 394 | public function getAssertionConsumerServiceIndex(): ?int |
||
| 395 | { |
||
| 396 | return $this->assertionConsumerServiceIndex; |
||
| 397 | } |
||
| 398 | |||
| 399 | |||
| 400 | /** |
||
| 401 | * Set the value of the AssertionConsumerServiceIndex attribute. |
||
| 402 | * |
||
| 403 | * @param int|null $assertionConsumerServiceIndex The AssertionConsumerServiceIndex attribute. |
||
| 404 | */ |
||
| 405 | private function setAssertionConsumerServiceIndex(?int $assertionConsumerServiceIndex): void |
||
| 409 | } |
||
| 410 | |||
| 411 | |||
| 412 | /** |
||
| 413 | * Retrieve the RequestedAuthnContext. |
||
| 414 | * |
||
| 415 | * @return \SimpleSAML\SAML2\XML\samlp\RequestedAuthnContext|null The RequestedAuthnContext. |
||
| 416 | */ |
||
| 417 | public function getRequestedAuthnContext(): ?RequestedAuthnContext |
||
| 418 | { |
||
| 419 | return $this->requestedAuthnContext; |
||
| 420 | } |
||
| 421 | |||
| 422 | |||
| 423 | /** |
||
| 424 | * Set the RequestedAuthnContext. |
||
| 425 | * |
||
| 426 | * @param \SimpleSAML\SAML2\XML\samlp\RequestedAuthnContext|null $requestedAuthnContext The RequestedAuthnContext. |
||
| 427 | */ |
||
| 428 | private function setRequestedAuthnContext(RequestedAuthnContext $requestedAuthnContext = null): void |
||
| 431 | } |
||
| 432 | |||
| 433 | |||
| 434 | /** |
||
| 435 | * Convert XML into an AuthnRequest |
||
| 436 | * |
||
| 437 | * @param \DOMElement $xml The XML element we should load |
||
| 438 | * @return \SimpleSAML\SAML2\XML\samlp\AuthnRequest |
||
| 439 | * |
||
| 440 | * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException if the qualified name of the supplied element is wrong |
||
| 441 | * @throws \SimpleSAML\XML\Exception\MissingAttributeException if the supplied element is missing one of the mandatory attributes |
||
| 442 | * @throws \SimpleSAML\XML\Exception\TooManyElementsException if too many child-elements of a type are specified |
||
| 443 | */ |
||
| 444 | public static function fromXML(DOMElement $xml): object |
||
| 445 | { |
||
| 446 | Assert::same($xml->localName, 'AuthnRequest', InvalidDOMElementException::class); |
||
| 447 | Assert::same($xml->namespaceURI, AuthnRequest::NS, InvalidDOMElementException::class); |
||
| 514 | } |
||
| 515 | |||
| 516 | |||
| 517 | /** |
||
| 518 | * Convert this message to an unsigned XML document. |
||
| 519 | * This method does not sign the resulting XML document. |
||
| 520 | * |
||
| 521 | * @param \DOMElement|null $parent |
||
| 522 | * @return \DOMElement The root element of the DOM tree |
||
| 523 | */ |
||
| 524 | protected function toUnsignedXML(?DOMElement $parent = null): DOMElement |
||
| 580 |