-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6088 from magento-tango/TANGO-PR-09-01-2020_24
TANGO PR 09-01-2020 v2.4
- Loading branch information
Showing
21 changed files
with
723 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/code/Magento/Customer/Model/Customer/Authorization.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Model\Customer; | ||
|
||
use Magento\Authorization\Model\UserContextInterface; | ||
use Magento\Customer\Model\CustomerFactory; | ||
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; | ||
use Magento\Framework\AuthorizationInterface; | ||
use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Checks if customer is logged in and authorized in the current store | ||
*/ | ||
class Authorization implements AuthorizationInterface | ||
{ | ||
/** | ||
* @var UserContextInterface | ||
*/ | ||
private $userContext; | ||
|
||
/** | ||
* @var CustomerFactory | ||
*/ | ||
private $customerFactory; | ||
|
||
/** | ||
* @var CustomerResource | ||
*/ | ||
private $customerResource; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* Authorization constructor. | ||
* | ||
* @param UserContextInterface $userContext | ||
* @param CustomerFactory $customerFactory | ||
* @param CustomerResource $customerResource | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
UserContextInterface $userContext, | ||
CustomerFactory $customerFactory, | ||
CustomerResource $customerResource, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->userContext = $userContext; | ||
$this->customerFactory = $customerFactory; | ||
$this->customerResource = $customerResource; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isAllowed($resource, $privilege = null) | ||
{ | ||
if ($resource === AuthorizationService::PERMISSION_SELF | ||
&& $this->userContext->getUserId() | ||
&& $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER | ||
) { | ||
$customer = $this->customerFactory->create(); | ||
$this->customerResource->load($customer, $this->userContext->getUserId()); | ||
$currentStoreId = $this->storeManager->getStore()->getId(); | ||
$sharedStoreIds = $customer->getSharedStoreIds(); | ||
|
||
return in_array($currentStoreId, $sharedStoreIds); | ||
} | ||
|
||
return false; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/code/Magento/Customer/Model/Customer/AuthorizationComposite.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Model\Customer; | ||
|
||
use Magento\Framework\AuthorizationInterface; | ||
|
||
/** | ||
* Class to invalidate user credentials | ||
*/ | ||
class AuthorizationComposite implements AuthorizationInterface | ||
{ | ||
/** | ||
* @var AuthorizationInterface[] | ||
*/ | ||
private $authorizationChecks; | ||
|
||
/** | ||
* AuthorizationComposite constructor. | ||
* | ||
* @param AuthorizationInterface[] $authorizationChecks | ||
*/ | ||
public function __construct( | ||
array $authorizationChecks | ||
) { | ||
$this->authorizationChecks = $authorizationChecks; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isAllowed($resource, $privilege = null) | ||
{ | ||
$result = false; | ||
|
||
foreach ($this->authorizationChecks as $authorizationCheck) { | ||
$result = $authorizationCheck->isAllowed($resource, $privilege); | ||
if (!$result) { | ||
break; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.