Skip to content

Commit 41e6b0e

Browse files
committed
ACP2E-4114: Production ACL Permission Check caused Performance Degradation – populateAcl Method is the bottleneck
1 parent 4adb884 commit 41e6b0e

File tree

3 files changed

+5
-2
lines changed
  • app/code/Magento/Authorization
  • lib/internal/Magento/Framework/Authorization/Policy

3 files changed

+5
-2
lines changed

app/code/Magento/Authorization/Model/Acl/Loader/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private function getRulesArray()
224224
private function getRulesArrayForRole(int $roleId): array
225225
{
226226
$groupRoleId = $this->resolveGroupRoleId($roleId);
227-
$cacheKey = self::ACL_RULE_CACHE_KEY . '_' . $groupRoleId;
227+
$cacheKey = hash('sha256', self::ACL_RULE_CACHE_KEY . '_' . $groupRoleId);
228228
$rulesCachedData = $this->aclDataCache->load($cacheKey);
229229
if ($rulesCachedData) {
230230
return $this->serializer->unserialize($rulesCachedData);

app/code/Magento/Authorization/Test/Unit/Model/Acl/Loader/RuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function testPopulateAclForSpecificRoleFromCache(): void
167167
// Expect the role-specific cache key to be read
168168
$this->aclDataCacheMock->expects($this->once())
169169
->method('load')
170-
->with(Rule::ACL_RULE_CACHE_KEY . '_' . $roleId)
170+
->with(hash('sha256', Rule::ACL_RULE_CACHE_KEY . '_' . $roleId))
171171
->willReturn(json_encode($rules));
172172

173173
// ACL expectations: allow for root, then for specific resource

lib/internal/Magento/Framework/Authorization/Policy/Acl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function __construct(Builder $aclBuilder, ?CurrentRoleContext $roleContex
4747
*/
4848
public function isAllowed($roleId, $resourceId, $privilege = null)
4949
{
50+
if ($roleId === null || $roleId === '') { //no user is logged in
51+
return false;
52+
}
5053
try {
5154
$this->roleContext->setRoleId((int) $roleId);
5255
return $this->_aclBuilder->getAcl()->isAllowed($roleId, $resourceId, $privilege);

0 commit comments

Comments
 (0)