protected function _unauthorized(Controller $controller)
    {
        if ($this->_config['unauthorizedRedirect'] === false) {
            throw new ForbiddenException($this->_config['authError']);
        }

        $this->flash($this->_config['authError']);
        if ($this->_config['unauthorizedRedirect'] === true) {
            $default = '/';
            if (!empty($this->_config['loginRedirect'])) {
                $default = $this->_config['loginRedirect'];
            }
            if (is_array($default)) {
                $default['_base'] = false;
            }
            $url = $controller->referer($default, true);
        } else {
            $url = $this->_config['unauthorizedRedirect'];
        }

        return $controller->redirect($url);
    }
protected function _unauthorized(Controller $controller)
    {
        if ($this->_config['unauthorizedRedirect'] === false) {
            throw new ForbiddenException($this->_config['authError']);
        }

        $this->flash($this->_config['authError']);
        if ($this->_config['unauthorizedRedirect'] === true) {
            $default = '/';
            if (!empty($this->_config['loginRedirect'])) {
                $default = $this->_config['loginRedirect'];
            }
            if (is_array($default)) {
                $default['_base'] = false;
            }
            $url = $controller->referer($default, true);
        } else {
            $url = $this->_config['unauthorizedRedirect'];
        }

        return $controller->redirect($url);
    }
protected function _unauthorized ( Controller $ controller ) { if ( $ this -> _config [ 'unauthorizedRedirect' ] === false ) { throw new ForbiddenException ( $ this -> _config [ 'authError' ] ) ; } $ this -> flash ( $ this -> _config [ 'authError' ] ) ; if ( $ this -> _config [ 'unauthorizedRedirect' ] === true ) { $ default = '/' ; if ( ! empty ( $ this -> _config [ 'loginRedirect' ] ) ) { $ default = $ this -> _config [ 'loginRedirect' ] ; } if ( is_array ( $ default ) ) { $ default [ '_base' ] = false ; } $ url = $ controller -> referer ( $ default , true ) ; } else { $ url = $ this -> _config [ 'unauthorizedRedirect' ] ; } return $ controller -> redirect ( $ url ) ; }
Handle unauthorized access attempt

@param \Cake\Controller\Controller $controller A reference to the controller object
@return \Cake\Http\Response
@throws \Cake\Http\Exception\ForbiddenException
Handle unauthorized access attempt