本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::getUser方法的具体用法?PHP TokenInterface::getUser怎么用?PHP TokenInterface::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\TokenInterface
的用法示例。
在下文中一共展示了TokenInterface::getUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* {@inheritDoc}
*/
public function getUser()
{
if (is_object($user = $this->token->getUser())) {
return $user;
}
return null;
}
示例2: vote
public function vote(TokenInterface $token, $object, array $attributes)
{
if ($object instanceof ResourceCollection) {
$granted = false;
$user = null;
if ($token->getUser() instanceof User) {
$user = $token->getUser();
}
if ($this->manager->hasTemporaryAccessOnSomeResources($user)) {
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute) && $this->supportsClass($object)) {
foreach ($object->getResources() as $resource) {
if ($this->manager->hasTemporaryAccess($resource, $user)) {
$granted = true;
break;
}
}
}
}
}
if ($granted) {
return VoterInterface::ACCESS_GRANTED;
} else {
return VoterInterface::ACCESS_DENIED;
}
}
return VoterInterface::ACCESS_ABSTAIN;
}
示例3: vote
/**
* {@inheritdoc}
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
if (!$token->getUser() instanceof User) {
return VoterInterface::ACCESS_ABSTAIN;
}
return $token->getUser()->hasRole('ROLE_SUPER_ADMIN') ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_ABSTAIN;
}
示例4: voteOnAttribute
/**
* @param string $attribute
* @param CourseLearningMaterialInterface $material
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute($attribute, $material, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
$course = $material->getCourse();
if (!$course) {
return false;
}
switch ($attribute) {
case self::VIEW:
$granted = $this->isViewGranted($course->getId(), $course->getSchool()->getId(), $user);
// prevent access if associated LM is in draft, and the current user has no elevated privileges.
if ($granted) {
$granted = $this->userHasRole($token->getUser(), ['Faculty', 'Course Director', 'Developer']) || LearningMaterialStatusInterface::IN_DRAFT !== $material->getLearningMaterial()->getStatus()->getId();
}
return $granted;
break;
case self::CREATE:
case self::EDIT:
case self::DELETE:
// prevent any sort of write operation (create/edit/delete) if the parent course is locked or archived.
if ($course->isLocked() || $course->isArchived()) {
return false;
}
return $this->isWriteGranted($course->getId(), $course->getSchool()->getId(), $user);
break;
}
return false;
}
示例5: onAuthenticationSuccess
/**
* @param Request $request
* @param TokenInterface $token
*
* @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$token->getUser()->setLastlogin(new \DateTime());
$token->getUser()->save();
$log = new UserLog();
$log->setIpSource($request->getClientIp());
$token->getUser()->addUserLog($log);
$token->getUser()->save();
/** @var SecurityContext $securityContext */
$securityContext = $this->container->get('security.context');
if ($securityContext->isGranted('ROLE_SUPER_ADMIN')) {
return new RedirectResponse($this->container->get('router')->generate('sonata_admin_dashboard'));
}
if ($securityContext->isGranted('ROLE_ADMIN')) {
return new RedirectResponse($this->container->get('router')->generate('pgs_admin_dashboard'));
}
if ($securityContext->isGranted('ROLE_OFFICE')) {
return new RedirectResponse($this->container->get('router')->generate('pgs_office_dashboard'));
}
if ($securityContext->isGranted('ROLE_PRINCIPAL')) {
return new RedirectResponse($this->container->get('router')->generate('pgs_principal_dashboard'));
}
if ($securityContext->isGranted('ROLE_SALES')) {
return new RedirectResponse($this->container->get('router')->generate('pgs_sales_dashboard'));
}
if ($securityContext->isGranted('ROLE_USER')) {
return new RedirectResponse($this->container->get('router')->generate('homepage'));
}
}
示例6: vote
/**
* Returns the vote for the given parameters.
*
* This method must return one of the following constants:
* ACCESS_GRANTED, ACCESS_DENIED, or ACCESS_ABSTAIN.
*
* @param TokenInterface $token A TokenInterface instance
* @param object $object The object to secure
* @param array $attributes An array of attributes associated with the method being invoked
*
* @return integer either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
$result = VoterInterface::ACCESS_ABSTAIN;
if (!$this->supportsClass(get_class($object))) {
return $result;
}
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
continue;
}
$result = VoterInterface::ACCESS_DENIED;
switch ($attribute) {
case Product::PRODUCT_OWNER:
if ($token->getUser() === $object->getUser()) {
return VoterInterface::ACCESS_GRANTED;
}
break;
case Product::PRODUCT_LIKE:
#echo '<pre>'; var_dump($object->getLikers()); exit;
if ($token->getUser() !== $object->getUser() && !$object->getLikers()->contains($token->getUser())) {
return VoterInterface::ACCESS_GRANTED;
}
break;
}
}
return $result;
}
示例7: vote
public function vote(TokenInterface $token, $object, array $attributes)
{
if (0 === strpos($attributes[0], 'ROLE_')) {
if ($token->getUser() instanceof User && in_array('ROLE_SUPER_ADMIN', $token->getUser()->getRoles())) {
return self::ACCESS_GRANTED;
}
}
return self::ACCESS_ABSTAIN;
}
示例8: getAuthenticationResponse
/**
* @param TokenInterface $token
*
* @return array
*/
public static function getAuthenticationResponse(TokenInterface $token)
{
$response = array('success' => false);
if ($token->isAuthenticated() && $token->getUser() instanceof User) {
/* @var User $user */
$user = $token->getUser();
$response = array('success' => true, 'profile' => self::userToArray($user));
}
return $response;
}
示例9: onAuthenticationSuccess
/**
* Redirige une authentification OAuth réussie vers le formulaire de demande d'authorisation
* @param Request $request
* @param TokenInterface $token
* @return RedirectResponse
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
if (!is_null($token->getUser()->getOauthClient())) {
$client = $token->getUser()->getOauthClient();
$redirection = new RedirectResponse($this->router->generate('fos_oauth_server_authorize', array('client_id' => $client->getPublicId(), 'response_type' => 'code', 'redirect_uri' => $client->getRedirectUris()[0])));
} else {
$redirection = new RedirectResponse('/');
}
return $redirection;
}
示例10: canDelete
/**
* Удалять могут: Пользователь-Владелец, Администратор
*/
private function canDelete(User $user, TokenInterface $token)
{
if (!$token->getUser() instanceof User) {
return false;
}
if ($token->getUser() === $user) {
return true;
}
return $this->decisionManager->decide($token, array('ROLE_ADMIN'));
}
示例11: logout
/**
* {@inheritdoc}
* @see user_logout()
*/
public function logout(Request $request, Response $response, TokenInterface $token)
{
$user = $token->getUser();
if (is_a($user, 'Bangpound\\Bundle\\DrupalBundle\\Security\\User\\User')) {
/** @var \Bangpound\Bundle\DrupalBundle\Security\User\User $user */
$user = $token->getUser()->getDrupalUser();
watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
module_invoke_all('user_logout', $user);
$GLOBALS['user'] = drupal_anonymous_user();
}
}
示例12: isGranted
/**
* @inheritdoc
*/
public function isGranted($attributes, $object = null)
{
if (!is_array($attributes)) {
$attributes = [$attributes];
}
if (null === $object) {
$object = $this->token->getUser();
}
$acceptedRoles = array_intersect($attributes, $object->getRoles());
return 0 !== count($acceptedRoles);
}
示例13: vote
/**
* {@inheritdoc}
*/
public function vote(TokenInterface $token, $page, array $attributes)
{
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute) && $this->supportsClass($page)) {
$userClass = $this->userClass;
if ($token->getUser() instanceof $userClass && $token->getUser()->hasRole('ROLE_VICTOIRE') || $page->getAuthor() === $token->getUser()) {
return VoterInterface::ACCESS_GRANTED;
}
}
}
return VoterInterface::ACCESS_DENIED;
}
示例14: authenticateToken
/**
* {@inheritdoc}
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (is_subclass_of($token->getUser(), $this->userClass)) {
return new PreAuthenticatedToken($token->getUser(), $token->getCredentials(), $providerKey, $token->getUser()->getRoles());
}
$ssoToken = $this->tokenRepository->find($token->getCredentials());
if (!$ssoToken) {
throw new AuthenticationException();
}
$user = $userProvider->loadUserByUsername($ssoToken->getUsername());
return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
示例15: setUp
public function setUp()
{
$this->user = $this->prophesize(UserInterface::class);
$this->token = $this->prophesize(TokenInterface::class);
$this->token->getUser()->willReturn($this->user);
$this->accessControlManager = $this->prophesize(AccessControlManagerInterface::class);
$this->tokenStorage = $this->prophesize(TokenStorageInterface::class);
$this->tokenStorage->getToken()->willReturn($this->token->reveal());
$this->securedEntitySubscriber = new SecuredEntitySubscriber($this->accessControlManager->reveal(), $this->tokenStorage->reveal());
$this->visitor = $this->prophesize(GenericSerializationVisitor::class);
$this->objectEvent = $this->prophesize(ObjectEvent::class);
$this->objectEvent->getVisitor()->willReturn($this->visitor);
}