public function addAuthenticationFactory(AuthenticationFactoryInterface $authFactory,
                                             UserProviderInterface $userProvider)
    {
        $id = $authFactory->getId();

        $this->authFactories[$id] = array(
            'factory' => $authFactory,
            'userProvider' => $userProvider,
        );

        $this->userProviders[] = $userProvider;

        if ($this->provider) {
            $this->registerAuthenticationFactory($this->provider->getApp(), $id, $authFactory, $userProvider);
        }

        return $this;
    }