作者:BranchBi
项目:KunstmaanBundlesCM
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
/* @var $conn Connection */
$conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
$conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase'));
/* @var $platform AbstractPlatform */
$platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
$conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
/* @var $stmt Statement */
$stmt = $this->getMockForAbstractClass('Kunstmaan\\AdminBundle\\Tests\\Mocks\\StatementMock');
$conn->expects($this->any())->method('executeQuery')->will($this->returnValue($stmt));
$this->em->expects($this->any())->method('getConnection')->will($this->returnValue($conn));
/* @var $conf Configuration */
$conf = $this->getMockBuilder('Doctrine\\ORM\\Configuration')->disableOriginalConstructor()->getMock();
/* @var $strat QuoteStrategy */
$strat = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\QuoteStrategy')->disableOriginalConstructor()->getMock();
$strat->expects($this->any())->method('getTableName')->will($this->returnValue('rootTable'));
$conf->expects($this->any())->method('getQuoteStrategy')->will($this->returnValue($strat));
$conf->expects($this->any())->method('getDefaultQueryHints')->willReturn(array());
$conf->expects($this->any())->method('isSecondLevelCacheEnabled')->willReturn(false);
$this->em->expects($this->any())->method('getConfiguration')->will($this->returnValue($conf));
/* @var $meta ClassMetadata */
$meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
$this->tokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface')->getMock();
$this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($this->token));
$this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock();
$this->object = new AclHelper($this->em, $this->tokenStorage, $this->rh);
}
作者:loic42
项目:Syliu
function it_returns_locale_of_currently_logged_admin_user(TokenStorageInterface $tokenStorage, TokenInterface $token, AdminUserInterface $admin)
{
$admin->getLocaleCode()->willReturn('en_US');
$token->getUser()->willreturn($admin);
$tokenStorage->getToken()->willReturn($token);
$this->getLocaleCode()->shouldReturn('en_US');
}
作者:stopfsted
项目:ilio
/**
* Set the username from injected security context
* @param TokenStorageInterface $securityTokenStorage
* @param AuditLogManager $auditLogManager
*/
public function __construct(TokenStorageInterface $securityTokenStorage, AuditLogManager $auditLogManager)
{
if (null !== $securityTokenStorage && null !== $securityTokenStorage->getToken()) {
$this->user = $securityTokenStorage->getToken()->getUser();
}
$this->manager = $auditLogManager;
}
作者:abdeldaye
项目:pim-community-de
public function __construct(ItemFactory $navigationItemFactory, TokenStorageInterface $tokenStorage, EntityManager $entityManager, TitleServiceInterface $titleService)
{
$this->navItemFactory = $navigationItemFactory;
$this->user = !$tokenStorage->getToken() || is_string($tokenStorage->getToken()->getUser()) ? null : $tokenStorage->getToken()->getUser();
$this->em = $entityManager;
$this->titleService = $titleService;
}
作者:wridger
项目:GremoHmacAuthenticationBundl
/**
* {@inheritdoc}
*/
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
if (null !== ($authorization = $request->headers->get($this->authenticationHeaderName))) {
$headerParts = array_map('trim', explode(' ', $authorization, 2));
if (2 === count($headerParts)) {
$credentialParts = explode(':', $headerParts[1]);
if (2 === count($credentialParts)) {
$token = new HmacUserToken();
$token->setServiceLabel($headerParts[0]);
$token->setUser($credentialParts[0]);
$token->setSignature($credentialParts[1]);
$token->setRequest($request);
try {
$authenticatedToken = $this->authenticationManager->authenticate($token);
// Call setToken() on an instance of SecurityContextInterface or TokenStorageInterface (>=2.6)
$this->tokenStorage->setToken($authenticatedToken);
// Success
return;
} catch (AuthenticationException $exception) {
}
}
}
}
$event->setResponse(new Response(null, 401));
}
作者:BenGorUse
项目:UserBundl
/**
* Constructor.
*
* @param TokenStorageInterface $aTokenStorage The token storage
*/
public function __construct(TokenStorageInterface $aTokenStorage)
{
$token = $aTokenStorage->getToken();
if ($token instanceof TokenInterface) {
$this->currentUser = $token->getUser() instanceof UserInterface ? $token->getUser() : null;
}
}
作者:javiermaduen
项目:futbo
public function __construct(TokenStorageInterface $token, ComunidadProvider $comunidadProvider, ControllerResolverInterface $resolver, LoggerInterface $logger)
{
$this->token = $token->getToken();
$this->comunidadProvider = $comunidadProvider;
$this->resolver = $resolver;
$this->logger = $logger;
}
作者:Yame
项目:mauti
/**
* MenuHelper constructor.
*
* @param CorePermissions $security
* @param TokenStorageInterface $tokenStorage
* @param RequestStack $requestStack
* @param array $mauticParameters
*/
public function __construct(CorePermissions $security, TokenStorageInterface $tokenStorage, RequestStack $requestStack, array $mauticParameters)
{
$this->security = $security;
$this->user = $tokenStorage->getToken()->getUser();
$this->mauticParameters = $mauticParameters;
$this->request = $requestStack->getCurrentRequest();
}
作者:oj
项目:oj
/**
* AbstractJournalItemMailer constructor.
* @param OjsMailer $ojsMailer
* @param RegistryInterface $registry
* @param TokenStorageInterface $tokenStorage
* @param RouterInterface $router
*/
public function __construct(OjsMailer $ojsMailer, RegistryInterface $registry, TokenStorageInterface $tokenStorage, RouterInterface $router)
{
$this->ojsMailer = $ojsMailer;
$this->em = $registry->getManager();
$this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
$this->router = $router;
}
作者:riki34
项目:game
/**
* @param EntityManager $em
* @param RESTResponse $response
* @param ValidatorInterface $validator
* @param TokenStorageInterface $tokenStorage
*/
public function __construct($em, $response, $validator, $tokenStorage)
{
$this->em = $em;
$this->response = $response;
$this->validator = $validator;
$this->user = $tokenStorage->getToken()->getUser();
}
作者:RomanGorbatk
项目:epar-symfon
public function __construct(EntityManager $oEntityManager, TokenStorageInterface $oUser, Ebay $oEbay)
{
$this->oEm = $oEntityManager;
$this->oEbayProfiles = $this->oEm->getRepository('EparServiceBundle:EbayProfiles');
$this->oUser = $oUser->getToken()->getUser();
$this->oEbay = $oEbay;
}
作者:abdeldaye
项目:pim-community-de
public function testBuild()
{
$type = 'history';
$userId = 1;
$user = $this->getMockBuilder('stdClass')->setMethods(['getId'])->getMock();
$user->expects($this->once())->method('getId')->will($this->returnValue($userId));
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$token->expects($this->once())->method('getUser')->will($this->returnValue($user));
$this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token));
$item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface');
$this->factory->expects($this->once())->method('createItem')->with($type, [])->will($this->returnValue($item));
$repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\HistoryItemRepository')->disableOriginalConstructor()->getMock();
$items = [['id' => 1, 'title' => 'test1', 'url' => '/'], ['id' => 2, 'title' => 'test2', 'url' => '/home']];
$repository->expects($this->once())->method('getNavigationItems')->with($userId, $type)->will($this->returnValue($items));
$this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository));
$menu = $this->getMockBuilder('Knp\\Menu\\MenuItem')->disableOriginalConstructor()->getMock();
$childMock = $this->getMock('Knp\\Menu\\ItemInterface');
$childMock2 = clone $childMock;
$children = [$childMock, $childMock2];
$matcher = $this->getMock('\\Knp\\Menu\\Matcher\\Matcher');
$matcher->expects($this->once())->method('isCurrent')->will($this->returnValue(true));
$this->builder->setMatcher($matcher);
$menu->expects($this->exactly(2))->method('addChild');
$menu->expects($this->once())->method('setExtra')->with('type', $type);
$menu->expects($this->once())->method('getChildren')->will($this->returnValue($children));
$menu->expects($this->once())->method('removeChild');
$n = rand(1, 10);
$configMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager')->disableOriginalConstructor()->getMock();
$configMock->expects($this->once())->method('get')->with($this->equalTo('oro_navigation.maxItems'))->will($this->returnValue($n));
$this->manipulator->expects($this->once())->method('slice')->with($menu, 0, $n);
$this->builder->setOptions($configMock);
$this->builder->build($menu, [], $type);
}
作者:clarolin
项目:distributio
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var \Claroline\CoreBundle\Entity\User $user */
$user = $this->tokenStorage->getToken()->getUser();
$locale = null === $user->getLocale() ? $this->platformConfigHandler->getParameter('locale_language') : $user->getLocale();
$builder->add('badge', 'zenstruck_ajax_entity', array('attr' => array('class' => 'fullwidth'), 'theme_options' => array('control_width' => 'col-md-3'), 'placeholder' => $this->translator->trans('badge_form_badge_selection', array(), 'icap_badge'), 'class' => 'IcapBadgeBundle:Badge', 'use_controller' => true, 'repo_method' => sprintf('findByNameForAjax'), 'extra_data' => array('userId' => $user->getId(), 'locale' => $locale)));
}
作者:SamirBouli
项目:pim-community-de
/**
* Get the attribute collection.
*
* TODO This action is only accessible via a GET or POST query, because of too long query URI. To respect standards,
* a refactor must be done.
*
* @param Request $request
*
* @return JsonResponse
*/
public function indexAction(Request $request)
{
$options = [];
$context = ['include_group' => true];
if ($request->request->has('identifiers')) {
$options['identifiers'] = explode(',', $request->request->get('identifiers'));
$context['include_group'] = false;
}
if ($request->request->has('types')) {
$options['types'] = explode(',', $request->request->get('types'));
}
if (empty($options)) {
$options = $request->request->get('options', ['limit' => SearchableRepositoryInterface::FETCH_LIMIT, 'locale' => null]);
}
$token = $this->tokenStorage->getToken();
$options['user_groups_ids'] = $token->getUser()->getGroupsIds();
if (null !== $this->attributeSearchRepository) {
$attributes = $this->attributeSearchRepository->findBySearch($request->request->get('search'), $options);
} else {
if (isset($options['identifiers'])) {
$options['code'] = $options['identifiers'];
}
$attributes = $this->attributeRepository->findBy($options);
}
$normalizedAttributes = $this->normalizer->normalize($attributes, 'internal_api', $context);
return new JsonResponse($normalizedAttributes);
}
作者:WeCam
项目:ihaveanide
private function getUserFromTokenStorage()
{
if (($token = $this->tokenStorage->getToken()) !== null) {
return $token->getUser();
}
throw new \RuntimeException('I don\'t have a token');
}
作者:BranchBi
项目:KunstmaanBundlesCM
/**
* @return \Symfony\Component\Security\Core\User\UserInterface
*/
private function getUser()
{
if (is_null($this->user)) {
$this->user = $this->tokenStorage->getToken()->getUser();
}
return $this->user;
}
作者:moder
项目:foundatio
/**
* Merge in dashboard list into runtime configuration.
*
* {@inheritdoc}
*/
public function merge(array $currentConfig)
{
/** @var User $user */
$user = $this->tokenStorage->getToken()->getUser();
$defaultDashboardNames = [];
foreach ($this->dashboardMgr->getDefaultDashboards($user) as $dashboard) {
$defaultDashboardNames[] = $dashboard->getName();
}
$isDefaultFound = false;
$result = array();
foreach ($this->dashboardMgr->getUserDashboards($user) as $dashboard) {
if (!$dashboard->isAllowed($this->container)) {
continue;
}
$isDefault = in_array($dashboard->getName(), $defaultDashboardNames);
if ($isDefault) {
$isDefaultFound = true;
}
$result[] = array_merge($this->serializeDashboard($dashboard), array('default' => $isDefault));
}
if (!$isDefaultFound) {
// if there's no default dashboard available for a given user then we will display a dashboard
// where user will be able to pick one he/she needs
$dashboard = new SimpleDashboard('default', 'List of user dashboards', 'Modera.backend.dashboard.runtime.DashboardListDashboardActivity');
$result[] = array_merge($this->serializeDashboard($dashboard), array('default' => true));
}
return array_merge($currentConfig, array('modera_backend_dashboard' => array('dashboards' => $result)));
}
作者:koenreinier
项目:oauth-server-bundl
/**
* @param GetResponseEvent $event
*/
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
if (empty($request->headers->get("Authorization"))) {
return;
}
$authHeader = $request->headers->get("Authorization");
if (strpos($authHeader, " ") === false) {
return;
}
list($tokenType, $token) = explode(" ", $authHeader, 2);
if (strtolower($tokenType) !== "bearer") {
return;
}
// Verify that there is an access_token present
/*
if(empty($request->get("access_token"))) {
return;
}
$token = $request->get("access_token");*/
$unauthenticatedToken = new OAuthToken();
$unauthenticatedToken->setToken($token);
try {
$authenticatedToken = $this->authenticationManager->authenticate($unauthenticatedToken);
$this->tokenStorage->setToken($authenticatedToken);
return;
} catch (AuthenticationException $e) {
if ($this->logger !== null) {
$this->logger->notice("Access token authentication failed");
}
}
$response = new Response();
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$event->setResponse($response);
}
作者:MathiasDeweld
项目:EscapeWSSEAuthenticationBundl
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
//find out if the current request contains any information by which the user might be authenticated
if (!$request->headers->has('X-WSSE')) {
return;
}
$ae_message = null;
$this->wsseHeader = $request->headers->get('X-WSSE');
$wsseHeaderInfo = $this->parseHeader();
if ($wsseHeaderInfo !== false) {
$token = new Token($wsseHeaderInfo['Username'], $wsseHeaderInfo['PasswordDigest'], $this->providerKey);
$token->setAttribute('nonce', $wsseHeaderInfo['Nonce']);
$token->setAttribute('created', $wsseHeaderInfo['Created']);
try {
$returnValue = $this->authenticationManager->authenticate($token);
if ($returnValue instanceof TokenInterface) {
return $this->tokenStorage->setToken($returnValue);
} else {
if ($returnValue instanceof Response) {
return $event->setResponse($returnValue);
}
}
} catch (AuthenticationException $ae) {
$event->setResponse($this->authenticationEntryPoint->start($request, $ae));
}
}
}
作者:clarolin
项目:distributio
public function buildForm(FormBuilderInterface $builder, array $options)
{
$token = $this->tokenStorage->getToken();
if ($token === null) {
throw new \LogicException('Unable to get token from security storage for portfolio widget form!');
}
$user = $token->getUser();
if (!$user) {
throw new \LogicException('Unable to get connected user for portfolio widget form!');
}
$builder->add('portfolio_id', 'entity', ['class' => 'IcapPortfolioBundle:Portfolio', 'query_builder' => function (EntityRepository $entityRepository) use($user) {
return $entityRepository->createQueryBuilder('p')->where('p.user = :user')->setParameter('user', $user);
}, 'property_path' => 'portfolio'])->add('widget_id', 'entity', ['class' => 'IcapPortfolioBundle:Widget\\AbstractWidget', 'query_builder' => function (EntityRepository $entityRepository) use($user) {
return $entityRepository->createQueryBuilder('w')->where('w.user = :user')->setParameter('user', $user);
}, 'property_path' => 'widget'])->add('col', 'integer')->add('row', 'integer')->add('sizeX', 'integer')->add('sizeY', 'integer');
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($user) {
$form = $event->getForm();
$choices = [];
$choiceTypes = $this->widgetTypeManager->getWidgetsTypes();
foreach ($choiceTypes as $choiceType) {
$choices[$choiceType['name']] = $choiceType['name'];
}
$form->add('widget_type', 'choice', ['choices' => $choices]);
});
}