|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2022 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
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace Surfnet\Migrations; |
|
22
|
|
|
|
|
23
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
24
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
25
|
|
|
use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; |
|
26
|
|
|
use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Adds the Self asserted tokens feature to the middleware and gateway databases |
|
30
|
|
|
*/ |
|
|
|
|
|
|
31
|
|
|
final class Version20220519134637 extends AbstractMigration implements ConfigurationAwareMigrationInterface |
|
32
|
|
|
{ |
|
33
|
|
|
use ConfigurationAwareMigrationTrait; |
|
34
|
|
|
|
|
35
|
|
|
public function up(Schema $schema): void |
|
36
|
|
|
{ |
|
37
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
38
|
|
|
$this->abortIf( |
|
39
|
|
|
$this->connection->getDatabasePlatform()->getName() !== 'mysql', |
|
|
|
|
|
|
40
|
|
|
'Migration can only be executed safely on \'mysql\'.', |
|
41
|
|
|
); |
|
42
|
|
|
$this->addSql( |
|
43
|
|
|
'ALTER TABLE institution_configuration_options ADD self_asserted_tokens_option INT DEFAULT \'0\' NOT NULL', |
|
44
|
|
|
); |
|
45
|
|
|
$this->addSql( |
|
46
|
|
|
'CREATE TABLE recovery_token (id VARCHAR(36) NOT NULL, identity_id VARCHAR(36) NOT NULL, type VARCHAR(16) NOT NULL, recovery_method_identifier VARCHAR(255) NOT NULL, INDEX idx_recovery_method_type (type), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', |
|
47
|
|
|
); |
|
48
|
|
|
$this->addSql( |
|
49
|
|
|
'CREATE TABLE identity_self_asserted_token_options (identity_id VARCHAR(36) NOT NULL, possessed_token TINYINT(1) NOT NULL, possessed_self_asserted_token TINYINT(1) NOT NULL, PRIMARY KEY(identity_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', |
|
50
|
|
|
); |
|
51
|
|
|
// The unknown vetting type is set on the vetted_second_factor::vetting_type column for the existing second |
|
52
|
|
|
// factors. This to inform consumers of the projection, that the vetting type was recorded at a time before we |
|
53
|
|
|
// tracked the vetting type of the vetted second factors. It is safe to assume the vetting type is either |
|
54
|
|
|
// on-premise or self-vetted (both vetting types where the identity of the user was verified at the service desk |
|
55
|
|
|
// at some point). |
|
56
|
|
|
$this->addSql('ALTER TABLE vetted_second_factor ADD vetting_type VARCHAR(255) DEFAULT \'unknown\''); |
|
57
|
|
|
$this->addSql( |
|
58
|
|
|
'ALTER TABLE recovery_token ADD institution VARCHAR(255) NOT NULL, ADD name VARCHAR(255) NOT NULL, ADD email VARCHAR(255) NOT NULL, ADD status INT NOT NULL', |
|
59
|
|
|
); |
|
60
|
|
|
$this->addSql( |
|
61
|
|
|
'ALTER TABLE audit_log ADD recovery_token_identifier VARCHAR(255) DEFAULT NULL, ADD recovery_token_type VARCHAR(36) DEFAULT NULL', |
|
62
|
|
|
); |
|
63
|
|
|
$this->addSql( |
|
64
|
|
|
'CREATE TABLE vetting_type_hint (institution VARCHAR(36) NOT NULL, hints LONGTEXT NOT NULL, PRIMARY KEY(institution)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
|
68
|
|
|
$this->addSql( |
|
69
|
|
|
sprintf( |
|
70
|
|
|
'ALTER TABLE %s.second_factor ADD identity_vetted TINYINT(1) DEFAULT \'1\'', |
|
71
|
|
|
$gatewaySchema, |
|
72
|
|
|
), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function down(Schema $schema): void |
|
77
|
|
|
{ |
|
78
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
79
|
|
|
$this->abortIf( |
|
80
|
|
|
$this->connection->getDatabasePlatform()->getName() !== 'mysql', |
|
|
|
|
|
|
81
|
|
|
'Migration can only be executed safely on \'mysql\'.', |
|
82
|
|
|
); |
|
83
|
|
|
$this->addSql('ALTER TABLE institution_configuration_options DROP self_asserted_tokens_option'); |
|
84
|
|
|
$this->addSql('DROP TABLE recovery_token'); |
|
85
|
|
|
$this->addSql('DROP TABLE identity_self_asserted_token_options'); |
|
86
|
|
|
$this->addSql('ALTER TABLE vetted_second_factor DROP vetting_type'); |
|
87
|
|
|
$this->addSql('ALTER TABLE audit_log DROP recovery_token_identifier, DROP recovery_token_type'); |
|
88
|
|
|
$this->addSql('DROP TABLE vetting_type_hint'); |
|
89
|
|
|
|
|
90
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
|
91
|
|
|
$this->addSql(sprintf('ALTER TABLE %s.second_factor DROP identity_vetted', $gatewaySchema)); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|