This repository was archived by the owner on Nov 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathUpdateTenant.php
More file actions
99 lines (84 loc) · 2.85 KB
/
UpdateTenant.php
File metadata and controls
99 lines (84 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Slides\Saml2\Commands;
use Slides\Saml2\Helpers\ConsoleHelper;
use Slides\Saml2\Repositories\TenantRepository;
/**
* Class UpdateTenant
*
* @package Slides\Saml2\Commands
*/
class UpdateTenant extends \Illuminate\Console\Command
{
use RendersTenants, ValidatesInput;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'saml2:update-tenant {id}
{ --k|key= : A tenant custom key }
{ --entityId= : IdP Issuer URL }
{ --loginUrl= : IdP Sign on URL }
{ --logoutUrl= : IdP Logout URL }
{ --relayStateUrl= : Redirection URL after successful login }
{ --nameIdFormat= : Name ID Format ("persistent" by default) }
{ --x509cert= : x509 certificate (base64) }
{ --metadata= : A custom metadata (JSON format) }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update a Tenant entity (relying identity provider)';
/**
* @var TenantRepository
*/
protected $tenants;
/**
* DeleteTenant constructor.
*
* @param TenantRepository $tenants
*/
public function __construct(TenantRepository $tenants)
{
$this->tenants = $tenants;
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if(!$tenant = $this->tenants->findById($this->argument('id'))) {
$this->error('Cannot find a tenant #' . $this->argument('id'));
return;
}
$metadata = null;
if ($this->option('metadata')) {
$metadata = $this->option('metadata') ? \json_decode($this->option('metadata')) : null;
if (($json_error = \json_last_error_msg()) !== 'No error') {
$this->error($json_error);
return;
}
}
$tenant->update(array_filter([
'key' => $this->option('key'),
'idp_entity_id' => $this->option('entityId'),
'idp_login_url' => $this->option('loginUrl'),
'idp_logout_url' => $this->option('logoutUrl'),
'idp_x509_cert' => $this->option('x509cert'),
'relay_state_url' => $this->option('relayStateUrl'),
'name_id_format' => $this->resolveNameIdFormat(),
'metadata' => $metadata,
]));
if(!$tenant->save()) {
$this->error('Tenant cannot be saved.');
return;
}
$this->info("The tenant #{$tenant->id} ({$tenant->uuid}) was successfully updated.");
$this->renderTenantCredentials($tenant);
$this->output->newLine();
}
}