Example #1
0
 /**
  *
  * @Flow\Around("methodAnnotatedWith(Sandstorm\PhpProfiler\Annotations\Profile)")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return array Result of the target method
  */
 public function profileAround(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $run = \Sandstorm\PhpProfiler\Profiler::getInstance()->getRun();
     $tag = str_replace('\\', '_', $joinPoint->getClassName()) . ':' . $joinPoint->getMethodName();
     $run->startTimer($tag);
     $result = $joinPoint->getAdviceChain()->proceed($joinPoint);
     $run->stopTimer($tag);
     return $result;
 }
 /**
  * Returns a string message, giving insights what happened during privilege evaluation.
  *
  * @param string $privilegeReasonMessage
  * @return string
  */
 protected function renderDecisionReasonMessage($privilegeReasonMessage)
 {
     if (count($this->securityContext->getRoles()) === 0) {
         $rolesMessage = 'No authenticated roles';
     } else {
         $rolesMessage = 'Authenticated roles: ' . implode(', ', array_keys($this->securityContext->getRoles()));
     }
     return sprintf('Access denied for method' . chr(10) . 'Method: %s::%s()' . chr(10) . chr(10) . '%s' . chr(10) . chr(10) . '%s', $this->joinPoint->getClassName(), $this->joinPoint->getMethodName(), $privilegeReasonMessage, $rolesMessage);
 }
 /**
  * Invokes a given join point
  *
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
  * @return mixed
  */
 public function Flow_Aop_Proxy_invokeJoinPoint(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     if (__CLASS__ !== $joinPoint->getClassName()) {
         return parent::Flow_Aop_Proxy_invokeJoinPoint($joinPoint);
     }
     if (isset($this->Flow_Aop_Proxy_methodIsInAdviceMode[$joinPoint->getMethodName()])) {
         return call_user_func_array(['self', $joinPoint->getMethodName()], $joinPoint->getMethodArguments());
     }
 }
 /**
  * @Flow\Around("setting(Ttree.Embedly.logApiRequest) && within(Ttree\Embedly\Embedly) && method(public .*->(oembed|preview|objectify|extract|services)())")
  * @param JoinPointInterface $joinPoint The current join point
  * @return mixed
  */
 public function getResponseFromCache(JoinPointInterface $joinPoint)
 {
     $proxy = $joinPoint->getProxy();
     $key = ObjectAccess::getProperty($proxy, 'key');
     $params = $joinPoint->getMethodArgument('params');
     $cacheKey = md5($joinPoint->getClassName() . $joinPoint->getMethodName() . $key . json_encode($params));
     if ($this->responseCache->has($cacheKey)) {
         $this->systemLogger->log(sprintf('   cache hit Embedly::%s', $joinPoint->getMethodName()), LOG_DEBUG);
         return $this->responseCache->get($cacheKey);
     } else {
         $this->systemLogger->log(sprintf('   cache miss Embedly::%s', $joinPoint->getMethodName()), LOG_DEBUG);
     }
     $response = $joinPoint->getAdviceChain()->proceed($joinPoint);
     $this->responseCache->set($cacheKey, $response);
     return $response;
 }
 /**
  * Passes the signal over to the Dispatcher
  *
  * @Flow\AfterReturning("methodAnnotatedWith(TYPO3\Flow\Annotations\Signal)")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return void
  */
 public function forwardSignalToDispatcher(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $signalName = lcfirst(str_replace('emit', '', $joinPoint->getMethodName()));
     $this->dispatcher->dispatch($joinPoint->getClassName(), $signalName, $joinPoint->getMethodArguments());
 }
 /**
  * Logs calls and results of the authenticate() method of an authentication provider
  *
  * @Flow\AfterReturning("within(TYPO3\Flow\Security\Authentication\AuthenticationProviderInterface) && method(.*->authenticate())")
  * @param JoinPointInterface $joinPoint The current joinpoint
  * @return mixed The result of the target method if it has not been intercepted
  */
 public function logPersistedUsernamePasswordProviderAuthenticate(JoinPointInterface $joinPoint)
 {
     $token = $joinPoint->getMethodArgument('authenticationToken');
     switch ($token->getAuthenticationStatus()) {
         case TokenInterface::AUTHENTICATION_SUCCESSFUL:
             $this->securityLogger->log(sprintf('Successfully authenticated token: %s', $token), LOG_NOTICE, array(), 'TYPO3.Flow', $joinPoint->getClassName(), $joinPoint->getMethodName());
             $this->alreadyLoggedAuthenticateCall = true;
             break;
         case TokenInterface::WRONG_CREDENTIALS:
             $this->securityLogger->log(sprintf('Wrong credentials given for token: %s', $token), LOG_WARNING, array(), 'TYPO3.Flow', $joinPoint->getClassName(), $joinPoint->getMethodName());
             break;
         case TokenInterface::NO_CREDENTIALS_GIVEN:
             $this->securityLogger->log(sprintf('No credentials given or no account found for token: %s', $token), LOG_WARNING, array(), 'TYPO3.Flow', $joinPoint->getClassName(), $joinPoint->getMethodName());
             break;
     }
 }
 /**
  * Determines the short or full class name of the session implementation
  *
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
  * @return string
  */
 protected function getClassName(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $className = $joinPoint->getClassName();
     if (substr($className, 0, 18) === \TYPO3\Flow\Session::class) {
         $className = substr($className, 19);
     }
     return $className;
 }
 /**
  *
  * @Flow\After("filter(Debug\Toolbar\Aop\PointcutSettingsClassFilter)")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return array Result of the target method
  */
 public function profilerStop(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $run = \SandstormMedia\PhpProfiler\Profiler::getInstance()->getRun();
     $tag = $joinPoint->getClassName() . '::' . $joinPoint->getMethodName();
     $run->stopTimer($tag);
 }
 /**
  * Returns the privileges a specific role has for the given joinpoint. The returned array
  * contains the privilege's resource as key of each privilege.
  *
  * @param \TYPO3\Flow\Security\Policy\Role $role The role for which the privileges should be returned
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The joinpoint for which the privileges should be returned
  * @return array Array of privileges
  * @throws \TYPO3\Flow\Security\Exception\NoEntryInPolicyException
  */
 public function getPrivilegesForJoinPoint(\TYPO3\Flow\Security\Policy\Role $role, \TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $methodIdentifier = strtolower($joinPoint->getClassName() . '->' . $joinPoint->getMethodName());
     $roleIdentifier = $role->getIdentifier();
     if (!isset($this->acls[$methodIdentifier])) {
         throw new \TYPO3\Flow\Security\Exception\NoEntryInPolicyException('The given joinpoint was not found in the policy cache. Most likely you have to recreate the AOP proxy classes.', 1222100851);
     }
     if (!isset($this->acls[$methodIdentifier][$roleIdentifier])) {
         return array();
     }
     $privileges = array();
     foreach ($this->acls[$methodIdentifier][$roleIdentifier] as $resource => $privilegeConfiguration) {
         if ($privilegeConfiguration['runtimeEvaluationsClosureCode'] !== FALSE) {
             // Make object manager usable as closure variable
             $objectManager = $this->objectManager;
             eval('$runtimeEvaluator = ' . $privilegeConfiguration['runtimeEvaluationsClosureCode'] . ';');
             if ($runtimeEvaluator->__invoke($joinPoint) === FALSE) {
                 continue;
             }
         }
         $privileges[$resource] = $privilegeConfiguration['privilege'];
     }
     return $privileges;
 }