Skip to content

Commit 7054689

Browse files
[#480] Add warnings to form and status page if using basic auth. (#513)
* [#480] Add warnings to form and status page if using basic auth. * [#480] Updated tests.
1 parent c4140b4 commit 7054689

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

apigee_edge.install

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
use Drupal\apigee_edge\OauthTokenFileStorage;
27+
use Drupal\apigee_edge\Plugin\EdgeKeyTypeInterface;
2728
use Drupal\Core\Installer\InstallerKernel;
2829
use Drupal\Core\Url;
2930
use Drupal\user\RoleInterface;
@@ -68,17 +69,36 @@ function apigee_edge_requirements($phase) {
6869
'severity' => REQUIREMENT_WARNING,
6970
];
7071
}
71-
// Warning message in status report if insecure Configuration Key provider is being used.
72+
7273
$auth_config = \Drupal::config('apigee_edge.auth');
73-
if ($key = $auth_config->get('active_key')) {
74-
$key_repository = \Drupal::service('key.repository')->getKey($key);
75-
if ($key_repository && $key_repository->getKeyProvider()->getPluginId() === "config") {
74+
if ($key_id = $auth_config->get('active_key')) {
75+
76+
// Warning message if insecure Configuration Key provider is being used.
77+
$key = \Drupal::service('key.repository')->getKey($key_id);
78+
if ($key && $key->getKeyProvider()->getPluginId() === "config") {
7679
$requirements['apigee_edge_insecure_config_key_provider'] = [
7780
'title' => t('Apigee Edge'),
7881
'description' => t('Edge connection settings are stored in Drupal’s configuration system, which is not designed to store sensitive information. When installing Kickstart for uses other than local development, we highly recommend changing the Apigee Edge connection key provider to a more secure storage location. <a href="https://www.drupal.org/docs/8/modules/apigee-developer-portal-kickstart/apigee-kickstart-faqs#s-during-installation-a-warning-is-displayed-that-the-apigee-edge-connection-key-provider-is-not-considered-secure-what-should-i-do" target="_blank">Learn more.</a>'),
7982
'severity' => REQUIREMENT_WARNING,
8083
];
8184
}
85+
86+
// Warning message in status report if using basic auth.
87+
try {
88+
if ($key && $key->getKeyType() instanceof EdgeKeyTypeInterface &&
89+
$key->getKeyType()->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC) {
90+
$requirements['apigee_edge_http_basic_auth'] = [
91+
'title' => t('Apigee Edge'),
92+
'description' => t('Apigee Edge HTTP basic authentication will be deprecated. Please choose another authentication method. Visit the <a href=":url">Apigee Edge general settings</a> page to get more information.', [
93+
':url' => Url::fromRoute('apigee_edge.settings', ['destination' => 'admin/reports/status'])->toString(),
94+
]),
95+
'severity' => REQUIREMENT_WARNING,
96+
];
97+
}
98+
}
99+
catch (Exception $e) {
100+
// Do nothing.
101+
}
82102
}
83103
}
84104

src/Plugin/KeyInput/ApigeeAuthKeyInput.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class ApigeeAuthKeyInput extends KeyInputBase {
4545
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
4646
$values = $this->getFormDefaultValues($form_state);
4747

48+
if (!empty($values['auth_type']) && $values['auth_type'] == EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC) {
49+
$this->messenger()->addWarning($this->t('HTTP basic authentication will be deprecated. Please choose another authentication method.'));
50+
}
51+
4852
$state_for_public = [
4953
':input[name="key_input_settings[instance_type]"]' => ['value' => EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC],
5054
];
@@ -76,9 +80,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
7680
'#required' => TRUE,
7781
'#options' => [
7882
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH => $this->t('OAuth'),
79-
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC => $this->t('HTTP basic'),
83+
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC => $this->t('HTTP basic (deprecated)'),
8084
],
81-
'#default_value' => $values['auth_type'] ?? EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC,
85+
'#default_value' => $values['auth_type'] ?? EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH,
8286
'#states' => [
8387
'visible' => [$state_for_public, $state_for_private],
8488
'required' => [$state_for_public, $state_for_private],

tests/src/FunctionalJavascript/Form/AuthenticationFormJsTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,15 @@ protected function validateForm(callable $visitFormAsAdmin): void {
286286
$visitFormAsAdmin();
287287

288288
// Make sure the default fields are visible and empty.
289-
$web_assert->fieldValueEquals('Authentication type', 'basic');
289+
$web_assert->fieldValueEquals('Authentication type', 'oauth');
290290
$web_assert->fieldValueEquals('Username', '');
291291
$web_assert->fieldValueEquals('Password', '');
292292
$web_assert->fieldValueEquals('Organization', '');
293293
$web_assert->fieldValueEquals('Apigee Edge endpoint', '');
294294

295+
// Select basic auth.
296+
$page->selectFieldOption('key_input_settings[auth_type]', EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC);
297+
295298
// Make sure the oauth fields are hidden.
296299
$this->assertFalse($this->cssSelect('input[name="key_input_settings[authorization_server]"]')[0]->isVisible());
297300
$this->assertFalse($this->cssSelect('input[name="key_input_settings[client_id]"]')[0]->isVisible());
@@ -348,6 +351,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
348351
$page->fillField('Username', $this->username);
349352
$page->fillField('Password', $this->password);
350353
$page->fillField('Organization', $this->organization);
354+
$page->selectFieldOption('key_input_settings[auth_type]', EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC);
351355

352356
// Test invalid password.
353357
$random_pass = $this->randomString();

0 commit comments

Comments
 (0)