diff --git a/app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsReauthCallback.php b/app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsReauthCallback.php index fca924ce53b45..b504396288d3b 100755 --- a/app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsReauthCallback.php +++ b/app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsReauthCallback.php @@ -123,7 +123,9 @@ public function execute(): ResultInterface if (empty($profile['email'])) { throw new AuthenticationException(__('An authentication error occurred. Verify and try again.')); } - $this->adminOrganizationService->checkOrganizationAllocation($profile); + + $accessToken = $tokenResponse->getAccessToken(); + $this->adminOrganizationService->checkOrganizationAllocation($accessToken); $this->adminReauthProcessService->execute($tokenResponse); $response = sprintf( diff --git a/app/code/Magento/AdminAdobeIms/Plugin/AdobeImsReauth/AddAdobeImsReAuthButton.php b/app/code/Magento/AdminAdobeIms/Plugin/AdobeImsReauth/AddAdobeImsReAuthButton.php index c3fb51334bd72..1d009565c5fff 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/AdobeImsReauth/AddAdobeImsReAuthButton.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/AdobeImsReauth/AddAdobeImsReAuthButton.php @@ -20,6 +20,8 @@ class AddAdobeImsReAuthButton */ public function addAdobeImsReAuthButton(AbstractElement $fieldset): void { + $fieldset->setLegend(__('Identity Verification')); + $fieldset->addField( 'ims_verification', 'button', @@ -30,7 +32,8 @@ public function addAdobeImsReAuthButton(AbstractElement $fieldset): void 'class' => 'ims_verification', 'title' => __('Verify Identity with Adobe IMS'), 'required' => true, - 'value' => __('Sign In with Adobe IMS'), + 'value' => __('Confirm Identity'), + 'note' => __('To apply changes you need to verify your Adobe identity.'), ] ); @@ -39,10 +42,10 @@ public function addAdobeImsReAuthButton(AbstractElement $fieldset): void 'hidden', [ 'name' => 'ims_verified', - 'label' => __('Verify Identity with Adobe IMS'), + 'label' => __('Identity Verified with Adobe IMS'), 'id' => 'ims_verified', 'class' => 'ims_verified', - 'title' => __('Verify Identity with Adobe IMS'), + 'title' => __('Identity Verified with Adobe IMS'), 'required' => true, ] ); diff --git a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/SignInPlugin.php b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/SignInPlugin.php index 18bf9afdea7a7..d02cac303eecb 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/SignInPlugin.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/SignInPlugin.php @@ -155,7 +155,7 @@ private function getUserData(): array return [ 'isAuthorized' => true, - 'name' => $user->getFirstName() . ' ' . $user->getLastName(), + 'name' => $user->getName(), 'email' => $user->getEmail(), 'image' => '' ]; diff --git a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/System/Account/Edit/AddReAuthVerification.php b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/System/Account/Edit/AddReAuthVerification.php index 973a7398f8c4d..0742d9ebf1fb1 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/System/Account/Edit/AddReAuthVerification.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/System/Account/Edit/AddReAuthVerification.php @@ -8,8 +8,8 @@ namespace Magento\AdminAdobeIms\Plugin\Block\Adminhtml\System\Account\Edit; -use Closure; use Magento\AdminAdobeIms\Plugin\AdobeImsReauth\AddAdobeImsReAuthButton; +use Magento\AdminAdobeIms\Service\ImsConfig; use Magento\Backend\Block\System\Account\Edit\Form; class AddReAuthVerification @@ -19,33 +19,40 @@ class AddReAuthVerification */ private AddAdobeImsReAuthButton $adobeImsReAuthButton; + /** + * @var ImsConfig + */ + private ImsConfig $adminAdobeImsConfig; + /** * @param AddAdobeImsReAuthButton $adobeImsReAuthButton + * @param ImsConfig $adminAdobeImsConfig */ public function __construct( - AddAdobeImsReAuthButton $adobeImsReAuthButton + AddAdobeImsReAuthButton $adobeImsReAuthButton, + ImsConfig $adminAdobeImsConfig ) { $this->adobeImsReAuthButton = $adobeImsReAuthButton; + $this->adminAdobeImsConfig = $adminAdobeImsConfig; } /** * Add adobeIms reAuth button to account edit form * * @param Form $subject - * @param Closure $proceed - * @return mixed + * @return void */ - public function aroundGetFormHtml(Form $subject, Closure $proceed) + public function beforeGetFormHtml(Form $subject): void { - $form = $subject->getForm(); - if (is_object($form)) { - $verificationFieldset = $form->getElement('current_user_verification_fieldset'); - if ($verificationFieldset !== null) { - $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); - $subject->setForm($form); + if ($this->adminAdobeImsConfig->enabled()) { + $form = $subject->getForm(); + if (is_object($form)) { + $verificationFieldset = $form->getElement('current_user_verification_fieldset'); + if ($verificationFieldset !== null) { + $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); + $subject->setForm($form); + } } } - - return $proceed(); } } diff --git a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Edit/Tab/AddReAuthVerification.php b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Edit/Tab/AddReAuthVerification.php index f0c84332b6152..9722ced6a8672 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Edit/Tab/AddReAuthVerification.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Edit/Tab/AddReAuthVerification.php @@ -8,8 +8,8 @@ namespace Magento\AdminAdobeIms\Plugin\Block\Adminhtml\User\Edit\Tab; -use Closure; use Magento\AdminAdobeIms\Plugin\AdobeImsReauth\AddAdobeImsReAuthButton; +use Magento\AdminAdobeIms\Service\ImsConfig; use Magento\User\Block\User\Edit\Tab\Main; class AddReAuthVerification @@ -19,33 +19,40 @@ class AddReAuthVerification */ private AddAdobeImsReAuthButton $adobeImsReAuthButton; + /** + * @var ImsConfig + */ + private ImsConfig $adminAdobeImsConfig; + /** * @param AddAdobeImsReAuthButton $adobeImsReAuthButton + * @param ImsConfig $adminAdobeImsConfig */ public function __construct( - AddAdobeImsReAuthButton $adobeImsReAuthButton + AddAdobeImsReAuthButton $adobeImsReAuthButton, + ImsConfig $adminAdobeImsConfig ) { $this->adobeImsReAuthButton = $adobeImsReAuthButton; + $this->adminAdobeImsConfig = $adminAdobeImsConfig; } /** * Add adobeIms reAuth button to user edit and create form * * @param Main $subject - * @param Closure $proceed - * @return mixed + * @return void */ - public function aroundGetFormHtml(Main $subject, Closure $proceed) + public function beforeGetFormHtml(Main $subject): void { - $form = $subject->getForm(); - if (is_object($form)) { - $verificationFieldset = $form->getElement('current_user_verification_fieldset'); - if ($verificationFieldset !== null) { - $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); - $subject->setForm($form); + if ($this->adminAdobeImsConfig->enabled()) { + $form = $subject->getForm(); + if (is_object($form)) { + $verificationFieldset = $form->getElement('current_user_verification_fieldset'); + if ($verificationFieldset !== null) { + $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); + $subject->setForm($form); + } } } - - return $proceed(); } } diff --git a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Role/Tab/AddReAuthVerification.php b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Role/Tab/AddReAuthVerification.php index 8be7c3a9b49b4..a33b938db4379 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Role/Tab/AddReAuthVerification.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/Block/Adminhtml/User/Role/Tab/AddReAuthVerification.php @@ -8,8 +8,8 @@ namespace Magento\AdminAdobeIms\Plugin\Block\Adminhtml\User\Role\Tab; -use Closure; use Magento\AdminAdobeIms\Plugin\AdobeImsReauth\AddAdobeImsReAuthButton; +use Magento\AdminAdobeIms\Service\ImsConfig; use Magento\User\Block\Role\Tab\Info; class AddReAuthVerification @@ -19,33 +19,40 @@ class AddReAuthVerification */ private AddAdobeImsReAuthButton $adobeImsReAuthButton; + /** + * @var ImsConfig + */ + private ImsConfig $adminAdobeImsConfig; + /** * @param AddAdobeImsReAuthButton $adobeImsReAuthButton + * @param ImsConfig $adminAdobeImsConfig */ public function __construct( - AddAdobeImsReAuthButton $adobeImsReAuthButton + AddAdobeImsReAuthButton $adobeImsReAuthButton, + ImsConfig $adminAdobeImsConfig ) { $this->adobeImsReAuthButton = $adobeImsReAuthButton; + $this->adminAdobeImsConfig = $adminAdobeImsConfig; } /** * Add adobeIms reAuth button to role edit and create form * * @param Info $subject - * @param Closure $proceed - * @return mixed + * @return void */ - public function aroundGetFormHtml(Info $subject, Closure $proceed) + public function beforeGetFormHtml(Info $subject): void { - $form = $subject->getForm(); - if (is_object($form)) { - $verificationFieldset = $form->getElement('current_user_verification_fieldset'); - if ($verificationFieldset !== null) { - $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); - $subject->setForm($form); + if ($this->adminAdobeImsConfig->enabled()) { + $form = $subject->getForm(); + if (is_object($form)) { + $verificationFieldset = $form->getElement('current_user_verification_fieldset'); + if ($verificationFieldset !== null) { + $this->adobeImsReAuthButton->addAdobeImsReAuthButton($verificationFieldset); + $subject->setForm($form); + } } } - - return $proceed(); } } diff --git a/app/code/Magento/AdminAdobeIms/Plugin/ReplaceVerifyIdentityWithImsPlugin.php b/app/code/Magento/AdminAdobeIms/Plugin/ReplaceVerifyIdentityWithImsPlugin.php index 17cf726c3b2fb..132676ba3b8fb 100644 --- a/app/code/Magento/AdminAdobeIms/Plugin/ReplaceVerifyIdentityWithImsPlugin.php +++ b/app/code/Magento/AdminAdobeIms/Plugin/ReplaceVerifyIdentityWithImsPlugin.php @@ -67,6 +67,10 @@ public function aroundVerifyIdentity(User $subject, callable $proceed, string $p } $valid = $this->verifyImsToken(); + + $session = $this->auth->getAuthStorage(); + $session->setAdobeReAuthToken(null); + if ($valid) { return true; } diff --git a/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/Block/Adminhtml/SignInPluginTest.php b/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/Block/Adminhtml/SignInPluginTest.php index 52ada038f9c3e..cfbd91534bd26 100644 --- a/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/Block/Adminhtml/SignInPluginTest.php +++ b/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/Block/Adminhtml/SignInPluginTest.php @@ -106,8 +106,7 @@ public function testAroundGetComponentJsonConfig( $userProfile = $this->createMock(User::class); if ($isAuthorized) { - $userProfile->method('getFirstName')->willReturn($userData['firstname']); - $userProfile->method('getLastName')->willReturn($userData['lastname']); + $userProfile->method('getName')->willReturn($userData['name']); $userProfile->method('getEmail')->willReturn($userData['email']); } @@ -170,8 +169,7 @@ public function userDataProvider(): array 'Existing authorized user' => [ [ 'isAuthorized' => true, - 'firstname' => 'John', - 'lastname' => 'Doe', + 'name' => 'John Doe', 'email' => 'john@email.com', ], [], @@ -186,7 +184,7 @@ public function userDataProvider(): array 'Existing non-authorized user' => [ [ 'isAuthorized' => false, - 'name' => 'John', + 'name' => 'John Doe', 'email' => 'john@email.com', 'image' => 'image.png' ], diff --git a/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/ReplaceVerifyIdentityWithImsPluginTest.php b/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/ReplaceVerifyIdentityWithImsPluginTest.php index c98897ae283c5..4c89b5d350f22 100644 --- a/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/ReplaceVerifyIdentityWithImsPluginTest.php +++ b/app/code/Magento/AdminAdobeIms/Test/Unit/Plugin/ReplaceVerifyIdentityWithImsPluginTest.php @@ -55,8 +55,7 @@ protected function setUp(): void $objectManagerHelper = new ObjectManagerHelper($this); $this->storageMock = $this->getMockBuilder(StorageInterface::class) - ->setMethods(['getAdobeAccessToken']) - ->setMethods(['getAdobeReAuthToken']) + ->setMethods(['getAdobeAccessToken', 'getAdobeReAuthToken', 'setAdobeReAuthToken']) ->getMockForAbstractClass(); $this->authMock = $this->getMockBuilder(Auth::class) @@ -129,7 +128,7 @@ public function testAroundVerifyIdentityVerifiesAccessTokenWhenModuleIsEnabled() ->method('getAdobeReAuthToken') ->willReturn('reAuthToken'); - $this->authMock->expects($this->once()) + $this->authMock->expects($this->atLeastOnce()) ->method('getAuthStorage') ->willReturn($this->storageMock); @@ -174,7 +173,7 @@ public function testAroundVerifyIdentityThrowsExceptionOnInvalidToken(): void ->method('getAdobeReAuthToken') ->willReturn('invalidToken'); - $this->authMock->expects($this->once()) + $this->authMock->expects($this->atLeastOnce()) ->method('getAuthStorage') ->willReturn($this->storageMock);