ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Processor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\Response;
4 
10 use SAML2\Response;
17 
21 class Processor
22 {
26  private $logger;
27 
32 
37 
42 
49  private $responseIsSigned = false;
50 
56  {
57  $this->logger = $logger;
58 
59  $this->signatureValidator = new Validator($logger);
60  }
61 
70  public function process(
71  ServiceProvider $serviceProviderConfiguration,
72  IdentityProvider $identityProviderConfiguration,
73  Destination $currentDestination,
75  ) {
76  $this->preconditionValidator = new PreconditionValidator($currentDestination);
77  $this->assertionProcessor = ProcessorBuilder::build(
78  $this->logger,
79  $this->signatureValidator,
80  $currentDestination,
81  $identityProviderConfiguration,
82  $serviceProviderConfiguration,
83  $response
84  );
85 
86  $this->enforcePreconditions($response);
87  $this->verifySignature($response, $identityProviderConfiguration);
88  return $this->processAssertions($response);
89  }
90 
97  {
98  $result = $this->preconditionValidator->validate($response);
99 
100  if (!$result->isValid()) {
101  throw PreconditionNotMetException::createFromValidationResult($result);
102  }
103  }
104 
109  private function verifySignature(
111  IdentityProvider $identityProviderConfiguration
112  ) {
113  if (!$response->isMessageConstructedWithSignature()) {
114  $this->logger->info(sprintf(
115  'SAMLResponse with id "%s" was not signed at root level, not attempting to verify the signature of the'
116  . ' reponse itself',
117  $response->getId()
118  ));
119 
120  return;
121  }
122 
123  $this->logger->info(sprintf(
124  'Attempting to verify the signature of SAMLResponse with id "%s"',
125  $response->getId()
126  ));
127 
128  $this->responseIsSigned = true;
129 
130  if (!$this->signatureValidator->hasValidSignature($response, $identityProviderConfiguration)) {
131  throw new InvalidResponseException();
132  }
133  }
134 
141  {
142  $assertions = $response->getAssertions();
143  if (empty($assertions)) {
144  throw new NoAssertionsFoundException('No assertions found in response from IdP.');
145  }
146 
147  if (!$this->responseIsSigned) {
148  foreach ($assertions as $assertion) {
149  if (!$assertion->getWasSignedAtConstruction()) {
150  throw new UnsignedResponseException(
151  'Both the response and the assertion it contains are not signed.'
152  );
153  }
154  }
155  }
156 
157  return $this->assertionProcessor->processAssertions($assertions);
158  }
159 }
processAssertions(Response $response)
Definition: Processor.php:140
Basic configuration wrapper.
(PHPMD.CouplingBetweenObjects) - due to specific exceptions
Definition: Processor.php:21
Validates the preconditions that have to be met prior to processing of the response.
Basic Configuration Wrapper.
$result
process(ServiceProvider $serviceProviderConfiguration, IdentityProvider $identityProviderConfiguration, Destination $currentDestination, Response $response)
Definition: Processor.php:70
enforcePreconditions(Response $response)
Checks the preconditions that must be valid in order for the response to be processed.
Definition: Processor.php:96
getAssertions()
Retrieve the assertions in this response.
Definition: Response.php:50
__construct(LoggerInterface $logger)
Definition: Processor.php:55
isMessageConstructedWithSignature()
Query whether or not the message contained a signature at the root level when the object was construc...
Definition: Message.php:401
getId()
Retrieve the identifier of this message.
Definition: Message.php:279
verifySignature(Response $response, IdentityProvider $identityProviderConfiguration)
Definition: Processor.php:109
Describes a logger instance.
build(array $parts)
This function takes the components returned from PHP&#39;s parse_url, and uses it to generate a new uri...
Definition: functions.php:221
Value Object representing the current destination.
Definition: Destination.php:10
Signature Validator.
Definition: Validator.php:14
$response
$assertions
The assertions in this response.
Definition: Response.php:15