-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathBaseSolutionBootstrapper.php
More file actions
135 lines (119 loc) · 5.85 KB
/
BaseSolutionBootstrapper.php
File metadata and controls
135 lines (119 loc) · 5.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 3.11.0
*/
namespace App;
use App\Utility\Application\FeaturePluginAwareTrait;
use Cake\Core\Configure;
use Cake\Core\PluginApplicationInterface;
use Passbolt\WebInstaller\Middleware\WebInstallerMiddleware;
/**
* A solution bootstrapper to:
* - Load plugins required by a given solution
* - Load/overwrite configs of a given solution
*/
class BaseSolutionBootstrapper
{
use FeaturePluginAwareTrait;
/**
* Loads all the plugins relative to the solution
*
* @param \App\Application $app Application
* @return void
*/
public function addFeaturePlugins(Application $app): void
{
if (Configure::read('debug') && Configure::read('passbolt.selenium.active')) {
$app->addPlugin('Passbolt/TestData', ['bootstrap' => true, 'routes' => false]);
$app->addPlugin('PassboltSeleniumApi', ['bootstrap' => true, 'routes' => true]);
}
$this->addFeaturePluginIfEnabled($app, 'JwtAuthentication');
// Add webinstaller plugin if not configured.
if (!WebInstallerMiddleware::isConfigured()) {
$app->addPlugin('Passbolt/WebInstaller', ['bootstrap' => true, 'routes' => true]);
return;
}
// Add Common plugins.
Configure::write('passbolt.plugins.metadata.enabled', Configure::read('passbolt.v5.enabled'));
$this->addFeaturePluginIfEnabled($app, 'Metadata');
$this->addFeaturePluginIfEnabled($app, 'Rbacs');
$app->addPlugin('Passbolt/AccountSettings', ['bootstrap' => true, 'routes' => true]);
$app->addPlugin('Passbolt/Import', ['bootstrap' => true, 'routes' => true]);
$app->addPlugin('Passbolt/InFormIntegration', ['bootstrap' => true, 'routes' => false]);
$app->addPlugin('Passbolt/Locale', ['bootstrap' => true, 'routes' => true]);
$app->addPlugin('Passbolt/Export', ['bootstrap' => true, 'routes' => false]);
$this->addFeaturePluginIfEnabled($app, 'PasswordExpiry');
$this->addFeaturePluginIfEnabled($app, 'ResourceTypes');
$this->addFeaturePluginIfEnabled($app, 'TotpResourceTypes', ['bootstrap' => true, 'routes' => false]);
$app->addPlugin('Passbolt/RememberMe', ['bootstrap' => true, 'routes' => false]);
$app->addPlugin('Passbolt/EmailNotificationSettings', ['bootstrap' => true, 'routes' => true]);
$this->addFeaturePluginIfEnabled($app, 'EmailDigest');
$app->addPlugin('Passbolt/Reports', ['bootstrap' => true, 'routes' => true]);
$this->addFeaturePluginIfEnabled($app, 'Mobile');
$this->addFeaturePluginIfEnabled($app, 'SelfRegistration');
$app->addPlugin('Passbolt/PasswordGenerator', ['routes' => true]);
$this->addFeaturePluginIfEnabled($app, 'SmtpSettings');
$this->addFeaturePluginIfEnabled(
$app,
'MultiFactorAuthentication',
['bootstrap' => true, 'routes' => true],
true
);
$logEnabled = Configure::read('passbolt.plugins.log.enabled');
if (!isset($logEnabled) || $logEnabled) {
$app->addPlugin('Passbolt/Log', ['bootstrap' => true, 'routes' => false]);
}
$folderEnabled = Configure::read('passbolt.plugins.folders.enabled');
if (!isset($folderEnabled) || $folderEnabled) {
$app->addPlugin('Passbolt/Folders', ['bootstrap' => true, 'routes' => true]);
}
$this->addFeaturePluginIfEnabled($app, 'PasswordPolicies');
$this->addFeaturePluginIfEnabled($app, 'UserKeyPolicies');
$this->addFeaturePluginIfEnabled($app, 'ExportPolicies');
$this->addFeaturePluginIfEnabled($app, 'SecretRevisions');
}
/**
* Adds a plugin to the application according to the feature flag configuration.
*
* In order to enable a plugin, you may set is as enabled in the config/default.php file
* under the passbolt.plugins config namespace key.
*
* The name of the plugin is without the "Passbolt/" prefix, either upper- or lower-case first.
* By default, a feature (aka plugin) is disabled. You may force the enabling as parameter by passing a boolean
* or a callable returning a boolean.
*
* @param \Cake\Core\PluginApplicationInterface $app Application
* @param string $name Name of the plugin (without the "Passbolt/" prefix)
* @param array $config Plugin loading config, will be merged with ['bootstrap' => true, 'routes' => true]
* @param callable|bool $isEnabledByDefault Boolean or callback indicating if the plugin should be loaded by default, if not priorly enabled in configurations. False by default.
* @return self
* @throws \TypeError if the callable $isEnabledByDefault does not return a boolean.
*/
final public function addFeaturePluginIfEnabled(
PluginApplicationInterface $app,
string $name,
array $config = [],
bool|callable $isEnabledByDefault = false
): self {
$config = array_merge(['bootstrap' => true, 'routes' => true], $config);
if (is_callable($isEnabledByDefault)) {
$isEnabledByDefault = $isEnabledByDefault();
}
if ($this->isFeaturePluginEnabled($name, $isEnabledByDefault)) {
$fullPluginName = 'Passbolt/' . ucfirst($name);
$app->addPlugin($fullPluginName, $config);
}
return $this;
}
}