public function authCheck(Event $event)
    {
        if ($this->_config['checkAuthIn'] !== $event->getName()) {
            return null;
        }

        /** @var \Cake\Controller\Controller $controller */
        $controller = $event->getSubject();

        $action = strtolower($controller->getRequest()->getParam('action'));
        if (!$controller->isAction($action)) {
            return null;
        }

        $this->_setDefaults();

        if ($this->_isAllowed($controller)) {
            return null;
        }

        $isLoginAction = $this->_isLoginAction($controller);

        if (!$this->_getUser()) {
            if ($isLoginAction) {
                return null;
            }
            $result = $this->_unauthenticated($controller);
            if ($result instanceof Response) {
                $event->stopPropagation();
            }

            return $result;
        }

        if ($isLoginAction ||
            empty($this->_config['authorize']) ||
            $this->isAuthorized($this->user())
        ) {
            return null;
        }

        $event->stopPropagation();

        return $this->_unauthorized($controller);
    }
public function authCheck(Event $event)
    {
        if ($this->_config['checkAuthIn'] !== $event->getName()) {
            return null;
        }

        /** @var \Cake\Controller\Controller $controller */
        $controller = $event->getSubject();

        $action = strtolower($controller->getRequest()->getParam('action'));
        if (!$controller->isAction($action)) {
            return null;
        }

        $this->_setDefaults();

        if ($this->_isAllowed($controller)) {
            return null;
        }

        $isLoginAction = $this->_isLoginAction($controller);

        if (!$this->_getUser()) {
            if ($isLoginAction) {
                return null;
            }
            $result = $this->_unauthenticated($controller);
            if ($result instanceof Response) {
                $event->stopPropagation();
            }

            return $result;
        }

        if ($isLoginAction ||
            empty($this->_config['authorize']) ||
            $this->isAuthorized($this->user())
        ) {
            return null;
        }

        $event->stopPropagation();

        return $this->_unauthorized($controller);
    }
public function authCheck ( Event $ event ) { if ( $ this -> _config [ 'checkAuthIn' ] !== $ event -> getName ( ) ) { return null ; } /** @var \Cake\Controller\Controller $controller */ $ controller = $ event -> getSubject ( ) ; $ action = strtolower ( $ controller -> getRequest ( ) -> getParam ( 'action' ) ) ; if ( ! $ controller -> isAction ( $ action ) ) { return null ; } $ this -> _setDefaults ( ) ; if ( $ this -> _isAllowed ( $ controller ) ) { return null ; } $ isLoginAction = $ this -> _isLoginAction ( $ controller ) ; if ( ! $ this -> _getUser ( ) ) { if ( $ isLoginAction ) { return null ; } $ result = $ this -> _unauthenticated ( $ controller ) ; if ( $ result instanceof Response ) { $ event -> stopPropagation ( ) ; } return $ result ; } if ( $ isLoginAction || empty ( $ this -> _config [ 'authorize' ] ) || $ this -> isAuthorized ( $ this -> user ( ) ) ) { return null ; } $ event -> stopPropagation ( ) ; return $ this -> _unauthorized ( $ controller ) ; }
Main execution method, handles initial authentication check and redirection
of invalid users.

The auth check is done when event name is same as the one configured in
`checkAuthIn` config.

@param \Cake\Event\Event $event Event instance.
@return \Cake\Http\Response|null
@throws \ReflectionException
Main execution method handles initial authentication check and redirection of invalid users .