Webiny\Component\Security\Authentication\Firewall::processLogin PHP Method

processLogin() public method

Call this method on your login submit page, it will trigger the authentication provider and validate the provided credentials.
public processLogin ( string $authProvider = '' ) : boolean
$authProvider string Name of the auth provider you wish to use to process the login. If you don't set it, the first registered provider will be used.
return boolean True if login is valid, false if login has failed.
    public function processLogin($authProvider = '')
    {
        try {
            // if we are on login page, first try to get the instance of Login object from current auth provider
            $login = $this->getAuthProvider($authProvider)->getLoginObject($this->getConfig());
            if (!$this->isInstanceOf($login, 'Webiny\\Component\\Security\\Authentication\\Providers\\Login')) {
                throw new FirewallException('Authentication provider method getLoginObject() must return an instance of
														"Webiny\\Component\\Security\\Authentication\\Providers\\Login".');
            }
            $login->setAuthProviderName($this->authProviderName);
        } catch (\Exception $e) {
            throw new FirewallException($e->getMessage());
        }
        // forward the login object to user providers and validate the credentials
        $this->user = $this->authenticate($login);
        if (!$this->user) {
            // login failed
            $this->getAuthProvider($authProvider)->invalidLoginProvidedCallback();
            $this->eventManager()->fire(SecurityEvent::LOGIN_INVALID, new SecurityEvent(new AnonymousUser()));
            return false;
        } else {
            $this->getAuthProvider($authProvider)->loginSuccessfulCallback($this->user);
            $this->eventManager()->fire(SecurityEvent::LOGIN_VALID, new SecurityEvent($this->user));
            $this->setUserRoles();
            $this->userAuthenticated = true;
            return true;
        }
    }

Usage Example

Example #1
0
 /**
  * @param Firewall $firewall
  *
  * @dataProvider firewallProvider
  */
 public function testIsUserDeniedAccessOnAddressThatIsInsideAccessRules($firewall)
 {
     $firewall->processLogin('MockProvider');
     // let's authenticate the user
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/about/');
     $result = $firewall->isUserAllowedAccess();
     $this->assertFalse($result);
 }