0

I am learning Symfony2 and I love it!
I have been using the great book and cookbook, but I can't find an answer to my question anywhere.
I am using another 3rd party login API, but it is a little slow to respond, so I would like to store known users in my own DB for faster respond time.
I have managed to create my own database with an entity provider and it works.
Now I would like to have Symfony try a login with my other service, when a login fails.

This is where, I would find it logical to put my new code.

public function loadUserByUsername($username) {

    $q = $this
            ->createQueryBuilder('u')
            ->where('u.username = :username')
            ->setParameter('username', $username)
            ->getQuery();

    try {
        $user = $q->getSingleResult();
    } catch (NoResultException $e) {

        // Try login to other service before failing
        $login = $APIHelper->login($username, $password);

        if ($login) {
            // Make sure the user is persisted to database
            ...
            // Return the user
            return $login->getUser();
        }
        else {
            $message = sprintf(
                'Unable to find user SHSnaphackBundle:User object identified by "%s".', $username
            );
            throw new UsernameNotFoundException($message, 0, $e);
        }
    }

    return $user;
}

I would think, this would work perfectly, but can't find any way to get the password, the user tried to login with?

And is this the right file at all for this purpose?

4

1 回答 1

0

单独的实体提供者不是正确的地方,因为安全框架(正确的,实体提供者)会进行密码检查。对于高级安全内容,您必须了解安全系统的内部结构,尤其是身份验证部分。对于您的用例,您需要编写一个身份验证提供程序来完成您问题中发布的工作。

于 2013-07-04T23:26:56.053 回答