| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Copyright 2014 SURFnet bv | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * you may not use this file except in compliance with the License. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * You may obtain a copy of the License at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Unless required by applicable law or agreed to in writing, software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * See the License for the specific language governing permissions and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * limitations under the License. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | namespace Surfnet\StepupMiddlewareClient\Identity\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Surfnet\StepupMiddlewareClient\Exception\AccessDeniedToResourceException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Surfnet\StepupMiddlewareClient\Exception\MalformedResponseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Surfnet\StepupMiddlewareClient\Exception\ResourceReadException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Surfnet\StepupMiddlewareClient\Identity\Dto\UnverifiedSecondFactorSearchQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorOfIdentitySearchQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorSearchQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Surfnet\StepupMiddlewareClient\Identity\Dto\VettedSecondFactorSearchQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Surfnet\StepupMiddlewareClient\Service\ApiService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Provides remote read access to the Middleware's second factors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | class SecondFactorService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var ApiService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private $apiService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param ApiService $apiService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function __construct(ApiService $apiService) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->apiService = $apiService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param string $secondFactorId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function getUnverified($secondFactorId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return $this->apiService->read('unverified-second-factor/%s', [$secondFactorId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param string $secondFactorId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function getVerified($secondFactorId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         return $this->apiService->read('verified-second-factor/%s', [$secondFactorId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $secondFactorId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function getVetted($secondFactorId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         return $this->apiService->read('vetted-second-factor/%s', [$secondFactorId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param UnverifiedSecondFactorSearchQuery $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function searchUnverified(UnverifiedSecondFactorSearchQuery $query) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $this->apiService->read('unverified-second-factors' . $query->toHttpQuery()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @param VerifiedSecondFactorSearchQuery $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     public function searchVerified(VerifiedSecondFactorSearchQuery $query) | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         return $this->apiService->read('verified-second-factors' . $query->toHttpQuery()); | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param VerifiedSecondFactorOfIdentitySearchQuery $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     public function searchOwnVerified(VerifiedSecondFactorOfIdentitySearchQuery $query) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return $this->apiService->read('verified-second-factors-of-identity' . $query->toHttpQuery()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @param VettedSecondFactorSearchQuery $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @return null|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @throws ResourceReadException When the server doesn't respond with the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     public function searchVetted(VettedSecondFactorSearchQuery $query) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         return $this->apiService->read('vetted-second-factors' . $query->toHttpQuery()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 131 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 132 |  |  |  |