Skip to content

Commit 8f6585a

Browse files
authored
Merge pull request #7654 from magento-performance/CABPI-398-no-test
CABPI-425: SignIn with AdobeID Button is missing on Login Page
2 parents 2ae2987 + 47ea041 commit 8f6585a

File tree

7 files changed

+92
-46
lines changed

7 files changed

+92
-46
lines changed

app/code/Magento/AdminAdobeIms/Console/Command/AdminAdobeImsEnableCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AdminAdobeImsEnableCommand extends Command
4646
/**
4747
* Name of "two-factor-auth" input option
4848
*/
49-
private const TWO_FACTOR_AUTH_ARGUMENT = '2fa-auth';
49+
private const TWO_FACTOR_AUTH_ARGUMENT = '2fa';
5050

5151
/**
5252
* @var ImsConfig
@@ -119,7 +119,8 @@ public function __construct(
119119
self::TWO_FACTOR_AUTH_ARGUMENT,
120120
't',
121121
InputOption::VALUE_OPTIONAL,
122-
'Check if 2FA Auth is enabled on Adobe IMS Side. Enables or disables the Magento 2FA'
122+
'Check if 2FA is enabled for Organization in Adobe Admin Console. ' .
123+
'Required when enabling the module'
123124
)
124125
]);
125126
}
@@ -169,7 +170,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
169170
}
170171

171172
throw new LocalizedException(
172-
__('The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
173+
__('The Client ID, Client Secret, Organization ID and 2FA are required ' .
173174
'when enabling the Admin Adobe IMS Module')
174175
);
175176
} catch (\Exception $e) {

app/code/Magento/AdminAdobeIms/README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Magento_Admin_Adobe_Ims module
2-
32
The Magento_Admin_Adobe_Ims module contains integration with Adobe IMS for backend authentication.
43

54
For information about module installation in Magento 2, see [Enable or disable modules](https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli-subcommands-enable.html).
65

76
# CLI command usage:
87
## bin/magento admin:adobe-ims:enable
98
Enables the AdminAdobeIMS Module. \
10-
Required values are `Organization ID`, `Client ID` and `Client Secret`
9+
Required values are `Organization ID`, `Client ID`, `Client Secret` and `2FA enabled`
1110

1211
### Argument Validation
1312
On enabling the AdminAdobeIMS Module, the input arguments will be validated. \
@@ -19,6 +18,7 @@ The pattern for the validation are configured in the di.xml
1918
<argument name="organizationIdRegex" xsi:type="string"><![CDATA[/^([A-Z0-9]{24})(@AdobeOrg)?$/i]]></argument>
2019
<argument name="clientIdRegex" xsi:type="string"><![CDATA[/[^a-z_\-0-9]/i]]></argument>
2120
<argument name="clientSecretRegex" xsi:type="string"><![CDATA[/[^a-z_\-0-9]/i]]></argument>
21+
<argument name="twoFactorAuthRegex" xsi:type="string"><![CDATA[/^y/i]]></argument>
2222
</arguments>
2323
</type>
2424
```
@@ -27,6 +27,7 @@ We check if the arguments are not empty, as they are all required.
2727

2828
For the Organization ID, Client ID and Client Secret, we check if they contain only alphanumeric characters. \
2929
Additionally for the Organization ID, we check if it matches 24 characters and optional has the suffix `@AdobeOrg`. But we only store the ID and ignore the suffix.
30+
Also make sure 2FA is enabled for the Organization in Adobe Admin Console.
3031

3132
## bin/magento admin:adobe-ims:disable
3233
Disables the AdminAdobeIMS Module.
@@ -44,7 +45,6 @@ Client Secret configured
4445
If Admin Adobe Ims module is disabled, cli command will show message "Module is disabled"
4546

4647
# Admin Login design
47-
4848
The admin login design changes when the AdminAdobeIms module is enabled and configured correctly via the CLI command.
4949
We have added the customer layout handle `adobe_ims_login` to deal with all the design changes.
5050
This handle is added via `\Magento\AdminAdobeIms\Plugin\AddAdobeImsLayoutHandlePlugin::afterAddDefaultHandle`.
@@ -59,24 +59,21 @@ We have included the minified css and the used svgs from Spectrum CSS with our m
5959
To rebuild the minified css run the command `./node_modules/.bin/postcss -o dist/index.min.css index.css` after npm install from inside the web directory.
6060

6161
# AdminAdobeIMS Callback
62-
6362
For the AdobeIMS Login we provide a redirect_uri on the request. After a successful Login in AdobeIMS, we get redirected to provided redirect_uri.
6463

6564
In the ImsCallback Controller we get the access_token and then the user profile.
66-
We then check if the assigned organization is valid and if the user does exist in the magento database, before we complete the user login in Magento.
65+
We then check if the assigned organization is valid and if the user does exist in the Magento database, before we complete the user login in Magento.
6766

6867
If there went something wrong during the authorization, the user gets redirected to the admin login page and an error message is shown.
6968

7069
# Organization ID Validation
71-
7270
During the authorization we check if the configured `Organization ID` provided on the enabling CLI command is assigned to the user.
7371

7472
In the profile response from Adobe IMS must be a `roles` array. There we have all assigned organizations to the user.
7573

7674
We compare if the configured organization ID does exist in this array and also the structure of the organization ID is valid.
7775

7876
# Admin Backend Login
79-
8077
Login with the help Adobe IMS Service is implemented. The redirect to Adobe IMS Service is performed-
8178
The redirect from Adobe IMS is done to \Magento\AdminAdobeIms\Controller\Adminhtml\OAuth\ImsCallback controller.
8279

@@ -97,14 +94,12 @@ If token is valid, value token_last_check_time will be updated to current time a
9794
If token is not valid, session will be destroyed.
9895

9996
# Admin Backend Logout
100-
10197
The logout from Adobe IMS Service is performed when Magento Admin User is logged out.
10298
It's triggered by the event `controller_action_predispatch_adminhtml_auth_logout`
10399

104-
We do external LogOut by call to IMS. Session revoke is standard magento behavior
100+
We do external LogOut by call to IMS. Session revoke is standard Magento behavior
105101

106102
# Admin Created Email
107-
108103
We created an Observer for the `admin_user_save_after` event. \
109104
There we check if the customer object is newly created or not. \
110105
When a new admin user got created in Magento, he will then receive an email with further information on how to login.
@@ -117,11 +112,11 @@ The notification mail will be sent inside our `AdminNotificationService` where w
117112
# Error Handling
118113
For the AdminAdobeIms Module we have two specific error messages and one general error message which are shown on the Admin Login page when an error occured.
119114

120-
###AdobeImsTokenAuthorizationException
115+
### AdobeImsTokenAuthorizationException
121116
Will be thrown when there was an error during the authorization. \
122-
e. g. a call to AdobeIMS fails or there was no matching admin found in the magento database.
117+
e. g. a call to AdobeIMS fails or there was no matching admin found in the Magento database.
123118

124-
###AdobeImsOrganizationAuthorizationException
119+
### AdobeImsOrganizationAuthorizationException
125120
Will be thrown when the admin user who wants to log in does not have the configured organization ID assigned to his AdobeIMS Profile.
126121

127122
### Error logging
@@ -133,28 +128,28 @@ Logging can be enabled or disabled in the config on changing the value for `adob
133128
There you can switch the toggle for `Enable Logging for Admin Adobe IMS Module`
134129

135130
# Password usage in Admin UI
136-
When the AdobeAdminIMS Module is enabled, we do not need any password fields in the magento admin backend anymore.
131+
When the AdobeAdminIMS Module is enabled, we do not need any password fields in the Magento admin backend anymore.
137132

138-
So we hide the "Current User Verification" fields and removed the "Password" and "Password Confirmation" fields of the user forms.
139-
This is done by the Plugin `\Magento\AdminAdobeIms\Plugin\RemovePasswordAndUserConfirmationFormFieldsPlugin`.
140-
Here we remove the password and password confirmation field, and hide the current user verification fieldset.
133+
So we removed the "Password" and "Password Confirmation" fields of the user forms.
134+
This is done by the plugin `\Magento\AdminAdobeIms\Plugin\RemovePasswordAndUserConfirmationFormFieldsPlugin`.
135+
Here we remove the password and password confirmation field.
141136
As the verification field is just hidden, we set a random password to bypass the input filters of the Save and Delete user Classes.
142-
The `\Magento\AdminAdobeIms\Plugin\RemoveUserValidationRulesPlugin` Plugin is required to remove the password fields from the form validation.
137+
The `\Magento\AdminAdobeIms\Plugin\RemoveUserValidationRulesPlugin` plugin is required to remove the password fields from the form validation.
138+
We update the "Current User Identity Verification" fieldset to add "Verify Identity with Adobe IMS" button instead "Your Password" field.
139+
This is done by the plugins: `Magento\AdminAdobeIms\Plugin\Block\Adminhtml\User\Edit\Tab\AddReAuthVerification`, `Magento\AdminAdobeIms\Plugin\Block\Adminhtml\System\Account\Edit\AddReAuthVerification`, `Magento\AdminAdobeIms\Plugin\Block\Adminhtml\User\Role\Tab\AddReAuthVerification` and `Magento\AdminAdobeIms\Plugin\Block\Adminhtml\Integration\Edit\Tab\AddReAuthVerification`.
143140

144-
As we don't show the current user verification field anymore, we have the `\Magento\AdminAdobeIms\Plugin\ReplaceVerifyIdentityWithImsPlugin` Plugin to verify the `access_token` of the current admin user in AdobeIMS and only proceed when it is still valid.
141+
As we update the current user verification field, we have the `\Magento\AdminAdobeIms\Plugin\ReplaceVerifyIdentityWithImsPlugin` plugin to verify the `AdobeReAuthToken` of the current admin user in AdobeIMS and only proceed when it is valid.
145142

146143
For the newly created user will be a random password generated, as we did not modify the admin_user table, where the password field can not be null.
147144
This is done in the `\Magento\AdminAdobeIms\Plugin\UserSavePlugin`.
148145

149-
We also disabled the "Change password in 30 days" functionally, as we don't need the magento admin user password for the login.
146+
We also disabled the "Change password in 30 days" functionally, as we don't need the Magento admin user password for the login.
150147
This can be found in the `\Magento\AdminAdobeIms\Plugin\DisableForcedPasswordChangePlugin` and `\Magento\AdminAdobeIms\Plugin\DisablePasswordResetPlugin` Plugins.
151148

152149
When the AdminAdobeIMS Module is disabled, the user can not be log in when using an empty password.
153150
Instead, the forgot password function must be used to reset the password.
154151

155-
156152
# WEB API authentication using IMS ACCESS_TOKEN
157-
158153
When Admin Adobe IMS is enabled, Adobe Commerce admin users will stop having credentials (username and password).
159154
These admin user credentials are needed for getting token that can be used to make requests to admin web APIs.
160155
It means that will be not possible to create token because admin doesn't have credentials. In these case we have to use IMS access token.
@@ -177,7 +172,7 @@ Magento has setting: Stores > Settings > Configuration > Services > OAuth > Acce
177172
Both of values are checked in function isTokenExpired \Magento\AdminAdobeIms\Model\TokenReader.
178173
it means that with default values is not possible to use tokens that older than 4h.
179174

180-
###IMS access token verification.
175+
### IMS access token verification.
181176
To verify token a public key is required. For more info https://wiki.corp.adobe.com/display/ims/IMS+public+key+retrieval
182177
In Admin Adobe Ims module was defined path where certificate has to be downloaded from.
183178
By default, in config.xml, these value for production.
@@ -201,9 +196,8 @@ Examples, how developers can test functionality:
201196
curl -X GET "{domain}/rest/V1/customers/2" -H "Authorization: Bearer AddAdobeImsAccessToken"
202197
curl -X GET "{domain}/rest/V1/products/24-MB01" -H "Authorization: Bearer AddAdobeImsAccessToken"
203198

204-
###Two-factor authentication.
205-
206-
During CLI enablement of the module, the admin user is asked, whether 2FA is enabled for him on Adobe side.
199+
### Two-factor authentication.
200+
During CLI enablement of the module, the admin user is asked, whether 2FA is enabled for Organization in Adobe Admin Console.
207201
If the answer is yes, Magento TFA module (if it's present in the code base), should be disable.
208202

209203
For this purpose the additional config value was added, this config value is read by Magento_TwoFactorAuth module.
@@ -222,4 +216,4 @@ When the form will be submitted, we verify the identity with the `Magento/AdminA
222216
Here the existens of the `AdobeAccessToken` and `AdobeReAuthToken` will be checked.
223217
The reauth_token will be used to call the AdobeIms validateToken Endpoint.
224218

225-
When this call is successfull, the form will be submitted, otherwise we update the Message of the thrown `AuthenticationException` to return a matching error message, done by the `Magento/AdminAdobeIms/Plugin/PerformIdentityCheckMessagePlugin.php` Plugin.
219+
When this call is successful, the form will be submitted, otherwise we update the Message of the thrown `AuthenticationException` to return a matching error message, done by the `Magento/AdminAdobeIms/Plugin/PerformIdentityCheckMessagePlugin.php` Plugin.

app/code/Magento/AdminAdobeIms/Service/ImsCommandOptionService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class ImsCommandOptionService
2222
private const OPTION_QUESTION = 'Please enter your %s:';
2323

2424
/**
25-
* Prompt for 2FA Auth CLI Command option
25+
* Prompt for 2FA CLI Command option
2626
*/
27-
private const TWO_FACTOR_OPTION_QUESTION = 'Is 2FA enabled on AdobeIMS? (yes/no):';
27+
private const TWO_FACTOR_OPTION_QUESTION = 'Is 2FA enabled for Organization in Adobe Admin Console? (yes/no):';
2828

2929
/**
3030
* Human-readable name for Organization ID input option

app/code/Magento/AdminAdobeIms/Service/ImsConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function enableModule(
121121
): void {
122122
if (!$isAdobeIms2FAEnabled) {
123123
throw new LocalizedException(
124-
__('2FA Auth is required when enabling the Admin Adobe IMS Module')
124+
__('2FA is required when enabling the Admin Adobe IMS Module')
125125
);
126126
}
127127

app/code/Magento/AdminAdobeIms/Test/Mftf/Data/ClientCredentialsData.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
1111
<entity name="ClientCredentialsData">
12-
<data key="org_id">{{_CREDS.magento/admin_adobe_ims/org_id}}</data>
13-
<data key="client_id">{{_CREDS.magento/admin_adobe_ims/client_id}}</data>
14-
<data key="client_key">{{_CREDS.magento/admin_adobe_ims/client_key}}</data>
12+
<data key="org_id">{{_CREDS.magento/admin_adobe_ims_org_id}}</data>
13+
<data key="client_id">{{_CREDS.magento/admin_adobe_ims_client_id}}</data>
14+
<data key="client_key">{{_CREDS.magento/admin_adobe_ims_client_key}}</data>
1515
</entity>
1616
</entities>

app/code/Magento/AdminAdobeIms/Test/Unit/Command/AdminAdobeImsEnableCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,23 @@ public function cliCommandProvider(): array
171171
false,
172172
$this->never(),
173173
$this->never(),
174-
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
174+
'<error>The Client ID, Client Secret, Organization ID and 2FA are required ' .
175175
'when enabling the Admin Adobe IMS Module</error>',
176176
true
177177
],
178178
[
179179
true,
180180
$this->never(),
181181
$this->never(),
182-
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
182+
'<error>The Client ID, Client Secret, Organization ID and 2FA are required ' .
183183
'when enabling the Admin Adobe IMS Module</error>',
184184
false
185185
],
186186
[
187187
false,
188188
$this->never(),
189189
$this->never(),
190-
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
190+
'<error>The Client ID, Client Secret, Organization ID and 2FA are required ' .
191191
'when enabling the Admin Adobe IMS Module</error>',
192192
false
193193
]

app/code/Magento/AdminAdobeIms/ViewModel/LinkViewModel.php

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,56 @@
99

1010
use Magento\AdminAdobeIms\Model\ImsConnection;
1111
use Magento\Framework\Exception\InvalidArgumentException;
12+
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
1213
use Magento\Framework\View\Element\Block\ArgumentInterface;
14+
use Psr\Log\LoggerInterface;
1315

1416
class LinkViewModel implements ArgumentInterface
1517
{
16-
/** @var string */
17-
private string $authUrl;
18+
/**
19+
* @var string|null
20+
*/
21+
private ?string $authUrl;
22+
23+
/**
24+
* @var LoggerInterface
25+
*/
26+
private LoggerInterface $logger;
27+
28+
/**
29+
* @var MessageManagerInterface
30+
*/
31+
private MessageManagerInterface $messageManager;
1832

1933
/**
2034
* @param ImsConnection $connection
35+
* @param LoggerInterface $logger
36+
* @param MessageManagerInterface $messageManager
2137
*/
2238
public function __construct(
23-
ImsConnection $connection
39+
ImsConnection $connection,
40+
LoggerInterface $logger,
41+
MessageManagerInterface $messageManager
2442
) {
43+
$this->logger = $logger;
44+
$this->messageManager = $messageManager;
45+
2546
try {
2647
$this->authUrl = $connection->auth();
27-
} catch (InvalidArgumentException $exception) {
28-
$this->authUrl = '';
48+
} catch (InvalidArgumentException $e) {
49+
$this->logger->error($e->getMessage());
50+
$this->authUrl = null;
51+
$this->addImsErrorMessage(
52+
'Could not connect to Adobe IMS.',
53+
$e->getMessage()
54+
);
55+
} catch (\Exception $e) {
56+
$this->logger->error($e->getMessage());
57+
$this->authUrl = null;
58+
$this->addImsErrorMessage(
59+
'Could not connect to Adobe IMS.',
60+
'Something went wrong during Adobe IMS connection check.'
61+
);
2962
}
3063
}
3164

@@ -42,10 +75,28 @@ public function isActive(): bool
4275
/**
4376
* Get authorization URL for Login Button
4477
*
45-
* @return string
78+
* @return string|null
4679
*/
47-
public function getButtonLink(): string
80+
public function getButtonLink(): ?string
4881
{
4982
return $this->authUrl;
5083
}
84+
85+
/**
86+
* Add Admin Adobe IMS Error Message
87+
*
88+
* @param string $headline
89+
* @param string $message
90+
* @return void
91+
*/
92+
private function addImsErrorMessage(string $headline, string $message): void
93+
{
94+
$this->messageManager->addComplexErrorMessage(
95+
'adminAdobeImsMessage',
96+
[
97+
'headline' => __($headline)->getText(),
98+
'message' => __($message)->getText()
99+
]
100+
);
101+
}
51102
}

0 commit comments

Comments
 (0)