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\IdentitySearchQuery; |
25
|
|
|
use Surfnet\StepupMiddlewareClient\Service\ApiService; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Provides remote read access to the Middleware's identities. |
29
|
|
|
*/ |
30
|
|
|
class IdentityService |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var ApiService |
34
|
|
|
*/ |
35
|
|
|
private $apiService; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ApiService $apiService |
39
|
|
|
*/ |
40
|
|
|
public function __construct(ApiService $apiService) |
41
|
|
|
{ |
42
|
|
|
$this->apiService = $apiService; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $id |
47
|
|
|
* @return null|array |
48
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
49
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
50
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
51
|
|
|
*/ |
52
|
|
|
public function get($id) |
53
|
|
|
{ |
54
|
|
|
return $this->apiService->read('identity/%s', [$id]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param IdentitySearchQuery $searchQuery |
59
|
|
|
* @return array|null |
60
|
|
|
*/ |
61
|
|
|
public function search(IdentitySearchQuery $searchQuery) |
62
|
|
|
{ |
63
|
|
|
return $this->apiService->read('identity', [], $searchQuery); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $identityId |
68
|
|
|
* @return array|null |
69
|
|
|
*/ |
70
|
|
|
public function getRegistrationAuthorityCredentials($identityId) |
71
|
|
|
{ |
72
|
|
|
return $this->apiService->read('registration-authority/%s', [$identityId]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|