本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage类的典型用法代码示例。如果您正苦于以下问题:PHP TokenStorage类的具体用法?PHP TokenStorage怎么用?PHP TokenStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TokenStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param TokenStorage $security
*/
public function __construct(TokenStorage $security)
{
$token = $security->getToken();
if ($token) {
$this->user = $token->getUser();
}
}
示例2: createMainMenu
public function createMainMenu(TokenStorage $tokenStorage)
{
/** @var User $user */
$user = $tokenStorage->getToken()->getUser();
$menu = $this->factory->createItem('root', ['navbar' => true]);
$layout = $menu->addChild('Главная страница', ['icon' => 'home', 'route' => 'homepage']);
$layout = $menu->addChild('Архив игр', ['icon' => 'archive', 'route' => 'archive']);
if ($user instanceof User) {
$dropdown = $menu->addChild($user->getUsername(), ['dropdown' => true, 'caret' => true, 'icon' => 'user']);
$dropdown->addChild('Профиль', ['route' => 'fos_user_profile_edit', 'icon' => 'user']);
$dropdown->addChild('Выход', ['route' => 'fos_user_security_logout', 'icon' => 'sign-out']);
$menu->addChild('Командные настройки', ['route' => 'team_settings', 'icon' => 'users']);
if ($user->hasRole('ROLE_ADMIN')) {
$menu->addChild('Администрирование домена', ['route' => 'sonata_admin_dashboard', 'icon' => 'edit']);
}
} else {
$login = $menu->addChild('Вход', ['dropdown' => true, 'caret' => true, 'icon' => 'sign-in']);
$login->addChild('ВКонтакте', ['route' => 'vkontakte_oauth', 'icon' => 'vk']);
$login->addChild('Facebook', ['route' => 'facebook_oauth', 'icon' => 'facebook']);
$login->addChild('Google+', ['route' => 'google_oauth', 'icon' => 'google-plus']);
$login->addChild('Вход через логин/пароль', ['route' => 'fos_user_security_login', 'icon' => 'sign-in']);
$menu->addChild('Регистрация', ['route' => 'fos_user_registration_register']);
$menu->addChild('Сброс пароля', ['route' => 'fos_user_resetting_request']);
}
return $menu;
}
示例3: testGetSetToken
public function testGetSetToken()
{
$tokenStorage = new TokenStorage();
$this->assertNull($tokenStorage->getToken());
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$tokenStorage->setToken($token);
$this->assertSame($token, $tokenStorage->getToken());
}
示例4: onCoreController
/**
* Update the user "lastActivity" on each request
*
* @param FilterControllerEvent $event
*/
public function onCoreController(FilterControllerEvent $event)
{
// Here we are checking that the current request is a "MASTER_REQUEST",
// and ignore any
// subrequest in the process (for example when
// doing a render() in a twig template)
if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
return;
}
// We are checking a token authentification is available before using
// the User
if ($this->tokenStorage->getToken()) {
$user = $this->tokenStorage->getToken()->getUser();
// We are using a delay during wich the user will be considered as
// still active, in order to
// avoid too much UPDATE in the
// database
// $delay = new \DateTime ();
// $delay
// ->setTimestamp (strtotime ('2 minutes ago'));
// We are checking the Admin class in order to be certain we can
// call "getLastActivity".
// && $user->getLastActivity() < $delay) {
if ($user instanceof User) {
$user->isActiveNow();
$this->em->persist($user);
$this->em->flush();
}
}
}
示例5: isGranted
protected function isGranted($attribute, $object, $user = null)
{
if (!$user) {
$user = $this->tokenStorage->getToken()->getUser();
}
if (!is_object($user)) {
return false;
}
if (in_array('ROLE_ADMINISTRATOR', $user->getRoles())) {
return true;
}
if (!in_array('ROLE_USER', $user->getRoles())) {
return false;
}
if (in_array($attribute, [self::ATTRIBUTE_VIEW, self::ATTRIBUTE_CREATE])) {
return true;
}
/**
* @var Subcontractor $object
*/
if ($attribute == self::ATTRIBUTE_EDIT) {
return $object->getCreatedBy() && $user->getId() == $object->getCreatedBy()->getId() || in_array('ROLE_SUBCONTRACTOR_MANAGER', $user->getRoles());
}
return false;
}
示例6: getUser
/**
* Returns the PartKeeprUser based on the user token within the Symfony2 environment.
*
* @return User The proxy user
*/
public function getUser()
{
$tokenProvider = $this->tokenStorage->getToken()->getAttribute("provider");
$provider = $this->getProvider($tokenProvider);
$username = $this->tokenStorage->getToken()->getUsername();
return $this->getProxyUser($username, $provider, true);
}
示例7: create
/**
* @param Request $request
*
* @return JsonResponse
*
* @throws \Assert\AssertionFailedException
* @throws InvalidMobileApiException
* @throws BlankAliasApiException
* @throws NoTopicsApiException
* @throws InsufficientBalanceApiException
* @throws ExistentMobileApiException
*/
protected function create(Request $request)
{
/** @var UsernamePasswordToken $token */
$token = $this->tokenStorage->getToken();
$uniqueness = $token->getUsername();
$data = $request->request->all();
foreach (array('mobile', 'alias', 'topics') as $key) {
Assertion::keyExists($data, $key);
}
try {
$this->createSubscriptionApiWorker->create($data['mobile'], $uniqueness, $data['alias'], $data['topics'], $data['resellPackage']);
} catch (InvalidMobileApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.INVALID_MOBILE'), 400);
} catch (BlankAliasApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.BLANK_ALIAS'), 400);
} catch (ExistentMobileApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.EXISTENT_MOBILE'), 400);
} catch (NoTopicsApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_TOPICS'), 400);
} catch (NoResellPackageApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_RESELL_PACKAGE'), 400);
} catch (TrialNotAcceptedApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.TRIAL_NOT_ACCEPTED'), 400);
} catch (InsufficientBalanceApiException $e) {
return new JsonResponse(array('code' => 'INFO_SMS.PROFILE.INSUFFICIENT_BALANCE'), 400);
}
return new JsonResponse();
}
示例8: isGranted
/**
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param string|array $attributes
* @param null $object
*
* @return boolean
*/
public function isGranted(AdminInterface $admin, $attributes, $object = null)
{
/** @var Administrator $administrator */
$administrator = $this->tokenStorage->getToken()->getUser();
if (!$administrator instanceof Administrator) {
return false;
}
$availableResources = $administrator->getAvailableResources();
$list = $this->entityManager->getRepository('OctavaAdministratorBundle:Resource')->getList();
if (!is_array($attributes)) {
$attributes = [$attributes];
}
foreach ($attributes as $attribute) {
if (in_array($attribute, ["EXPORT", "VIEW"])) {
$attribute = 'LIST';
}
if (!isset($list[get_class($admin)][$attribute])) {
continue;
}
$currentId = $list[get_class($admin)][$attribute];
if (isset($availableResources[$currentId])) {
return true;
}
}
return false;
}
示例9: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$user = $this->tokenStorage->getToken()->getUser();
$builder->add('text')->add('task', EntityType::class, ['class' => 'AppBundle:Task', 'choice_label' => 'name', 'placeholder' => '===== SELECT TASK =====', 'query_builder' => function (EntityRepository $er) use($user) {
return $er->createQueryBuilder('task')->where('task.owner = :user')->setParameter('user', $user)->orderBy('task.isDefault', 'DESC')->addOrderBy('task.name', 'ASC');
}])->add('finish', CheckboxType::class, ['mapped' => false, 'required' => false]);
}
示例10: pickAction
/**
* @Req\Route("/info-sms/me/pick-profile")
* @Req\Method({"GET"})
*
* @return JsonResponse
*/
public function pickAction()
{
/** @var UsernamePasswordToken $token */
$token = $this->tokenStorage->getToken();
$uniqueness = $token->getUsername();
return new JsonResponse($this->pickProfileApiWorker->pick($uniqueness));
}
示例11: handle
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
$response = new Response();
$response->setStatusCode(403);
$response->setContent('Invalid or missing WSSE.');
$event->setResponse($response);
return;
}
$token = new WsseUserToken();
$token->setUser($matches[1]);
$token->digest = $matches[2];
$token->nonce = $matches[3];
$token->created = $matches[4];
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);
} catch (AuthenticationException $failed) {
$response = new Response();
$response->setStatusCode(403);
$response->getContent($failed->getMessage());
$event->setResponse($response);
}
}
示例12: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$routes = $this->router->getRouteCollection();
$route = $routes->get($request->attributes->get('_route'));
if (!$route->getOption('requires_license')) {
return;
}
if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
// Checking for whitelisted users
try {
$user = $this->tokenStorage->getToken()->getUser();
$today = date('Y-m-d');
if ($user instanceof UserInterface) {
$whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
foreach ($whitelist as $allowed) {
if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
return;
}
}
}
} catch (\Exception $e) {
// Do nothing
}
$url = $this->router->generate('atlassian_connect_unlicensed');
$response = new RedirectResponse($url);
$event->setResponse($response);
}
}
示例13: getUser
/**
* @return User|null
*/
private function getUser()
{
if ($token = $this->tokenStorage->getToken()) {
return $token->getUser();
}
return null;
}
示例14: save
public function save(ContentInterface $content)
{
if (!$content->getId()) {
$content->setAuthor($this->tokenStorage->getToken()->getUser());
}
return parent::save($content);
}
示例15: collectByUniquenessAction
/**
* @Req\Route("/credit/me/profile/balance/collect-operations")
* @Req\Method({"GET"})
*
* @return JsonResponse
*/
public function collectByUniquenessAction()
{
/** @var UsernamePasswordToken $token */
$token = $this->tokenStorage->getToken();
$uniqueness = $token->getUsername();
return new JsonResponse($this->collectOperationsApiWorker->collect($uniqueness));
}