ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Processor.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2\Response;
4
17
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,
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()) {
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()) {
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}
sprintf('%.4f', $callTime)
$result
An exception for terminatinating execution or to throw for unit testing.
Simple Builder that allows to build a new Assertion Processor.
static build(LoggerInterface $logger, Validator $signatureValidator, Destination $currentDestination, IdentityProvider $identityProvider, ServiceProvider $serviceProvider, Response $response)
Value Object representing the current destination.
Definition: Destination.php:11
Basic configuration wrapper.
Basic Configuration Wrapper.
Named exception to indicate that the preconditions for processing the SAML response have not been met...
@SuppressWarnings(PHPMD.CouplingBetweenObjects) - due to specific exceptions
Definition: Processor.php:22
__construct(LoggerInterface $logger)
Definition: Processor.php:55
verifySignature(Response $response, IdentityProvider $identityProviderConfiguration)
Definition: Processor.php:109
enforcePreconditions(Response $response)
Checks the preconditions that must be valid in order for the response to be processed.
Definition: Processor.php:96
processAssertions(Response $response)
Definition: Processor.php:140
process(ServiceProvider $serviceProviderConfiguration, IdentityProvider $identityProviderConfiguration, Destination $currentDestination, Response $response)
Definition: Processor.php:70
Validates the preconditions that have to be met prior to processing of the response.
$assertions
The assertions in this response.
Definition: Response.php:15
Signature Validator.
Definition: Validator.php:15
Describes a logger instance.
$response