diff --git a/src/Sylius/Bundle/RbacBundle/Provider/SecurityIdentityProvider.php b/src/Sylius/Bundle/RbacBundle/Provider/SecurityIdentityProvider.php index 71407a6fac63..9d4be004cf56 100644 --- a/src/Sylius/Bundle/RbacBundle/Provider/SecurityIdentityProvider.php +++ b/src/Sylius/Bundle/RbacBundle/Provider/SecurityIdentityProvider.php @@ -14,7 +14,7 @@ use Sylius\Component\Rbac\Model\IdentityInterface; use Sylius\Component\Rbac\Provider\CurrentIdentityProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; /** * @author Paweł Jędrzejewski @@ -22,16 +22,16 @@ class SecurityIdentityProvider implements CurrentIdentityProviderInterface { /** - * @var SecurityContextInterface + * @var TokenStorageInterface */ - private $securityContext; + private $tokenStorage; /** - * @param SecurityContextInterface $securityContext + * @param TokenStorageInterface $tokenStorage */ - public function __construct(SecurityContextInterface $securityContext) + public function __construct(TokenStorageInterface $tokenStorage) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; } /** @@ -39,7 +39,7 @@ public function __construct(SecurityContextInterface $securityContext) */ public function getIdentity() { - if (null === $token = $this->securityContext->getToken()) { + if (null === $token = $this->tokenStorage->getToken()) { return; } diff --git a/src/Sylius/Bundle/RbacBundle/Resources/config/services.xml b/src/Sylius/Bundle/RbacBundle/Resources/config/services.xml index 6bfccf3cae13..113395cc3b37 100644 --- a/src/Sylius/Bundle/RbacBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/RbacBundle/Resources/config/services.xml @@ -30,7 +30,7 @@ - + diff --git a/src/Sylius/Bundle/RbacBundle/spec/Provider/SecurityIdentityProviderSpec.php b/src/Sylius/Bundle/RbacBundle/spec/Provider/SecurityIdentityProviderSpec.php index 06160e8c0ca1..5209343cf1c1 100644 --- a/src/Sylius/Bundle/RbacBundle/spec/Provider/SecurityIdentityProviderSpec.php +++ b/src/Sylius/Bundle/RbacBundle/spec/Provider/SecurityIdentityProviderSpec.php @@ -15,8 +15,8 @@ use Sylius\Component\Rbac\Model\IdentityInterface; use Sylius\Component\Rbac\Provider\CurrentIdentityProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\User\UserInterface; /** @@ -24,9 +24,9 @@ */ class SecurityIdentityProviderSpec extends ObjectBehavior { - function let(SecurityContextInterface $securityContext) + function let(TokenStorageInterface $tokenStorage) { - $this->beConstructedWith($securityContext); + $this->beConstructedWith($tokenStorage); } function it_is_initializable() @@ -39,39 +39,39 @@ function it_is_a_rbac_identity_provider() $this->shouldHaveType(CurrentIdentityProviderInterface::class); } - function it_returns_null_if_user_is_not_logged_in($securityContext) + function it_returns_null_if_user_is_not_logged_in($tokenStorage) { - $securityContext->getToken()->shouldBeCalled()->willReturn(null); + $tokenStorage->getToken()->shouldBeCalled()->willReturn(null); $this->getIdentity()->shouldReturn(null); } - function it_returns_null_if_token_exists_but_still_no_authenticated_user($securityContext, TokenInterface $token) + function it_returns_null_if_token_exists_but_still_no_authenticated_user($tokenStorage, TokenInterface $token) { - $securityContext->getToken()->shouldBeCalled()->willReturn($token); + $tokenStorage->getToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn(null); $this->getIdentity()->shouldReturn(null); } - function it_returns_null_if_token_exists_but_its_an_anonymous_user($securityContext, AnonymousToken $token) + function it_returns_null_if_token_exists_but_its_an_anonymous_user($tokenStorage, AnonymousToken $token) { - $securityContext->getToken()->shouldBeCalled()->willReturn($token); + $tokenStorage->getToken()->shouldBeCalled()->willReturn($token); $this->getIdentity()->shouldReturn(null); } - function it_returns_the_authenticated_user($securityContext, TokenInterface $token, IdentityInterface $user) + function it_returns_the_authenticated_user($tokenStorage, TokenInterface $token, IdentityInterface $user) { - $securityContext->getToken()->shouldBeCalled()->willReturn($token); + $tokenStorage->getToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn($user); $this->getIdentity()->shouldReturn($user); } - function it_throws_exception_if_user_does_not_implement_identity_interface($securityContext, TokenInterface $token, UserInterface $user) + function it_throws_exception_if_user_does_not_implement_identity_interface($tokenStorage, TokenInterface $token, UserInterface $user) { - $securityContext->getToken()->shouldBeCalled()->willReturn($token); + $tokenStorage->getToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn($user); $this diff --git a/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php b/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php index 736022d46447..666f25c54a3d 100644 --- a/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php +++ b/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php @@ -26,7 +26,8 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Intl\Intl; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\User\UserInterface; abstract class DefaultContext extends RawMinkContext implements Context, KernelAwareContext @@ -252,7 +253,7 @@ protected function generatePageUrl($page, array $parameters = array()) */ protected function getUser() { - $token = $this->getSecurityContext()->getToken(); + $token = $this->getTokenStorage()->getToken(); if (null === $token) { throw new \Exception('No token found in security context.'); @@ -262,11 +263,19 @@ protected function getUser() } /** - * @return SecurityContextInterface + * @return TokenStorageInterface */ - protected function getSecurityContext() + protected function getTokenStorage() { - return $this->getContainer()->get('security.context'); + return $this->getContainer()->get('security.token_storage'); + } + + /** + * @return AuthorizationCheckerInterface + */ + protected function getAuthorizationChecker() + { + return $this->getContainer()->get('security.authorization_checker'); } /** diff --git a/src/Sylius/Bundle/ResourceBundle/Behat/WebContext.php b/src/Sylius/Bundle/ResourceBundle/Behat/WebContext.php index 711655b38777..ebb64922c04d 100644 --- a/src/Sylius/Bundle/ResourceBundle/Behat/WebContext.php +++ b/src/Sylius/Bundle/ResourceBundle/Behat/WebContext.php @@ -334,7 +334,7 @@ public function iShouldSeeThatMuchResourcesInTheList($amount, $type) */ public function iShouldBeLoggedIn() { - if (!$this->getSecurityContext()->isGranted('ROLE_USER')) { + if (!$this->getAuthorizationChecker()->isGranted('ROLE_USER')) { throw new AuthenticationException('User is not authenticated.'); } } @@ -344,7 +344,7 @@ public function iShouldBeLoggedIn() */ public function iShouldNotBeLoggedIn() { - if ($this->getSecurityContext()->isGranted('ROLE_USER')) { + if ($this->getAuthorizationChecker()->isGranted('ROLE_USER')) { throw new AuthenticationException('User was not expected to be logged in, but he is.'); } } diff --git a/src/Sylius/Bundle/UserBundle/Context/CustomerContext.php b/src/Sylius/Bundle/UserBundle/Context/CustomerContext.php index cbb578fb3ad1..b0dd98471594 100644 --- a/src/Sylius/Bundle/UserBundle/Context/CustomerContext.php +++ b/src/Sylius/Bundle/UserBundle/Context/CustomerContext.php @@ -14,7 +14,8 @@ use Sylius\Component\User\Context\CustomerContextInterface; use Sylius\Component\User\Model\CustomerInterface; use Sylius\Component\User\Model\UserInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * @author Michał Marcinkowski @@ -22,16 +23,23 @@ class CustomerContext implements CustomerContextInterface { /** - * @var SecurityContextInterface + * @var TokenStorageInterface */ - private $securityContext; + private $tokenStorage; /** - * @param SecurityContextInterface $securityContext + * @var AuthorizationCheckerInterface */ - public function __construct(SecurityContextInterface $securityContext) + private $authorizationChecker; + + /** + * @param TokenStorageInterface $tokenStorage + * @param AuthorizationCheckerInterface $authorizationChecker + */ + public function __construct(TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; + $this->authorizationChecker = $authorizationChecker; } /** @@ -41,10 +49,12 @@ public function __construct(SecurityContextInterface $securityContext) */ public function getCustomer() { - if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') - && $this->securityContext->getToken()->getUser() instanceof UserInterface - ) { - return $this->securityContext->getToken()->getUser()->getCustomer(); + if (null === $token = $this->tokenStorage->getToken()) { + return null; + } + + if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') && $token->getUser() instanceof UserInterface) { + return $token->getUser()->getCustomer(); } return null; diff --git a/src/Sylius/Bundle/UserBundle/EventListener/UserDeleteListener.php b/src/Sylius/Bundle/UserBundle/EventListener/UserDeleteListener.php index ee889f5820f0..a48066817fb2 100644 --- a/src/Sylius/Bundle/UserBundle/EventListener/UserDeleteListener.php +++ b/src/Sylius/Bundle/UserBundle/EventListener/UserDeleteListener.php @@ -15,7 +15,7 @@ use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; /** * User delete listener. @@ -27,9 +27,9 @@ class UserDeleteListener { /** - * @var SecurityContextInterface + * @var TokenStorageInterface */ - protected $securityContext; + protected $tokenStorage; /** * @var SessionInterface @@ -37,12 +37,12 @@ class UserDeleteListener protected $session; /** - * @param SecurityContextInterface $securityContext + * @param TokenStorageInterface $tokenStorage * @param SessionInterface $session */ - public function __construct(SecurityContextInterface $securityContext, SessionInterface $session) + public function __construct(TokenStorageInterface $tokenStorage, SessionInterface $session) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->session = $session; } @@ -60,7 +60,7 @@ public function deleteUser(ResourceEvent $event) ); } - if (($token = $this->securityContext->getToken()) && ($loggedUser = $token->getUser()) && ($loggedUser->getId() === $user->getId())) { + if (($token = $this->tokenStorage->getToken()) && ($loggedUser = $token->getUser()) && ($loggedUser->getId() === $user->getId())) { $event->stopPropagation(); $this->session->getBag('flashes')->add('error', 'Cannot remove currently logged in user.'); } diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml index 8ac97ea38388..8f26aa98d40a 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml @@ -60,7 +60,8 @@ - + + @@ -98,7 +99,7 @@ - + @@ -143,7 +144,7 @@ - + diff --git a/src/Sylius/Bundle/UserBundle/Security/Authentication/AuthenticationUtils.php b/src/Sylius/Bundle/UserBundle/Security/Authentication/AuthenticationUtils.php index ae6a4532723a..97e36c709a82 100644 --- a/src/Sylius/Bundle/UserBundle/Security/Authentication/AuthenticationUtils.php +++ b/src/Sylius/Bundle/UserBundle/Security/Authentication/AuthenticationUtils.php @@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface as Container; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AuthenticationException; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Security; /** * Extracts Security Errors from Request @@ -48,13 +48,13 @@ public function getLastAuthenticationError($clearSession = true) $session = $request->getSession(); $authenticationException = null; - if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { - $authenticationException = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR); - } elseif ($session !== null && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { - $authenticationException = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); + if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) { + $authenticationException = $request->attributes->get(Security::AUTHENTICATION_ERROR); + } elseif ($session !== null && $session->has(Security::AUTHENTICATION_ERROR)) { + $authenticationException = $session->get(Security::AUTHENTICATION_ERROR); if ($clearSession) { - $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR); + $session->remove(Security::AUTHENTICATION_ERROR); } } @@ -68,7 +68,7 @@ public function getLastUsername() { $session = $this->getRequest()->getSession(); - return null === $session ? '' : $session->get(SecurityContextInterface::LAST_USERNAME); + return null === $session ? '' : $session->get(Security::LAST_USERNAME); } /** diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php index 16b33a63d342..d30790e1b53d 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php @@ -15,9 +15,9 @@ use Sylius\Bundle\UserBundle\UserEvents; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AuthenticationException; -use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; /** @@ -27,9 +27,9 @@ class UserLogin implements UserLoginInterface { /** - * @var SecurityContextInterface + * @var TokenStorageInterface */ - private $securityContext; + private $tokenStorage; /** * @var UserCheckerInterface @@ -42,13 +42,13 @@ class UserLogin implements UserLoginInterface private $eventDispatcher; /** - * @param SecurityContextInterface $securityContext + * @param TokenStorageInterface $tokenStorage * @param UserCheckerInterface $userChecker * @param EventDispatcherInterface $eventDispatcher */ - public function __construct(SecurityContextInterface $securityContext, UserCheckerInterface $userChecker, EventDispatcherInterface $eventDispatcher) + public function __construct(TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker, EventDispatcherInterface $eventDispatcher) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->userChecker = $userChecker; $this->eventDispatcher = $eventDispatcher; } @@ -66,7 +66,7 @@ public function login(UserInterface $user, $firewallName = 'main') throw new AuthenticationException('Unauthenticated token'); } - $this->securityContext->setToken($token); + $this->tokenStorage->setToken($token); $this->eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, new UserEvent($user)); } diff --git a/src/Sylius/Bundle/UserBundle/spec/Context/CustomerContextSpec.php b/src/Sylius/Bundle/UserBundle/spec/Context/CustomerContextSpec.php index 948233cb9e12..04496cffd68c 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Context/CustomerContextSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Context/CustomerContextSpec.php @@ -14,17 +14,18 @@ use PhpSpec\ObjectBehavior; use Sylius\Component\User\Model\CustomerInterface; use Sylius\Component\User\Model\UserInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * @author Michał Marcinkowski */ class CustomerContextSpec extends ObjectBehavior { - function let(SecurityContextInterface $securityContext) + function let(TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker) { - $this->beConstructedWith($securityContext); + $this->beConstructedWith($tokenStorage, $authorizationChecker); } function it_is_initializable() @@ -32,19 +33,19 @@ function it_is_initializable() $this->shouldHaveType('Sylius\Bundle\UserBundle\Context\CustomerContext'); } - function it_gets_customer_from_currently_logged_user($securityContext, TokenInterface $token, UserInterface $user, CustomerInterface $customer) + function it_gets_customer_from_currently_logged_user($tokenStorage, $authorizationChecker, TokenInterface $token, UserInterface $user, CustomerInterface $customer) { - $securityContext->getToken()->willReturn($token); - $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true); + $tokenStorage->getToken()->willReturn($token); + $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true); $token->getUser()->willReturn($user); $user->getCustomer()->willReturn($customer); $this->getCustomer()->shouldReturn($customer); } - function it_returns_null_if_user_is_not_logged_in($securityContext) + function it_returns_null_if_user_is_not_logged_in($tokenStorage) { - $securityContext->getToken()->willReturn(null); + $tokenStorage->getToken()->willReturn(null); $this->getCustomer()->shouldReturn(null); } diff --git a/src/Sylius/Bundle/UserBundle/spec/EventListener/UserDeleteListenerSpec.php b/src/Sylius/Bundle/UserBundle/spec/EventListener/UserDeleteListenerSpec.php index 45cc5053cc1f..7e3c9329a779 100644 --- a/src/Sylius/Bundle/UserBundle/spec/EventListener/UserDeleteListenerSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/EventListener/UserDeleteListenerSpec.php @@ -17,8 +17,8 @@ use Sylius\Component\User\Model\UserInterface; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; /** * User delete listener spec. @@ -29,9 +29,9 @@ */ class UserDeleteListenerSpec extends ObjectBehavior { - function let(SecurityContextInterface $securityContext, SessionInterface $session, FlashBagInterface $flashBag) + function let(TokenStorageInterface $tokenStorage, SessionInterface $session, FlashBagInterface $flashBag) { - $this->beConstructedWith($securityContext, $session); + $this->beConstructedWith($tokenStorage, $session); $session->getBag('flashes')->willReturn($flashBag); } @@ -40,12 +40,12 @@ function it_is_initializable() $this->shouldHaveType('Sylius\Bundle\UserBundle\EventListener\UserDeleteListener'); } - function it_deletes_user_if_it_is_different_than_currently_loggged_one(ResourceEvent $event, UserInterface $userToBeDeleted, UserInterface $currentlyLoggedUser, $flashBag, $securityContext, TokenInterface $tokenInterface) + function it_deletes_user_if_it_is_different_than_currently_loggged_one(ResourceEvent $event, UserInterface $userToBeDeleted, UserInterface $currentlyLoggedUser, $flashBag, $tokenStorage, TokenInterface $tokenInterface) { $event->getSubject()->willReturn($userToBeDeleted); $userToBeDeleted->getId()->willReturn(11); - $securityContext->getToken()->willReturn($tokenInterface); + $tokenStorage->getToken()->willReturn($tokenInterface); $currentlyLoggedUser->getId()->willReturn(1); $tokenInterface->getUser()->willReturn($currentlyLoggedUser); @@ -54,12 +54,12 @@ function it_deletes_user_if_it_is_different_than_currently_loggged_one(ResourceE $this->deleteUser($event); } - function it_deletes_user_if_no_user_is_logged_in(ResourceEvent $event, UserInterface $userToBeDeleted, $flashBag, $securityContext, TokenInterface $tokenInterface) + function it_deletes_user_if_no_user_is_logged_in(ResourceEvent $event, UserInterface $userToBeDeleted, $flashBag, $tokenStorage, TokenInterface $tokenInterface) { $event->getSubject()->willReturn($userToBeDeleted); $userToBeDeleted->getId()->willReturn(11); - $securityContext->getToken()->willReturn($tokenInterface); + $tokenStorage->getToken()->willReturn($tokenInterface); $tokenInterface->getUser()->willReturn(null); $event->stopPropagation()->shouldNotBeCalled(); @@ -67,23 +67,23 @@ function it_deletes_user_if_no_user_is_logged_in(ResourceEvent $event, UserInter $this->deleteUser($event); } - function it_deletes_user_if_there_is_no_token(ResourceEvent $event, UserInterface $userToBeDeleted, $flashBag, $securityContext) + function it_deletes_user_if_there_is_no_token(ResourceEvent $event, UserInterface $userToBeDeleted, $flashBag, $tokenStorage) { $event->getSubject()->willReturn($userToBeDeleted); $userToBeDeleted->getId()->willReturn(11); - $securityContext->getToken()->willReturn(null); + $tokenStorage->getToken()->willReturn(null); $event->stopPropagation()->shouldNotBeCalled(); $flashBag->add('error', Argument::any())->shouldNotBeCalled(); $this->deleteUser($event); } - function it_does_not_allow_to_delete_currently_logged_user(ResourceEvent $event, UserInterface $userToBeDeleted, UserInterface $currentlyLoggedInUser, $securityContext, $flashBag, TokenInterface $token) + function it_does_not_allow_to_delete_currently_logged_user(ResourceEvent $event, UserInterface $userToBeDeleted, UserInterface $currentlyLoggedInUser, $tokenStorage, $flashBag, TokenInterface $token) { $event->getSubject()->willReturn($userToBeDeleted); $userToBeDeleted->getId()->willReturn(1); - $securityContext->getToken()->willReturn($token); + $tokenStorage->getToken()->willReturn($token); $currentlyLoggedInUser->getId()->willReturn(1); $token->getUser()->willReturn($currentlyLoggedInUser); diff --git a/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php b/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php index 00a93771bd75..969239b6fe1f 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php @@ -18,11 +18,11 @@ use Sylius\Bundle\UserBundle\UserEvents; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\CredentialsExpiredException; use Symfony\Component\Security\Core\Exception\DisabledException; -use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; /** @@ -31,9 +31,9 @@ */ class UserLoginSpec extends ObjectBehavior { - function let(SecurityContextInterface $securityContext, UserCheckerInterface $userChecker, EventDispatcherInterface $eventDispatcher) + function let(TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker, EventDispatcherInterface $eventDispatcher) { - $this->beConstructedWith($securityContext, $userChecker, $eventDispatcher); + $this->beConstructedWith($tokenStorage, $userChecker, $eventDispatcher); } function it_is_initializable() @@ -46,48 +46,48 @@ function it_implements_user_login_interface() $this->shouldImplement(UserLoginInterface::class); } - function it_throws_exception_and_does_not_log_user_in_when_user_is_disabled($securityContext, $userChecker, $eventDispatcher, UserInterface $user) + function it_throws_exception_and_does_not_log_user_in_when_user_is_disabled($tokenStorage, $userChecker, $eventDispatcher, UserInterface $user) { $user->getRoles()->willReturn(array('ROLE_TEST')); $userChecker->checkPreAuth($user)->willThrow(DisabledException::class); - $securityContext->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); + $tokenStorage->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldNotBeCalled(); $this->shouldThrow(DisabledException::class)->during('login', array($user)); } - function it_throws_exception_and_does_not_log_user_in_when_user_account_status_is_invalid($securityContext, $userChecker, $eventDispatcher, UserInterface $user) + function it_throws_exception_and_does_not_log_user_in_when_user_account_status_is_invalid($tokenStorage, $userChecker, $eventDispatcher, UserInterface $user) { $user->getRoles()->willReturn(array('ROLE_TEST')); $userChecker->checkPreAuth($user)->shouldBeCalled(); $userChecker->checkPostAuth($user)->willThrow(CredentialsExpiredException::class); - $securityContext->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); + $tokenStorage->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldNotBeCalled(); $this->shouldThrow(CredentialsExpiredException::class)->during('login', array($user)); } - function it_throws_exception_and_does_not_log_user_in_when_user_has_no_roles($securityContext, $userChecker, $eventDispatcher, UserInterface $user) + function it_throws_exception_and_does_not_log_user_in_when_user_has_no_roles($tokenStorage, $userChecker, $eventDispatcher, UserInterface $user) { $user->getRoles()->willReturn(array()); $userChecker->checkPreAuth($user)->shouldBeCalled(); $userChecker->checkPostAuth($user)->shouldBeCalled(); - $securityContext->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); + $tokenStorage->setToken(Argument::type(UsernamePasswordToken::class))->shouldNotBeCalled(); $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldNotBeCalled(); $this->shouldThrow(AuthenticationException::class)->during('login', array($user)); } - function it_logs_user_in($securityContext, $userChecker, $eventDispatcher, UserInterface $user) + function it_logs_user_in($tokenStorage, $userChecker, $eventDispatcher, UserInterface $user) { $user->getRoles()->willReturn(array('ROLE_TEST')); $userChecker->checkPreAuth($user)->shouldBeCalled(); $userChecker->checkPostAuth($user)->shouldBeCalled(); - $securityContext->setToken(Argument::type(UsernamePasswordToken::class))->shouldBeCalled(); + $tokenStorage->setToken(Argument::type(UsernamePasswordToken::class))->shouldBeCalled(); $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldBeCalled(); $this->login($user); diff --git a/src/Sylius/Bundle/WebBundle/Behat/WebContext.php b/src/Sylius/Bundle/WebBundle/Behat/WebContext.php index 1c2459ac28e7..fcefffcf4b8f 100644 --- a/src/Sylius/Bundle/WebBundle/Behat/WebContext.php +++ b/src/Sylius/Bundle/WebBundle/Behat/WebContext.php @@ -480,7 +480,7 @@ public function iShouldBeOnTheOrderPage($action, $number) */ public function iAmNotAuthenticated() { - $this->getSecurityContext()->setToken(null); + $this->getTokenStorage()->setToken(null); $this->getContainer()->get('session')->invalidate(); } diff --git a/src/Sylius/Bundle/WebBundle/Menu/BackendMenuBuilder.php b/src/Sylius/Bundle/WebBundle/Menu/BackendMenuBuilder.php index dfec55d34123..80858b0d604b 100644 --- a/src/Sylius/Bundle/WebBundle/Menu/BackendMenuBuilder.php +++ b/src/Sylius/Bundle/WebBundle/Menu/BackendMenuBuilder.php @@ -112,14 +112,14 @@ protected function addAssortmentMenu(ItemInterface $menu, array $childOptions, $ ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.assortment', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.taxonomy.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.taxonomy.index')) { $child->addChild('taxonomies', array( 'route' => 'sylius_backend_taxonomy_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-folder-close'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.taxonomies', $section))); } - if ($this->authorizationChecker->isGranted('sylius.product.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.product.index')) { $child->addChild('products', array( 'route' => 'sylius_backend_product_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-th-list'), @@ -130,21 +130,21 @@ protected function addAssortmentMenu(ItemInterface $menu, array $childOptions, $ ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.stockables', $section))); } - if ($this->authorizationChecker->isGranted('sylius.product_option.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.product_option.index')) { $child->addChild('options', array( 'route' => 'sylius_backend_product_option_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-th'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.options', $section))); } - if ($this->authorizationChecker->isGranted('sylius.product_attribute.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.product_attribute.index')) { $child->addChild('product_attributes', array( 'route' => 'sylius_backend_product_attribute_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-list-alt'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.attributes', $section))); } - if ($this->authorizationChecker->isGranted('sylius.product_archetype.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.product_archetype.index')) { $child->addChild('product_archetypes', array( 'route' => 'sylius_backend_product_archetype_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-compressed'), @@ -170,31 +170,31 @@ protected function addContentMenu(ItemInterface $menu, array $childOptions, $sec ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.content', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.simple_block.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.simple_block.index')) { $child->addChild('blocks', array( 'route' => 'sylius_backend_block_overview', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-th-large'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.blocks', $section))); } - if ($this->authorizationChecker->isGranted('sylius.static_content.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.static_content.index')) { $child->addChild('Pages', array( 'route' => 'sylius_backend_static_content_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-file'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.pages', $section))); } - if ($this->authorizationChecker->isGranted('sylius.menu.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.menu.index')) { $child->addChild('Menus', array( 'route' => 'sylius_backend_menu_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-list-alt'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.menus', $section))); } - if ($this->authorizationChecker->isGranted('sylius.slideshow.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.slideshow.index')) { $child->addChild('Slideshow', array( 'route' => 'sylius_backend_slideshow_block_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-film'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.slideshow', $section))); } - if ($this->authorizationChecker->isGranted('sylius.route.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.route.index')) { $child->addChild('Routes', array( 'route' => 'sylius_backend_route_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-random'), @@ -220,19 +220,19 @@ protected function addMarketingMenu(ItemInterface $menu, array $childOptions, $s ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.marketing', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.promotion.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.promotion.index')) { $child->addChild('promotions', array( 'route' => 'sylius_backend_promotion_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-bullhorn'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.promotions', $section))); } - if ($this->authorizationChecker->isGranted('sylius.promotion.create')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.promotion.create')) { $child->addChild('new_promotion', array( 'route' => 'sylius_backend_promotion_create', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-plus-sign'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.new_promotion', $section))); } - if ($this->authorizationChecker->isGranted('sylius.manage.email')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.manage.email')) { $child->addChild('emails', array( 'route' => 'sylius_backend_email_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-envelope'), @@ -258,13 +258,13 @@ protected function addSupportMenu(ItemInterface $menu, array $childOptions, $sec ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.support', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.contact_request.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.contact_request.index')) { $child->addChild('contact_requests', array( 'route' => 'sylius_backend_contact_request_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-envelope'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.contact_requests', $section))); } - if ($this->authorizationChecker->isGranted('sylius.contact_topic.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.contact_topic.index')) { $child->addChild('contact_topics', array( 'route' => 'sylius_backend_contact_topic_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-align-justify'), @@ -290,25 +290,25 @@ protected function addCustomerMenu(ItemInterface $menu, array $childOptions, $se ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.customer', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.customer.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.customer.index')) { $child->addChild('customers', array( 'route' => 'sylius_backend_customer_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-user'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.customers', $section))); } - if ($this->authorizationChecker->isGranted('sylius.group.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.group.index')) { $child->addChild('groups', array( 'route' => 'sylius_backend_group_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-home'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.groups', $section))); } - if ($this->authorizationChecker->isGranted('sylius.role.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.role.index')) { $child->addChild('roles', array( 'route' => 'sylius_backend_role_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-sort-by-attributes'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.roles', $section))); } - if ($this->authorizationChecker->isGranted('sylius.permission.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.permission.index')) { $child->addChild('permissions', array( 'route' => 'sylius_backend_permission_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-lock'), @@ -334,25 +334,25 @@ protected function addSalesMenu(ItemInterface $menu, array $childOptions, $secti ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.sales', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.order.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.order.index')) { $child->addChild('orders', array( 'route' => 'sylius_backend_order_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-shopping-cart'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.orders', $section))); } - if ($this->authorizationChecker->isGranted('sylius.shipment.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.shipment.index')) { $child->addChild('shipments', array( 'route' => 'sylius_backend_shipment_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-plane'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.shipments', $section))); } - if ($this->authorizationChecker->isGranted('sylius.payment.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.payment.index')) { $child->addChild('payments', array( 'route' => 'sylius_backend_payment_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-credit-card'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.payments', $section))); } - if ($this->authorizationChecker->isGranted('sylius.report.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.report.index')) { $child->addChild('reports', array( 'route' => 'sylius_backend_report_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-stats'), @@ -378,98 +378,98 @@ protected function addConfigurationMenu(ItemInterface $menu, array $childOptions ->setLabel($this->translate(sprintf('sylius.backend.menu.%s.configuration', $section))) ; - if ($this->authorizationChecker->isGranted('sylius.settings.general')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.settings.general')) { $child->addChild('general_settings', array( 'route' => 'sylius_backend_general_settings', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-info-sign'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.general_settings', $section))); } - if ($this->authorizationChecker->isGranted('sylius.settings.security')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.settings.security')) { $child->addChild('security_settings', array( 'route' => 'sylius_backend_security_settings', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-lock'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.security_settings', $section))); } - if ($this->authorizationChecker->isGranted('sylius.channel.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.channel.index')) { $child->addChild('channels', array( 'route' => 'sylius_backend_channel_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.channels', $section))); } - if ($this->authorizationChecker->isGranted('sylius.locale.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.locale.index')) { $child->addChild('locales', array( 'route' => 'sylius_backend_locale_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-flag'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.locales', $section))); } - if ($this->authorizationChecker->isGranted('sylius.payment_method.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.payment_method.index')) { $child->addChild('payment_methods', array( 'route' => 'sylius_backend_payment_method_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-credit-card'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.payment_methods', $section))); } - if ($this->authorizationChecker->isGranted('sylius.currency.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.currency.index')) { $child->addChild('currencies', array( 'route' => 'sylius_backend_currency_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-usd'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.currencies', $section))); } - if ($this->authorizationChecker->isGranted('sylius.settings.taxation')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.settings.taxation')) { $child->addChild('taxation_settings', array( 'route' => 'sylius_backend_taxation_settings', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.taxation_settings', $section))); } - if ($this->authorizationChecker->isGranted('sylius.tax_category.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.tax_category.index')) { $child->addChild('tax_categories', array( 'route' => 'sylius_backend_tax_category_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.tax_categories', $section))); } - if ($this->authorizationChecker->isGranted('sylius.tax_rate.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.tax_rate.index')) { $child->addChild('tax_rates', array( 'route' => 'sylius_backend_tax_rate_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.tax_rates', $section))); } - if ($this->authorizationChecker->isGranted('sylius.shipping_category.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.shipping_category.index')) { $child->addChild('shipping_categories', array( 'route' => 'sylius_backend_shipping_category_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.shipping_categories', $section))); } - if ($this->authorizationChecker->isGranted('sylius.shipping_method.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.shipping_method.index')) { $child->addChild('shipping_methods', array( 'route' => 'sylius_backend_shipping_method_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-cog'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.shipping_methods', $section))); } - if ($this->authorizationChecker->isGranted('sylius.country.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.country.index')) { $child->addChild('countries', array( 'route' => 'sylius_backend_country_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-flag'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.countries', $section))); } - if ($this->authorizationChecker->isGranted('sylius.zone.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.zone.index')) { $child->addChild('zones', array( 'route' => 'sylius_backend_zone_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-globe'), ))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.zones', $section))); } - if ($this->authorizationChecker->isGranted('sylius.api_client.index')) { + if ($this->rbacAuthorizationChecker->isGranted('sylius.api_client.index')) { $child->addChild('api_clients', array( 'route' => 'sylius_backend_api_client_index', 'labelAttributes' => array('icon' => 'glyphicon glyphicon-globe'), diff --git a/src/Sylius/Bundle/WebBundle/Menu/FrontendMenuBuilder.php b/src/Sylius/Bundle/WebBundle/Menu/FrontendMenuBuilder.php index 3e6101da086a..180423af7c18 100644 --- a/src/Sylius/Bundle/WebBundle/Menu/FrontendMenuBuilder.php +++ b/src/Sylius/Bundle/WebBundle/Menu/FrontendMenuBuilder.php @@ -18,12 +18,13 @@ use Sylius\Component\Cart\Provider\CartProviderInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Currency\Provider\CurrencyProviderInterface; -use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface; +use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface as RbacAuthorizationCheckerInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\Taxonomy\Model\TaxonInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Intl\Intl; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Translation\TranslatorInterface; /** @@ -66,38 +67,47 @@ class FrontendMenuBuilder extends MenuBuilder */ protected $channelContext; + /** + * @var TokenStorageInterface + */ + protected $tokenStorage; + /** * Constructor. * - * @param FactoryInterface $factory - * @param SecurityContextInterface $securityContext - * @param TranslatorInterface $translator - * @param EventDispatcherInterface $eventDispatcher + * @param FactoryInterface $factory * @param AuthorizationCheckerInterface $authorizationChecker + * @param TranslatorInterface $translator + * @param EventDispatcherInterface $eventDispatcher + * @param RbacAuthorizationCheckerInterface $rbacAuthorizationChecker * @param CurrencyProviderInterface $currencyProvider - * @param RepositoryInterface $taxonomyRepository - * @param CartProviderInterface $cartProvider - * @param CurrencyHelper $currencyHelper + * @param RepositoryInterface $taxonomyRepository + * @param CartProviderInterface $cartProvider + * @param CurrencyHelper $currencyHelper + * @param ChannelContextInterface $channelContext + * @param TokenStorageInterface $tokenStorage */ public function __construct( - FactoryInterface $factory, - SecurityContextInterface $securityContext, - TranslatorInterface $translator, - EventDispatcherInterface $eventDispatcher, + FactoryInterface $factory, AuthorizationCheckerInterface $authorizationChecker, + TranslatorInterface $translator, + EventDispatcherInterface $eventDispatcher, + RbacAuthorizationCheckerInterface $rbacAuthorizationChecker, CurrencyProviderInterface $currencyProvider, - RepositoryInterface $taxonomyRepository, - CartProviderInterface $cartProvider, - CurrencyHelper $currencyHelper, - ChannelContextInterface $channelContext + RepositoryInterface $taxonomyRepository, + CartProviderInterface $cartProvider, + CurrencyHelper $currencyHelper, + ChannelContextInterface $channelContext, + TokenStorageInterface $tokenStorage ) { - parent::__construct($factory, $securityContext, $translator, $eventDispatcher, $authorizationChecker); + parent::__construct($factory, $authorizationChecker, $translator, $eventDispatcher, $rbacAuthorizationChecker); $this->currencyProvider = $currencyProvider; $this->taxonomyRepository = $taxonomyRepository; $this->cartProvider = $cartProvider; $this->currencyHelper = $currencyHelper; $this->channelContext = $channelContext; + $this->tokenStorage = $tokenStorage; } /** @@ -133,7 +143,7 @@ public function createMainMenu() '%total%' => $this->currencyHelper->convertAndFormatAmount($cartTotals['total']) ))); - if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $route = $this->request === null ? '' : $this->request->get('_route'); if (1 === preg_match('/^(sylius_account)/', $route)) { @@ -168,18 +178,18 @@ public function createMainMenu() ))->setLabel($this->translate('sylius.frontend.menu.main.register')); } - if ($this->securityContext->isGranted('ROLE_ADMINISTRATION_ACCESS') || $this->securityContext->isGranted('ROLE_PREVIOUS_ADMIN')) { + if ($this->authorizationChecker->isGranted('ROLE_ADMINISTRATION_ACCESS') || $this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { $routeParams = array( 'route' => 'sylius_backend_dashboard', 'linkAttributes' => array('title' => $this->translate('sylius.frontend.menu.main.administration')), 'labelAttributes' => array('icon' => 'icon-briefcase icon-large', 'iconOnly' => false) ); - if ($this->securityContext->isGranted('ROLE_PREVIOUS_ADMIN')) { + if ($this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { $routeParams = array_merge($routeParams, array( 'route' => 'sylius_switch_user_return', 'routeParameters' => array( - 'username' => $this->securityContext->getToken()->getUsername(), + 'username' => $this->tokenStorage->getToken()->getUsername(), '_switch_user' => '_exit' ) )); diff --git a/src/Sylius/Bundle/WebBundle/Menu/LocaleMenuBuilder.php b/src/Sylius/Bundle/WebBundle/Menu/LocaleMenuBuilder.php index 12453b9f6f69..e5703b237a5e 100644 --- a/src/Sylius/Bundle/WebBundle/Menu/LocaleMenuBuilder.php +++ b/src/Sylius/Bundle/WebBundle/Menu/LocaleMenuBuilder.php @@ -14,10 +14,10 @@ use Knp\Menu\FactoryInterface; use Knp\Menu\ItemInterface; use Sylius\Component\Locale\Provider\LocaleProviderInterface; -use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface; +use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface as RbacAuthorizationCheckerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Intl\Intl; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Translation\TranslatorInterface; /** @@ -33,21 +33,22 @@ class LocaleMenuBuilder extends MenuBuilder protected $localeProvider; /** - * @param FactoryInterface $factory - * @param SecurityContextInterface $securityContext - * @param TranslatorInterface $translator + * @param FactoryInterface $factory + * @param AuthorizationCheckerInterface $authorizationChecker + * @param TranslatorInterface $translator * @param EventDispatcherInterface $eventDispatcher - * @param LocaleProviderInterface $localeProvider + * @param LocaleProviderInterface $localeProvider + * @param RbacAuthorizationCheckerInterface $rbacAuthorizationChecker */ public function __construct( - FactoryInterface $factory, - SecurityContextInterface $securityContext, - TranslatorInterface $translator, - EventDispatcherInterface $eventDispatcher, - LocaleProviderInterface $localeProvider, - AuthorizationCheckerInterface $authorizationChecker + FactoryInterface $factory, + AuthorizationCheckerInterface $authorizationChecker, + TranslatorInterface $translator, + EventDispatcherInterface $eventDispatcher, + LocaleProviderInterface $localeProvider, + RbacAuthorizationCheckerInterface $rbacAuthorizationChecker ) { - parent::__construct($factory, $securityContext, $translator, $eventDispatcher, $authorizationChecker); + parent::__construct($factory, $authorizationChecker, $translator, $eventDispatcher, $rbacAuthorizationChecker); $this->localeProvider = $localeProvider; } diff --git a/src/Sylius/Bundle/WebBundle/Menu/MenuBuilder.php b/src/Sylius/Bundle/WebBundle/Menu/MenuBuilder.php index d418f6a7d9d3..b2a8009bc5c1 100644 --- a/src/Sylius/Bundle/WebBundle/Menu/MenuBuilder.php +++ b/src/Sylius/Bundle/WebBundle/Menu/MenuBuilder.php @@ -12,10 +12,10 @@ namespace Sylius\Bundle\WebBundle\Menu; use Knp\Menu\FactoryInterface; -use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface; +use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface as RbacAuthorizationCheckerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Translation\TranslatorInterface; /** @@ -35,9 +35,9 @@ abstract class MenuBuilder /** * Security context. * - * @var SecurityContextInterface + * @var AuthorizationCheckerInterface */ - protected $securityContext; + protected $authorizationChecker; /** * Translator instance. @@ -59,31 +59,31 @@ abstract class MenuBuilder protected $eventDispatcher; /** - * @var AuthorizationCheckerInterface + * @var RbacAuthorizationCheckerInterface */ - protected $authorizationChecker; + protected $rbacAuthorizationChecker; /** * Constructor. * - * @param FactoryInterface $factory - * @param SecurityContextInterface $securityContext - * @param TranslatorInterface $translator - * @param EventDispatcherInterface $eventDispatcher + * @param FactoryInterface $factory * @param AuthorizationCheckerInterface $authorizationChecker + * @param TranslatorInterface $translator + * @param EventDispatcherInterface $eventDispatcher + * @param RbacAuthorizationCheckerInterface $rbacAuthorizationChecker */ public function __construct( FactoryInterface $factory, - SecurityContextInterface $securityContext, + AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, EventDispatcherInterface $eventDispatcher, - AuthorizationCheckerInterface $authorizationChecker + RbacAuthorizationCheckerInterface $rbacAuthorizationChecker ) { $this->factory = $factory; - $this->securityContext = $securityContext; + $this->authorizationChecker = $authorizationChecker; $this->translator = $translator; $this->eventDispatcher = $eventDispatcher; - $this->authorizationChecker = $authorizationChecker; + $this->rbacAuthorizationChecker = $rbacAuthorizationChecker; } /** diff --git a/src/Sylius/Bundle/WebBundle/Resources/config/services.xml b/src/Sylius/Bundle/WebBundle/Resources/config/services.xml index e77915ec4357..aa8f5616492e 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/WebBundle/Resources/config/services.xml @@ -64,7 +64,7 @@ - + @@ -73,13 +73,14 @@ + - + @@ -89,7 +90,7 @@ - +