1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Commands; |
4
|
|
|
|
5
|
|
|
use Cerbero\CommandValidator\ValidatesInput; |
6
|
|
|
use Illuminate\Validation\Rules\Exists; |
|
|
|
|
7
|
|
|
use Illuminate\Validation\Rules\In; |
|
|
|
|
8
|
|
|
use Illuminate\Validation\Rules\Unique; |
|
|
|
|
9
|
|
|
use Slides\Saml2\Helpers\ConsoleHelper; |
10
|
|
|
use Slides\Saml2\Repositories\IdentityProviderRepository; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class Update extends \Illuminate\Console\Command |
15
|
|
|
{ |
16
|
|
|
use RendersTenants, ValidatesInput; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The name and signature of the console command. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $signature = 'saml2:idp-update {id} |
24
|
|
|
{ --key : Key/name of the Identity Provider } |
25
|
|
|
{ --entityId= : IdP Issuer URL } |
26
|
|
|
{ --loginUrl= : IdP Sign on URL } |
27
|
|
|
{ --logoutUrl= : IdP Logout URL } |
28
|
|
|
{ --relayStateUrl= : Redirection URL after successful login } |
29
|
|
|
{ --nameIdFormat= : Name ID Format ("persistent" by default) } |
30
|
|
|
{ --x509cert= : x509 certificate (base64) } |
31
|
|
|
{ --metadata= : A custom metadata }'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The console command description. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $description = 'Update an existing Identity Provider'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var IdentityProviderRepository |
42
|
|
|
*/ |
43
|
|
|
protected IdentityProviderRepository $repository; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* DeleteTenant constructor. |
47
|
|
|
* |
48
|
|
|
* @param IdentityProviderRepository $repository |
49
|
|
|
*/ |
50
|
|
|
public function __construct(IdentityProviderRepository $repository) |
51
|
|
|
{ |
52
|
|
|
$this->repository = $repository; |
53
|
|
|
|
54
|
|
|
parent::__construct(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Execute the console command. |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function handle() |
63
|
|
|
{ |
64
|
|
|
$tenant = $this->repository->findById($this->argument('id')); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$tenant->update(array_filter([ |
67
|
|
|
'key' => $this->option('key'), |
68
|
|
|
'idp_entity_id' => $this->option('entityId'), |
69
|
|
|
'idp_login_url' => $this->option('loginUrl'), |
70
|
|
|
'idp_logout_url' => $this->option('logoutUrl'), |
71
|
|
|
'idp_x509_cert' => $this->option('x509cert'), |
72
|
|
|
'relay_state_url' => $this->option('relayStateUrl'), |
73
|
|
|
'name_id_format' => $this->option('nameIdFormat'), |
74
|
|
|
'metadata' => ConsoleHelper::stringToArray($this->option('metadata')) |
75
|
|
|
])); |
76
|
|
|
|
77
|
|
|
if (!$tenant->save()) { |
78
|
|
|
$this->error('Identity Provider cannot be saved.'); |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->info("The tenant #$tenant->id ($tenant->uuid) was successfully updated."); |
83
|
|
|
|
84
|
|
|
$this->renderTenantCredentials($tenant); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$this->output->newLine(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param InputInterface $input |
91
|
|
|
* @param OutputInterface $output |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
protected function interact(InputInterface $input, OutputInterface $output) |
96
|
|
|
{ |
97
|
|
|
if (! $input->getOption('entityId')) { |
98
|
|
|
$input->setOption('entityId', $this->ask('Entity ID (fx. https://sts.windows.net/65b9e948-757b-4431-b140-62a2f8a3fdeb/) (optional)')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if (! $input->getOption('loginUrl')) { |
102
|
|
|
$input->setOption('loginUrl', $this->ask('Login URL (fx. https://login.microsoftonline.com/65b9e948-757b-4431-b140-62a2f8a3fdeb/saml2)')); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if (! $input->getOption('logoutUrl')) { |
106
|
|
|
$input->setOption('logoutUrl', $this->ask('Logout URL')); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if (! $input->getOption('nameIdFormat')) { |
110
|
|
|
$input->setOption('nameIdFormat', $this->choice('Name ID Format', $this->nameIdFormatValues(), 'persistent')); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if (! $input->getOption('relayStateUrl')) { |
114
|
|
|
$input->setOption('relayStateUrl', $this->ask('Post-login redirect URL (optional)')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
if (! $input->getOption('key')) { |
118
|
|
|
$input->setOption('key', $this->ask('Key/name of the identity provider (optional)')); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if (! $input->getOption('metadata')) { |
122
|
|
|
$input->setOption('metadata', $this->ask('Custom metadata (in format "field:value,anotherfield:value") (optional)')); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Validation rules for the user input. |
128
|
|
|
* |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
|
|
protected function rules(): array |
132
|
|
|
{ |
133
|
|
|
return [ |
134
|
|
|
'id' => ['required', 'int', new Exists(config('saml2.idpModel'))], |
|
|
|
|
135
|
|
|
'key' => ['string', new Unique(config('saml2.idpModel'), 'key')], |
136
|
|
|
'entityId' => 'string', |
137
|
|
|
'loginUrl' => 'string|url', |
138
|
|
|
'logoutUrl' => 'string|url', |
139
|
|
|
'x509cert' => 'string', |
140
|
|
|
'relayStateUrl' => 'string|url', |
141
|
|
|
'metadata' => 'string', |
142
|
|
|
'nameIdFormat' => ['string', new In($this->nameIdFormatValues())] |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the values for the name ID format rule. |
148
|
|
|
* |
149
|
|
|
* @return string[] |
150
|
|
|
*/ |
151
|
|
|
protected function nameIdFormatValues(): array |
152
|
|
|
{ |
153
|
|
|
return [ |
154
|
|
|
'persistent', |
155
|
|
|
'transient', |
156
|
|
|
'emailAddress', |
157
|
|
|
'unspecified', |
158
|
|
|
'X509SubjectName', |
159
|
|
|
'WindowsDomainQualifiedName', |
160
|
|
|
'kerberos', |
161
|
|
|
'entity' |
162
|
|
|
]; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths