|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* FreeIPA library for PHP |
|
5
|
|
|
* Copyright (C) 2015-2019 Tobias Sette <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Lesser General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace Gnumoksha\FreeIpa; |
|
23
|
|
|
|
|
24
|
|
|
use Gnumoksha\FreeIpa\Infra\Rpc\ClientBuilder; |
|
25
|
|
|
use Gnumoksha\FreeIpa\Infra\Rpc\PluginClientBuilder; |
|
26
|
|
|
use Gnumoksha\FreeIpa\Infra\Rpc\Request\Body as RequestBodyInterface; |
|
27
|
|
|
use Gnumoksha\FreeIpa\Infra\Rpc\Request\CommonBody as CommonRequestBody; |
|
28
|
|
|
use Gnumoksha\FreeIpa\Infra\Rpc\Response\Body as ResponseBodyInterface; |
|
29
|
|
|
use Gnumoksha\FreeIpa\Model\User\UserRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Façade providing easy bootstrapping and convenient methods. |
|
33
|
|
|
*/ |
|
34
|
|
|
class FreeIpa |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var \Gnumoksha\FreeIpa\Infra\Rpc\Client */ |
|
37
|
|
|
private $client; |
|
38
|
|
|
/** @var \Gnumoksha\FreeIpa\Infra\Rpc\Request\Body */ |
|
39
|
|
|
private $requestBody; |
|
40
|
|
|
/** @var \Gnumoksha\FreeIpa\Model\User\UserRepository|null */ |
|
41
|
|
|
private $userRepository; |
|
42
|
|
|
|
|
43
|
|
|
public function __construct( |
|
44
|
|
|
Options $options, |
|
45
|
|
|
ClientBuilder $clientBuilder = null, |
|
46
|
|
|
RequestBodyInterface $requestBody = null |
|
47
|
|
|
) { |
|
48
|
|
|
$clientBuilder = $clientBuilder ?? new PluginClientBuilder($options); |
|
49
|
|
|
|
|
50
|
|
|
$this->client = $clientBuilder->build(); |
|
51
|
|
|
$this->requestBody = $requestBody ?? new CommonRequestBody(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
|
56
|
|
|
*/ |
|
57
|
|
|
public function login(string $username, string $password): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->client->login($username, $password); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getUserRepository(): UserRepository |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->userRepository === null) { |
|
65
|
|
|
$this->userRepository = new UserRepository($this->client, $this->requestBody); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->userRepository; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Sends a raw request. |
|
73
|
|
|
* |
|
74
|
|
|
* @throws \Gnumoksha\FreeIpa\Infra\Json\JsonException |
|
75
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
public function sendRequest(RequestBodyInterface $body): ResponseBodyInterface |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->client->sendRequest($body); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|