/** * {@inheritdoc} */ protected function getSessionId() { if (!$this->session->isStarted()) { $this->session->start(); } return $this->session->getId(); }
public function testImplicitGrant() { // Start session manually. $session = new Session(new MockFileSessionStorage()); $session->start(); // Query authorization endpoint with response_type = token. $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient1.com/', 'redirect_uri' => 'http://democlient1.com/redirect_uri', 'scope' => 'demoscope1', 'state' => $session->getId()); $server = array('PHP_AUTH_USER' => 'demousername1', 'PHP_AUTH_PW' => 'demopassword1'); $client = $this->createClient(); $crawler = $client->request('GET', '/api/oauth2/authorize', $parameters, array(), $server); $this->assertTrue($client->getResponse()->isRedirect()); // Check basic auth response that can simply compare. $authResponse = Request::create($client->getResponse()->headers->get('Location'), 'GET'); $this->assertEquals('http://democlient1.com/redirect_uri', $authResponse->getSchemeAndHttpHost() . $authResponse->getBaseUrl() . $authResponse->getPathInfo()); // Check basic token response that can simply compare. $tokenResponse = $authResponse->query->all(); $this->assertEquals('bearer', $tokenResponse['token_type']); $this->assertEquals('demoscope1', $tokenResponse['scope']); $this->assertEquals($session->getId(), $tokenResponse['state']); // Query debug endpoint with access_token. $parameters = array(); $server = array('HTTP_Authorization' => implode(' ', array('Bearer', $tokenResponse['access_token']))); $client = $this->createClient(); $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, array(), $server); $debugResponse = json_decode($client->getResponse()->getContent(), true); $this->assertEquals('demousername1', $debugResponse['username']); }
private function createCustomerFromSession() { $customer = new Customer(); $customer->setSessionId($this->session->getId()); $this->entityManager->persist($customer); $this->entityManager->flush(); return $customer; }
public function getMediacenterUserToken(User $user, Mediacenter $mediacenter) { $hasInwicastToken = $this->session->get("has_inwicast_token"); $token = $this->session->getId(); if (!$hasInwicastToken) { $this->mediacenterUserRepository->createInwicastUserIfNotExists($user, $token, $mediacenter); $this->session->set("has_inwicast_token", true); } return $token; }
/** * Generate token string */ private function generateTokenString() { if ($this->session->isStarted() === false) { $this->session->start(); } return sha1($this->secret . $this->session->getId()); }
/** * Find all objects having the same session as the current user. * @return QueueItem[]|null */ public function findQueueItemsInSession() { $session = new Session(); $sessionId = $session->getId(); $qb = parent::createQueryBuilder('e'); $qb->where('e.sessionId = :sessionId')->andWhere('e.isDeleted = 0')->setParameter('sessionId', $sessionId); return $qb->getQuery()->getResult(); }
public function testNothingIsPersisted() { session_id('nullsessionstorage'); $storage = $this->getStorage(); $session = new Session($storage); $session->start(); $this->assertEquals('nullsessionstorage', $session->getId()); $this->assertNull($session->get('something')); }
/** * @param $sessionTag * @param $sessionValue * @return QueueItem */ public static function registerQueueItem($sessionTag, $sessionValue) { $session = new Session(); $QueueItem = new QueueItem(); $QueueItem->setSessionId($session->getId()); $QueueItem->setSessionTag($sessionTag); $QueueItem->setSessionValue($sessionValue); return $QueueItem; }
/** * @Given I am logged in as :username */ public function iAmAnLoggedInAs($username) { $session = new Session(); $client = $this->getSession()->getDriver()->getClient(); $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); $session = $this->getContainer()->get('session'); $user = $this->getKernel()->getContainer()->get('oauth2_server.test_bundle.end_user_manager')->getEndUserByUsername($username); if (null === $user) { throw new \Exception('Unknown user'); } $token = new UsernamePasswordToken($user, 'secret', 'main', $user->getRoles()); $session->set('_security_main', serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); }
public function loginAction(Request $request) { $this->getLogger()->debug("Login request."); $username = $request->request->get('username'); $password = $request->request->get('password'); $systemDBManager = $this->get('doctrine')->getManager('system'); $user = $systemDBManager->getRepository('AmburgerBundle:User')->checkUser($username, $password); if (is_numeric($user)) { switch ($user) { // username case -1: return $this->render('AmburgerBundle:DataCorrection:login.html.twig', array('show_username_notice' => true, 'show_password_notice' => false, 'logged_in' => false)); // password // password case -2: return $this->render('AmburgerBundle:DataCorrection:login.html.twig', array('show_password_notice' => true, 'show_username_notice' => false, 'logged_in' => false)); default: return $this->render('AmburgerBundle:DataCorrection:login.html.twig'); } } else { //set logged in //set user session $session = $this->getRequest()->getSession(); // Get started session if (!$session instanceof Session) { $session = new Session(); // if there is no session, start it $session->start(); } $value = $session->getId(); // get session id $session->set('name', $username); $session->set('userid', $user->getId()); $this->getLogger()->debug("Successfully logged in user: " . $username); if ($user->getAdmin()) { return $this->redirect($this->generateUrl('admin_overview')); } else { return $this->redirect($this->generateUrl('correction')); } } }
/** * Inject values into the context * * The provider is expected to use the ->set() interface on the context object to * provide information. * * @param ContextInterface $context * @return mixed */ public function inject(ContextInterface $context) { $context->set('session_id', sha1($this->session->getId() . __CLASS__)); }
/** * {@inheritdoc} */ protected function getSessionId() { $this->session->start(); return $this->session->getId(); }
/** * Função para validar a sessão * * @param Session $session * @return bool */ public function checkSession(Session $session) { $logger = $this->get('logger'); $session->getMetadataBag()->getCreated(); $session->getMetadataBag()->getLastUsed(); if (time() - $session->getMetadataBag()->getLastUsed() > $this->maxIdleTime) { $session->invalidate(); $logger->error("Sessão inválida:\n" . $session->getId()); //throw new SessionExpired(); // direciona para a página de sessão expirada return false; } else { return true; } }
/** * Extends Symfony's built in class to ensure that the session has already * started when we try and get the ID. * * @return string The session ID */ public function getId() { parent::start(); return parent::getId(); }
/** * @Route( * path = "/search/searchByText/{text}", * name = "searchByText", * defaults={"text" = "012345678901"} * ) */ public function searchByTextAction(Request $request) { /* TODO: DISPLAYING A MESSAGE WHEN NOTHING HAS BEEN FOUND */ /* DISPLAYING THE INPUT FORM */ $textQuery = array('text' => ''); $form = $this->createFormBuilder($textQuery)->setAction($this->generateUrl('searchByText'))->setMethod('GET')->add('text', TextType::class, array('label' => 'Keywords', 'attr' => array('class' => 'form-control')))->add('submit', SubmitType::class, array('label' => 'Look for possible equivalent items', 'attr' => array('class' => 'btn btn-default')))->getForm(); $form->handleRequest($request); if ($form->isSubmitted()) { // Form has been submitted or some text has been passed in the URL $data = $form->getData(); if ($data['text'] != '') { $text = $data['text']; } // ... perform some action, such as saving the task to the database //$resString = print_r($data); //return(new Response($resString)); /* searching by text, if found displaying what has been found */ // TODO: // moving configuration data outside in a configuration file $conf = new GenericConfiguration(); $conf->setCountry('com')->setAccessKey('AKIAJD57F37W2KGLXEVQ')->setSecretKey('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')->setAssociateTag('quercusroburn-20')->setRequest('\\ApaiIO\\Request\\Soap\\Request'); $query = new Search(); $query->setKeywords($text); $query->setCategory('Music'); $query->setResponseGroup(array('ItemAttributes', 'Images', 'Tracks')); // More detailed information $apaiIo = new ApaiIO($conf); $response = $apaiIo->runOperation($query); $logger = $this->get('logger'); $records = array(); if (property_exists($response, 'Items')) { // handlig the case when one item only is returned, // in that case $response->Items->Item is not an array!!! $results = array(); if (is_array($response->Items->Item)) { $results = $response->Items->Item; } else { $results[] = $response->Items->Item; } foreach ($results as $item) { $logger->info('----------------------------'); $record = new Record(); // ASIN $logger->info("ASIN: {$item->ASIN}"); $record->setAsin($item->ASIN); // TODO: // now getting UPC just for testing purposes, // this should be stopped... if (property_exists($item->ItemAttributes, 'UPC')) { $logger->info('UPC: ' . $item->ItemAttributes->UPC); } else { $logger->info('NO UPC!'); } // Artist // Structure changes if several artists are listed if (property_exists($item->ItemAttributes, 'Artist')) { if (!is_array($item->ItemAttributes->Artist)) { $record->setArtist($item->ItemAttributes->Artist); } else { $logger->info('Here it is the array: ' . print_r($item->ItemAttributes->Artist, true) . ' - Seen as: ' . gettype($item->ItemAttributes->Artist) . ' - size: ' . sizeof($item->ItemAttributes->Artist)); $artist = 'Various artists ('; for ($i = 1; $i < sizeof($item->ItemAttributes->Artist); $i++) { $artist .= $item->ItemAttributes->Artist[$i]; if ($i < sizeof($item->ItemAttributes->Artist) - 1) { $artist .= ', '; } } $artist .= ')'; $record->setArtist($artist); $logger->info('Values: ' . join(' - ', $item->ItemAttributes->Artist)); } $logger->info('Artist: ' . $record->getArtist()); } // title $record->setTitle($item->ItemAttributes->Title); $logger->info('Title: ' . $record->getTitle()); // label if (property_exists($item->ItemAttributes, 'Brand')) { $record->setRecordLabel($item->ItemAttributes->Brand); } else { if (property_exists($item->ItemAttributes, 'Label')) { $record->setRecordLabel($item->ItemAttributes->Label); } else { // } } $logger->info('Label: ' . $record->getRecordLabel()); // Year if (property_exists($item->ItemAttributes, 'ReleaseDate')) { $record->setYear(substr($item->ItemAttributes->ReleaseDate, 0, 4)); $logger->info('Label: ' . $record->getYear()); } else { $logger->info('\'ReleaseDate\' not available, so dunno how to get the year...'); } // Media count if (property_exists($item->ItemAttributes, 'NumberOfItems')) { $record->setMediaCount($item->ItemAttributes->NumberOfItems); $logger->info('Media count: ' . $record->getMediaCount()); } else { if (property_exists($item->ItemAttributes, 'NumberOfDiscs')) { $record->setMediaCount($item->ItemAttributes->NumberOfDiscs); $logger->info('Media count: ' . $record->getMediaCount()); } else { //$logger->info(print_r($item->ItemAttributes, true)); $logger->info('Number of media not available. Now what?! Tentatively I guess the value \'1\'.'); $record->setMediaCount('1'); $item->ItemAttributes->NumberOfItems = '1'; } } // Media type $record->setMediaType($item->ItemAttributes->Binding); $logger->info('Media type: ' . $record->getMediaType()); // Cover image (it may be unavailable) if (property_exists($item, 'LargeImage')) { $record->setCoverImageUrl($item->LargeImage->URL); $logger->info('Cover image URL: ' . $record->getCoverImageUrl()); } // each media item has a track list $trackLists = array(); if (property_exists($item, 'Tracks')) { // Tracks info is not for granted... // When number of media/items is greater than 1, but // the tracks list is just one // (it happened at least once with B000B66OVW, see EX03 below) // then ->Tracks->Disc is not an array at it should be // when more than one media are actually present $oneListOnly = 0; if (!is_array($item->Tracks->Disc)) { $logger->info('The web service reported ' . $record->getMediaCount() . ' media, but all tracks are in just one list.'); $oneListOnly = 1; } if ($record->getMediaCount() < 2 || $oneListOnly) { // one item only, one list if (property_exists($item->Tracks, 'Disc')) { $totalTracks = sizeof($item->Tracks->Disc->Track); for ($i = 0; $i < $totalTracks; $i++) { $tracksLists[0][] = $item->Tracks->Disc->Track[$i]->_; } } else { $logger->info('Couldn\'t find "Disc"... ' . print_r($item->Tracks, true)); } } else { for ($j = 0; $j < $record->getMediaCount(); $j++) { $totalTracks = sizeof($item->Tracks->Disc[$j]->Track); for ($i = 0; $i < $totalTracks; $i++) { $tracksLists[$j][] = $item->Tracks->Disc[$j]->Track[$i]->_; } } } $record->setTracksLists($tracksLists); } else { // Tracks info is not available (no property "Tracks" in the object) $logger->info('Tracks info is not available'); } // Appending the record to the list of possible records $records[] = $record; } } // TODO: // saving the array of results in session $session = new Session(); //$session->start(); $session->set('results', $records); $logger->info('Session ID: ' . $session->getId()); // Returning the list of the results // TODO: // handling in the template the id of each record, so that in can be passed // afterwards for insertion and recovered from session without re-fetching // its data return $this->render('AppBundle:Record:results.html.twig', array('records' => $records)); } // The form has not been submitted, displaying the form return $this->render('AppBundle:Record:searchByText.html.twig', array('form' => $form->createView())); }
private function getSessionID($request) { $session = $request->getSession(); $logger = $this->get('logger'); if (!$session instanceof Session) { $logger->info('Session Not Found'); $session = new Session(); $session->start(); } else { if (!$session->isStarted()) { $logger->info('Session Started'); $session->start(); } $logger->info('Session Found = ' . $session->getId()); } $logger->info('Session ID = ' . $session->getId()); return $session->getId(); }
/** * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $sessionId = $this->session->getId(); $view->vars['sessionId'] = $this->encryption->encrypt($sessionId); }
/** * Creates a backup of current sessionId in case of sessionId change, * we need this value to identify user on YooChoose side. * Be aware that session is automatically destroyed when user logs off, * in this case the new sessionId will be set. This issue can be treated * as a later improvement as it's not required by YooChoose to work correctly. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if ($this->session->get('yc-session-id', null) == null) { $this->session->set('yc-session-id', $this->session->getId()); } }
public function testGoodTokenFormSubmitRememberMe() { // Start session manually. $session = new Session(new MockFileSessionStorage()); $session->start(); // Save cookie REMEMBERME from first client. $client = $this->createClient(); $crawler = $client->request('GET', '/oauth2/login'); $buttonCrawlerNode = $crawler->selectButton('submit'); $form = $buttonCrawlerNode->form(array('_username' => 'demousername3', '_password' => 'demopassword3', '_remember_me' => true)); $client->submit($form); $rememberMe = $client->getCookieJar()->get('REMEMBERME'); // Reuse cookie REMEMBERME for second client. $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient3.com/', 'redirect_uri' => 'http://democlient3.com/redirect_uri', 'scope' => 'demoscope1 demoscope2 demoscope3', 'state' => $session->getId()); $server = array(); $client = $this->createClient(); $client->getCookieJar()->get($rememberMe); $crawler = $client->request('GET', '/oauth2/authorize', $parameters, array(), $server); $this->assertTrue($client->getResponse()->isRedirect()); }
public function rememberSession(Session $session) { if (null !== ($token = $this->app['repo.api-oauth-tokens']->find($this->token))) { $this->app['manipulator.api-oauth-token']->rememberSessionId($token, $session->getId()); } }
<?php /** * Created by PhpStorm. * User: kendoctor * Date: 15/8/18 * Time: 下午9:44 */ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; require __DIR__ . '/vendor/autoload.php'; $session = new Session(); $session->start(); echo $session->getId(); $request = Request::createFromGlobals(); $response = new Response(sprintf("Path info is %s. Base path is %s", $request->getPathInfo(), $request->getBasePath())); $response->send();
public function testGoodTokenFormSubmit() { // Start session manually. $session = new Session(new MockFileSessionStorage()); $session->start(); // Must use single shared client for continue session. $client = $this->createClient(); $crawler = $client->request('GET', '/oauth2/login'); $buttonCrawlerNode = $crawler->selectButton('submit'); $form = $buttonCrawlerNode->form(array('_username' => 'demousername3', '_password' => 'demopassword3')); $client->submit($form); $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient3.com/', 'redirect_uri' => 'http://democlient3.com/redirect_uri', 'scope' => 'demoscope1 demoscope2 demoscope3', 'state' => $session->getId()); $server = array(); $crawler = $client->request('GET', '/oauth2/authorize', $parameters, array(), $server); $this->assertTrue($client->getResponse()->isRedirect()); }