Conditions | 7 |
Paths | 10 |
Total Lines | 75 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
87 | public function consumeAssertion(Provider $provider, Request $httpRequest, ProxyResponseFactory $proxyResponseFactory) |
||
88 | { |
||
89 | $stateHandler = $provider->getStateHandler(); |
||
90 | $originalRequestId = $stateHandler->getRequestId(); |
||
91 | |||
92 | $this->handledRequestId = $originalRequestId; |
||
93 | |||
94 | $logger = $this->samlLogger->forAuthentication($originalRequestId); |
||
|
|||
95 | |||
96 | $action = $stateHandler->hasSubject() ? 'Second Factor Verification' : 'Proxy Response'; |
||
97 | $logger->notice( |
||
98 | sprintf('Received SAMLResponse, attempting to process for %s', $action) |
||
99 | ); |
||
100 | |||
101 | try { |
||
102 | $assertion = $this->postBinding->processResponse( |
||
103 | $httpRequest, |
||
104 | $provider->getRemoteIdentityProvider(), |
||
105 | $provider->getServiceProvider() |
||
106 | ); |
||
107 | } catch (Exception $exception) { |
||
108 | $message = sprintf('Could not process received Response, error: "%s"', $exception->getMessage()); |
||
109 | $logger->error($message); |
||
110 | // Only pass along the original message back to the SP |
||
111 | throw new ResponseFailureException($exception->getMessage()); |
||
112 | } |
||
113 | |||
114 | $adaptedAssertion = new AssertionAdapter($assertion); |
||
115 | $expectedResponse = $stateHandler->getGatewayRequestId(); |
||
116 | if (!$adaptedAssertion->inResponseToMatches($expectedResponse)) { |
||
117 | throw new UnknownInResponseToException( |
||
118 | $adaptedAssertion->getInResponseTo(), |
||
119 | $expectedResponse |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | $authenticatedNameId = $assertion->getNameId(); |
||
124 | $isSubjectRequested = $stateHandler->hasSubject(); |
||
125 | if ($isSubjectRequested && ($stateHandler->getSubject() !== $authenticatedNameId->getValue())) { |
||
126 | $message = sprintf( |
||
127 | 'Requested Subject NameID "%s" and Response NameID "%s" do not match', |
||
128 | $stateHandler->getSubject(), |
||
129 | $authenticatedNameId->getValue() |
||
130 | ); |
||
131 | $logger->critical($message); |
||
132 | |||
133 | throw new InvalidSubjectException($message); |
||
134 | } |
||
135 | |||
136 | $logger->notice('Successfully processed SAMLResponse'); |
||
137 | |||
138 | if ($stateHandler->secondFactorVerificationRequested()) { |
||
139 | $message = 'Second Factor verification was requested and was successful, forwarding to SecondFactor handling'; |
||
140 | $logger->notice($message); |
||
141 | |||
142 | throw new SecondfactorVerificationRequiredException($message); |
||
143 | } |
||
144 | |||
145 | $targetServiceProvider = $this->getServiceProvider($stateHandler->getRequestServiceProvider()); |
||
146 | |||
147 | $response = $proxyResponseFactory->createProxyResponse( |
||
148 | $assertion, |
||
149 | $targetServiceProvider->determineAcsLocation( |
||
150 | $stateHandler->getRequestAssertionConsumerServiceUrl(), |
||
151 | $this->logger |
||
152 | ) |
||
153 | ); |
||
154 | |||
155 | $logger->notice(sprintf( |
||
156 | 'Responding to request "%s" with response based on response from the remote IdP with response "%s"', |
||
157 | $stateHandler->getRequestId(), |
||
158 | $response->getId() |
||
159 | )); |
||
160 | |||
161 | return $response; |
||
162 | } |
||
181 |