src/EventListener/ApiAuthorizationSubscriber.php
public function authorize(ActionDispatchEvent $event)
    {
        $callable = $event->getCallable();

        if (!$callable->isMethod() && !$callable->isMethodStatic()) {
            // Native function or \Closure
            return;
        }

        $class = $callable->getReflection()->getDeclaringClass()->getName();
        $method = $callable->getReflection()->getName();
        $parameters = $event->getParameters();
        $action = $event->getAction();

        foreach ($action->getSecurityGroups() as $group) {
            $authorized = $this->authorizationChecker
                ->isGrantedMethodCall($class, $method, $parameters, [], $group);

            if (!$authorized) {
                throw new AccessDeniedException();
            }
        }
    }
public function authorize(ActionDispatchEvent $event)
    {
        $callable = $event->getCallable();

        if (!$callable->isMethod() && !$callable->isMethodStatic()) {
            // Native function or \Closure
            return;
        }

        $class = $callable->getReflection()->getDeclaringClass()->getName();
        $method = $callable->getReflection()->getName();
        $parameters = $event->getParameters();
        $action = $event->getAction();

        foreach ($action->getSecurityGroups() as $group) {
            $authorized = $this->authorizationChecker
                ->isGrantedMethodCall($class, $method, $parameters, [], $group);

            if (!$authorized) {
                throw new AccessDeniedException();
            }
        }
    }
public function authorize ( ActionDispatchEvent $ event ) { $ callable = $ event -> getCallable ( ) ; if ( ! $ callable -> isMethod ( ) && ! $ callable -> isMethodStatic ( ) ) { // Native function or \Closure return ; } $ class = $ callable -> getReflection ( ) -> getDeclaringClass ( ) -> getName ( ) ; $ method = $ callable -> getReflection ( ) -> getName ( ) ; $ parameters = $ event -> getParameters ( ) ; $ action = $ event -> getAction ( ) ; foreach ( $ action -> getSecurityGroups ( ) as $ group ) { $ authorized = $ this -> authorizationChecker -> isGrantedMethodCall ( $ class , $ method , $ parameters , [ ] , $ group ) ; if ( ! $ authorized ) { throw new AccessDeniedException ( ) ; } } }
Authorize and authenticate on API method

@param ActionDispatchEvent $event
Authorize and authenticate on API method