Skip to content

Commit 3da90c4

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento/magento2ce into ACP2E-257
2 parents 410a9b1 + d0dccd8 commit 3da90c4

File tree

56 files changed

+1652
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1652
-318
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Analytics\Plugin;
10+
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Integration\Model\Integration;
13+
use Magento\Integration\Model\Validator\BearerTokenValidator;
14+
15+
/**
16+
* Overrides authorization config to always allow analytics token to be used as bearer
17+
*/
18+
class BearerTokenValidatorPlugin
19+
{
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private ScopeConfigInterface $config;
24+
25+
/**
26+
* @param ScopeConfigInterface $config
27+
*/
28+
public function __construct(ScopeConfigInterface $config)
29+
{
30+
$this->config = $config;
31+
}
32+
33+
/***
34+
* Always allow access token for analytics to be used as bearer
35+
*
36+
* @param BearerTokenValidator $subject
37+
* @param bool $result
38+
* @param Integration $integration
39+
* @return bool
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function afterIsIntegrationAllowedAsBearerToken(
43+
BearerTokenValidator $subject,
44+
bool $result,
45+
Integration $integration
46+
): bool {
47+
return $result || $integration->getName() === $this->config->getValue('analytics/integration_name');
48+
}
49+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Analytics\Test\Unit\Plugin;
10+
11+
use Magento\Analytics\Plugin\BearerTokenValidatorPlugin;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Integration\Model\Integration;
14+
use Magento\Integration\Model\Validator\BearerTokenValidator;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class BearerTokenValidatorPluginTest extends TestCase
19+
{
20+
/**
21+
* @var BearerTokenValidatorPlugin
22+
*/
23+
private BearerTokenValidatorPlugin $plugin;
24+
25+
/**
26+
* @var BearerTokenValidator|MockObject
27+
*/
28+
private $validator;
29+
30+
public function setUp(): void
31+
{
32+
$config = $this->createMock(ScopeConfigInterface::class);
33+
$config->method('getValue')
34+
->with('analytics/integration_name')
35+
->willReturn('abc');
36+
$this->plugin = new BearerTokenValidatorPlugin($config);
37+
$this->validator = $this->createMock(BearerTokenValidator::class);
38+
}
39+
40+
public function testTrueIsPassedThrough()
41+
{
42+
$integration = $this->createMock(Integration::class);
43+
$integration->method('__call')
44+
->with('getName')
45+
->willReturn('invalid');
46+
47+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
48+
self::assertTrue($result);
49+
}
50+
51+
public function testFalseWhenIntegrationDoesntMatch()
52+
{
53+
$integration = $this->createMock(Integration::class);
54+
$integration->method('__call')
55+
->with('getName')
56+
->willReturn('invalid');
57+
58+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, false, $integration);
59+
self::assertFalse($result);
60+
}
61+
62+
public function testTrueWhenIntegrationMatches()
63+
{
64+
$integration = $this->createMock(Integration::class);
65+
$integration->method('__call')
66+
->with('getName')
67+
->willReturn('abc');
68+
69+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
70+
self::assertTrue($result);
71+
}
72+
}

app/code/Magento/Analytics/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,7 @@
271271
<argument name="connectionFactory" xsi:type="object">Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory</argument>
272272
</arguments>
273273
</type>
274+
<type name="Magento\Integration\Model\Validator\BearerTokenValidator">
275+
<plugin name="allow_bearer_token" type="Magento\Analytics\Plugin\BearerTokenValidatorPlugin"/>
276+
</type>
274277
</config>

app/code/Magento/Catalog/etc/acl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<resource id="Magento_Catalog::catalog" title="Catalog" translate="title" sortOrder="30">
1313
<resource id="Magento_Catalog::catalog_inventory" title="Inventory" translate="title" sortOrder="10">
1414
<resource id="Magento_Catalog::products" title="Products" translate="title" sortOrder="10">
15-
<resource id="Magento_Catalog::update_attributes" title="Update Attributes" translate="title" sortOrder="10" />
15+
<resource id="Magento_Catalog::update_attributes" title="Mass Update Attributes" translate="title" sortOrder="10" />
1616
<resource id="Magento_Catalog::edit_product_design" title="Edit Product Design" translate="title" sortOrder="20" />
1717
</resource>
1818
<resource id="Magento_Catalog::categories" title="Categories" translate="title" sortOrder="20">
@@ -27,7 +27,7 @@
2727
</resource>
2828
</resource>
2929
<resource id="Magento_Backend::stores_attributes">
30-
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30" />
30+
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30"/>
3131
<resource id="Magento_Catalog::sets" title="Attribute Set" translate="title" sortOrder="40"/>
3232
</resource>
3333
</resource>

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Quantity,Quantity
148148
Edit,Edit
149149
"Are you sure?","Are you sure?"
150150
"Change Status","Change Status"
151-
"Update Attributes","Update Attributes"
151+
"Mass Update Attributes","Mass Update Attributes"
152152
"start typing to search category","start typing to search category"
153153
"New Category","New Category"
154154
"Images (.gif, .jpg, .png)","Images (.gif, .jpg, .png)"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Integration\Model;
10+
11+
use Magento\Integration\Api\Data\UserToken;
12+
use Magento\Integration\Api\Exception\UserTokenException;
13+
use Magento\Integration\Api\UserTokenReaderInterface;
14+
15+
/**
16+
* Checks multiple sources for reading a token
17+
*/
18+
class CompositeTokenReader implements UserTokenReaderInterface
19+
{
20+
/**
21+
* @var UserTokenReaderInterface[]
22+
*/
23+
private $readers;
24+
25+
/**
26+
* @param UserTokenReaderInterface[] $readers
27+
*/
28+
public function __construct(array $readers)
29+
{
30+
$this->readers = $readers;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function read(string $token): UserToken
37+
{
38+
foreach ($this->readers as $reader) {
39+
try {
40+
return $reader->read($token);
41+
} catch (UserTokenException $exception) {
42+
continue;
43+
}
44+
}
45+
46+
throw new UserTokenException('Composite reader could not read a token');
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Integration\Model\Config;
10+
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
/**
15+
* Represents configuration related to WebAPI Authorization
16+
*/
17+
class AuthorizationConfig
18+
{
19+
/**
20+
* XML Path for Enable Integration as Bearer
21+
*/
22+
private const CONFIG_PATH_INTEGRATION_BEARER = 'oauth/consumer/enable_integration_as_bearer';
23+
24+
/**
25+
* @var ScopeConfigInterface
26+
*/
27+
private ScopeConfigInterface $scopeConfig;
28+
29+
/**
30+
* @param ScopeConfigInterface $scopeConfig
31+
*/
32+
public function __construct(ScopeConfigInterface $scopeConfig)
33+
{
34+
$this->scopeConfig = $scopeConfig;
35+
}
36+
37+
/**
38+
* Return if integration access tokens can be used as bearer tokens
39+
*
40+
* @return bool
41+
*/
42+
public function isIntegrationAsBearerEnabled(): bool
43+
{
44+
return $this->scopeConfig->isSetFlag(
45+
self::CONFIG_PATH_INTEGRATION_BEARER,
46+
ScopeInterface::SCOPE_STORE
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)