public function beforeMethod(RequestInterface $request, ResponseInterface $response)
    {
        if ($this->currentPrincipal) {
            // We already have authentication information. This means that the
            // event has already fired earlier, and is now likely fired for a
            // sub-request.
            //
            // We don't want to authenticate users twice, so we simply don't do
            // anything here. See Issue #700 for additional reasoning.
            //
            // This is not a perfect solution, but will be fixed once the
            // "currently authenticated principal" is information that's not
            // not associated with the plugin, but rather per-request.
            //
            // See issue #580 for more information about that.
            return;
        }

        $authResult = $this->check($request, $response);

        if ($authResult[0]) {
            // Auth was successful
            $this->currentPrincipal = $authResult[1];
            $this->loginFailedReasons = null;

            return;
        }

        // If we got here, it means that no authentication backend was
        // successful in authenticating the user.
        $this->currentPrincipal = null;
        $this->loginFailedReasons = $authResult[1];

        if ($this->autoRequireLogin) {
            $this->challenge($request, $response);
            throw new NotAuthenticated(implode(', ', $authResult[1]));
        }
    }
public function beforeMethod(RequestInterface $request, ResponseInterface $response)
    {
        if ($this->currentPrincipal) {
            // We already have authentication information. This means that the
            // event has already fired earlier, and is now likely fired for a
            // sub-request.
            //
            // We don't want to authenticate users twice, so we simply don't do
            // anything here. See Issue #700 for additional reasoning.
            //
            // This is not a perfect solution, but will be fixed once the
            // "currently authenticated principal" is information that's not
            // not associated with the plugin, but rather per-request.
            //
            // See issue #580 for more information about that.
            return;
        }

        $authResult = $this->check($request, $response);

        if ($authResult[0]) {
            // Auth was successful
            $this->currentPrincipal = $authResult[1];
            $this->loginFailedReasons = null;

            return;
        }

        // If we got here, it means that no authentication backend was
        // successful in authenticating the user.
        $this->currentPrincipal = null;
        $this->loginFailedReasons = $authResult[1];

        if ($this->autoRequireLogin) {
            $this->challenge($request, $response);
            throw new NotAuthenticated(implode(', ', $authResult[1]));
        }
    }
public function beforeMethod ( RequestInterface $ request , ResponseInterface $ response ) { if ( $ this -> currentPrincipal ) { // We already have authentication information. This means that the // event has already fired earlier, and is now likely fired for a // sub-request. // // We don't want to authenticate users twice, so we simply don't do // anything here. See Issue #700 for additional reasoning. // // This is not a perfect solution, but will be fixed once the // "currently authenticated principal" is information that's not // not associated with the plugin, but rather per-request. // // See issue #580 for more information about that. return ; } $ authResult = $ this -> check ( $ request , $ response ) ; if ( $ authResult [ 0 ] ) { // Auth was successful $ this -> currentPrincipal = $ authResult [ 1 ] ; $ this -> loginFailedReasons = null ; return ; } // If we got here, it means that no authentication backend was // successful in authenticating the user. $ this -> currentPrincipal = null ; $ this -> loginFailedReasons = $ authResult [ 1 ] ; if ( $ this -> autoRequireLogin ) { $ this -> challenge ( $ request , $ response ) ; throw new NotAuthenticated ( implode ( ', ' , $ authResult [ 1 ] ) ) ; } }
This method is called before any HTTP method and forces users to be authenticated.

@param RequestInterface  $request
@param ResponseInterface $response

@return bool
This method is called before any HTTP method and forces users to be authenticated .