1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Commands; |
4
|
|
|
|
5
|
|
|
use Slides\Saml2\Models\Tenant; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class CreateTenant |
10
|
|
|
* |
11
|
|
|
* @package Slides\Saml2\Commands |
12
|
|
|
*/ |
13
|
|
|
trait RendersTenants |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Render tenants in a table. |
17
|
|
|
* |
18
|
|
|
* @param \Slides\Saml2\Models\Tenant|\Illuminate\Support\Collection $tenants |
19
|
|
|
* @param string|null $title |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
protected function renderTenants($tenants, ?string $title = null) |
24
|
|
|
{ |
25
|
|
|
/** @var \Slides\Saml2\Models\Tenant[]|\Illuminate\Database\Eloquent\Collection $tenants */ |
26
|
|
|
$tenants = $tenants instanceof Tenant |
27
|
|
|
? collect([$tenants]) |
28
|
|
|
: $tenants; |
29
|
|
|
|
30
|
|
|
$headers = ['Column', 'Value']; |
31
|
|
|
$columns = []; |
32
|
|
|
|
33
|
|
|
foreach ($tenants as $tenant) { |
34
|
|
|
foreach ($this->getTenantColumns($tenant) as $column => $value) { |
35
|
|
|
$columns[] = [$column, $value ?: '(empty)']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if($tenants->last()->id !== $tenant->id) { |
39
|
|
|
$columns[] = new \Symfony\Component\Console\Helper\TableSeparator(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if($title) { |
44
|
|
|
$this->getOutput()->title($title); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$this->table($headers, $columns); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get a columns of the Tenant. |
52
|
|
|
* |
53
|
|
|
* @param \Slides\Saml2\Models\Tenant $tenant |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function getTenantColumns(Tenant $tenant) |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'ID' => $tenant->id, |
61
|
|
|
'UUID' => $tenant->uuid, |
62
|
|
|
'Key' => $tenant->key, |
63
|
|
|
'Entity ID' => $tenant->idp_entity_id, |
64
|
|
|
'Login URL' => $tenant->idp_login_url, |
65
|
|
|
'Logout URL' => $tenant->idp_logout_url, |
66
|
|
|
'Relay State URL' => $tenant->relay_state_url, |
67
|
|
|
'Name ID format' => $tenant->name_id_format, |
68
|
|
|
'x509 cert' => Str::limit($tenant->idp_x509_cert, 50), |
69
|
|
|
'Metadata' => $this->renderArray($tenant->metadata ?: []), |
70
|
|
|
'Created' => $tenant->created_at->toDateTimeString(), |
71
|
|
|
'Updated' => $tenant->updated_at->toDateTimeString(), |
72
|
|
|
'Deleted' => $tenant->deleted_at ? $tenant->deleted_at->toDateTimeString() : null |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Render a tenant credentials. |
78
|
|
|
* |
79
|
|
|
* @param \Slides\Saml2\Models\Tenant $tenant |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
protected function renderTenantCredentials(Tenant $tenant) |
84
|
|
|
{ |
85
|
|
|
$this->output->section('Credentials for the tenant'); |
86
|
|
|
|
87
|
|
|
$this->getOutput()->text([ |
88
|
|
|
'Identifier (Entity ID): <comment>' . route('saml.metadata', ['uuid' => $tenant->uuid]) . '</comment>', |
|
|
|
|
89
|
|
|
'Reply URL (Assertion Consumer Service URL): <comment>' . route('saml.acs', ['uuid' => $tenant->uuid]) . '</comment>', |
90
|
|
|
'Sign on URL: <comment>' . route('saml.login', ['uuid' => $tenant->uuid]) . '</comment>', |
91
|
|
|
'Logout URL: <comment>' . route('saml.logout', ['uuid' => $tenant->uuid]) . '</comment>', |
92
|
|
|
'Relay State: <comment>' . ($tenant->relay_state_url ?: config('saml2.loginRoute')) . ' (optional)</comment>' |
|
|
|
|
93
|
|
|
]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Print an array to a string. |
98
|
|
|
* |
99
|
|
|
* @param array $array |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
protected function renderArray(array $array) |
104
|
|
|
{ |
105
|
|
|
$lines = []; |
106
|
|
|
|
107
|
|
|
foreach ($array as $key => $value) { |
108
|
|
|
$lines[] = "$key: $value"; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return implode(PHP_EOL, $lines); |
112
|
|
|
} |
113
|
|
|
} |