/** * {@inheritdoc} */ public function decide(TokenInterface $token, array $attributes, $object = null) { $result = parent::decide($token, $attributes, $object); if (false === $result && true === $this->_tryBBTokenOnDenied && null !== $this->_application && null !== $this->_application->getBBUserToken()) { $result = parent::decide($this->_application->getBBUserToken(), $attributes, $object); } return $result; }
/** * @param \BackBee\Event\Event $event */ public function onPostLoad(Event $event) { $page = $event->getTarget(); if (!$page instanceof Page) { return; } $isBbSessionActive = $this->_application->getBBUserToken() === null; $page->setUseUrlRedirect($isBbSessionActive); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $startingTime = microtime(true); $this->bbapp = $this->getContainer()->get('bbapp'); $this->em = $this->bbapp->getEntityManager(); $this->output = $output; if ($input->getOption('verbose')) { $this->output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } else { $this->output->setVerbosity(OutputInterface::VERBOSITY_NORMAL); } $this->em->getConnection()->getConfiguration()->setSQLLogger(null); $this->aclProvider = $this->bbapp->getSecurityContext()->getACLProvider(); $this->entitiesFinder = new EntityFinder(dirname($this->bbapp->getBBDir())); $this->classContentManager = $this->bbapp->getContainer()->get('classcontent.manager')->setBBUserToken($this->bbapp->getBBUserToken()); if (null !== $input->getOption('memory-limit')) { ini_set('memory_limit', $input->getOption('memory-limit')); } $outputCmd = ''; $outputCmd .= $input->getOption('memory-limit') !== null ? ' --m=' . $input->getOption('memory-limit') : ''; $outputCmd .= $input->getOption('user_name') !== null ? ' --user_name=' . $input->getOption('user_name') : ''; $outputCmd .= $input->getOption('user_password') !== null ? ' --user_password='******'user_password') : ''; $outputCmd .= $input->getOption('user_email') !== null ? ' --user_email=' . $input->getOption('user_email') : ''; $outputCmd .= $input->getOption('user_firstname') !== null ? ' --user_firstname=' . $input->getOption('user_firstname') : ''; $outputCmd .= $input->getOption('user_lastname') !== null ? ' --user_lastname=' . $input->getOption('user_lastname') : ''; $outputCmd .= $input->getOption('user_group') !== null ? ' --user_group=' . $input->getOption('user_group') : ''; $outputCmd .= $input->getOption('verbose') ? ' --v' : ''; $this->writeln(sprintf('BEGIN : users:update_rights %s', $outputCmd), OutputInterface::VERBOSITY_NORMAL); // Récupère le fichier users_rights.yml $usersRights = $this->bbapp->getConfig()->getGroupsConfig(); if (null === $this->aclProvider) { throw new \InvalidArgumentException('None ACL provider found'); } // Vérifier que les groups de droit sont bien définis if (false === is_array($usersRights)) { throw new \InvalidArgumentException('Malformed groups.yml file, aborting'); } if ($this->checksBackBeeVersion()) { // Vérification et mise à jour de la structure de la table user $this->checksUserTable(); // Vérification et mise à jour de la structure de la table group (anciennement groups) $this->checksGroupTable(); } // Traitement de l'option clean if ($input->getOption('clean')) { $this->writeln("\n" . '<info>[Cleaning all tables]</info>' . "\n"); $this->cleanTables(); $this->writeln(sprintf('Cleaning done in %d s.', microtime(true) - $startingTime)); } $this->writeln("\n" . '<info>[Check ACL tables existence]</info>' . "\n"); $this->checkAclTables(); // Update des droits $this->writeln("\n" . '<info>[Updating users rights]</info>' . "\n"); $this->updateRights($usersRights); // Update des utilisateurs $this->writeln("\n" . '<info>[Updating/Creating user]</info>' . "\n"); $this->updateUsers($usersRights, $input); $this->writeln(sprintf('<info>Update done in %d s.</info>', microtime(true) - $startingTime), OutputInterface::VERBOSITY_NORMAL); }
/** * Handles the request when none other action was found. * * @access public * * @param string $uri The URI to handle * * @throws FrontControllerException */ public function defaultAction($uri = null, $sendResponse = true) { if (null === $this->application) { throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR); } if (false === $this->application->getContainer()->has('site')) { throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR); } $site = $this->application->getContainer()->get('site'); preg_match('/(.*)(\\.[' . $this->url_extension . ']+)/', $uri, $matches); if ('_root_' !== $uri && '/' !== $uri[strlen($uri) - 1] && 0 === count($matches) && true === $this->force_url_extension || 0 < count($matches) && true === isset($matches[2]) && $site->getDefaultExtension() !== $matches[2]) { throw new FrontControllerException(sprintf('The URL `%s` can not be found.', $this->getRouteCollection()->getUri($uri)), FrontControllerException::NOT_FOUND); } $uri = preg_replace('/(.*)\\.' . $this->url_extension . '?$/i', '$1', $uri); $redirect_page = null !== $this->application->getRequest()->get('bb5-redirect', null) ? 'false' !== $this->application->getRequest()->get('bb5-redirect') : true; if ('_root_' == $uri) { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site); } else { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates())); } if (null !== $page && false === $page->isOnline()) { $page = null === $this->application->getBBUserToken() ? null : $page; } if (null === $page) { throw new FrontControllerException(sprintf('The URL `%s` can not be found.', $this->request->getHost() . '/' . $uri), FrontControllerException::NOT_FOUND); } if (null !== ($redirect = $page->getRedirect()) && $page->getUseUrlRedirect()) { if (null === $this->application->getBBUserToken() || null !== $this->application->getBBUserToken() && true === $redirect_page) { $redirect = $this->application->getRenderer()->getUri($redirect); $response = new RedirectResponse($redirect, 301, ['Cache-Control' => 'no-store, no-cache, must-revalidate', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT']); $this->send($response); $this->application->stop(); } } try { $this->application->info(sprintf('Handling URL request `%s`.', $uri)); $event = new PageFilterEvent($this, $this->application->getRequest(), self::MASTER_REQUEST, $page); $this->application->getEventDispatcher()->dispatch('application.page', $event); if (null !== $this->getRequest()->get('bb5-mode')) { $response = new Response($this->application->getRenderer()->render($page, $this->getRequest()->get('bb5-mode'))); } else { $response = new Response($this->application->getRenderer()->render($page)); } if ($sendResponse) { $this->send($response); } else { return $response; } } catch (FrontControllerException $fe) { throw $fe; } catch (\Exception $e) { throw new FrontControllerException(sprintf('An error occured while rendering URL `%s`.', $this->request->getHost() . '/' . $uri), FrontControllerException::INTERNAL_ERROR, $e); } }
/** * Handles a media file request. * * @param string $filename The media file to provide * * @throws FrontControllerException * * @return Response */ public function mediaAction($type, $filename, $includePath = array()) { $includePath = array_merge($includePath, array($this->application->getStorageDir(), $this->application->getMediaDir())); if (null !== $this->application->getBBUserToken()) { $includePath[] = $this->application->getTemporaryDir(); } $matches = array(); if (preg_match('/([a-f0-9]{3})\\/([a-f0-9]{29})\\/(.*)\\.([^\\.]+)/', $filename, $matches)) { $filename = $matches[1] . '/' . $matches[2] . '.' . $matches[4]; } elseif (preg_match('/([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})\\/.*\\.([^\\.]+)/', $filename, $matches)) { $filename = $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5] . $matches[6] . $matches[7] . $matches[8] . '.' . $matches[9]; File::resolveMediapath($filename, null, array('include_path' => $includePath)); } File::resolveFilepath($filename, null, array('include_path' => $includePath)); $this->application->info(sprintf('Handling image URL `%s`.', $filename)); if (false === file_exists($filename) || false === is_readable($filename)) { $request = $this->application->getRequest(); throw new FrontControllerException(sprintf('The file `%s` can not be found (referer: %s).', $request->getHost() . '/' . $request->getPathInfo(), $request->server->get('HTTP_REFERER')), FrontControllerException::NOT_FOUND); } return $this->createMediaResponse($filename); }
/** * @see BackBee\Cache\Validator\ValidatorInterface::isValid */ public function isValid($object = null) { return false === $this->application->isDebugMode() && null === $this->application->getBBUserToken() && true === $this->application->isStarted() && false === $this->application->isClientSAPI(); }