bug #22830 [SecurityBundle] forward compatibility with Symfony 4 (xabbuh)
This PR was merged into the 3.4 branch.
Discussion
----------
[SecurityBundle] forward compatibility with Symfony 4
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | https://github.com/symfony/symfony/pull/22821#issuecomment-302935588
Commits
-------
c783e1e
forward compatibility with Symfony 4
This commit is contained in:
commit
bb2a2e2a32
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bundle\SecurityBundle\DataCollector;
|
namespace Symfony\Bundle\SecurityBundle\DataCollector;
|
||||||
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@ -110,6 +111,14 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
|
|||||||
// fail silently when the logout URL cannot be generated
|
// fail silently when the logout URL cannot be generated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$extractRoles = function ($role) {
|
||||||
|
if (!$role instanceof RoleInterface && !$role instanceof Role) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Roles must be instances of %s or %s (%s given).', RoleInterface::class, Role::class, is_object($role) ? get_class($role) : gettype($role)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $role->getRole();
|
||||||
|
};
|
||||||
|
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'authenticated' => $token->isAuthenticated(),
|
'authenticated' => $token->isAuthenticated(),
|
||||||
@ -117,8 +126,8 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
|
|||||||
'token_class' => $this->hasVarDumper ? new ClassStub(get_class($token)) : get_class($token),
|
'token_class' => $this->hasVarDumper ? new ClassStub(get_class($token)) : get_class($token),
|
||||||
'logout_url' => $logoutUrl,
|
'logout_url' => $logoutUrl,
|
||||||
'user' => $token->getUsername(),
|
'user' => $token->getUsername(),
|
||||||
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles),
|
'roles' => array_map($extractRoles, $assignedRoles),
|
||||||
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
|
'inherited_roles' => array_map($extractRoles, $inheritedRoles),
|
||||||
'supports_role_hierarchy' => null !== $this->roleHierarchy,
|
'supports_role_hierarchy' => null !== $this->roleHierarchy,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user