Symfony2 在两个文件夹中的两个安装意外地共享用户

Symfony2 two installations in two folders share users unwantingly

我有以下设置:

www.domain.com/application1 {单独的 symfony 安装和数据库} www.domain.com/application2 {单独的 symfony 安装和数据库}

两个应用程序都有不同的用户,但是如果 user_id 1 的用户登录到应用程序 1,然后将 URL 更改为 www.domain。com/application2 他被允许进入如果 application2 中存在具有相同 ID 的有效用户。

我对此很头疼,无法得到一个像样的工作解决方案,因为它们共享同一个主机,似乎在 security.yml 中使用主机限制是不可能的。

Security.yml 片段

firewalls:
    secured_area:
         pattern:   ^/
         anonymous: ~
         form_login:
             csrf_provider: form.csrf_provider
             login_path: login
             check_path: login_check
         logout:
             path:   /logout
             target: /

非常感谢任何指向正确方向的指示。

编辑 1
两个秘密不同,用户名和密码也不同。当尝试使用来自 application1 的用户登录 application2 时,它应该会失败。但是一旦登录,他们就可以看到这两个应用程序。

我已经有一段时间没有写任何东西了 PHP(更不用说 symfony 了),但是...

我在检查 the docs 时注意到 always_authenticate_before_granting 默认为 false。您可能希望在两个应用的 security.yml.

的安全部分将其更改为 true

正如上面的评论,我最终解决了如下问题:

Symfony 网站上为 refreshUser 建议的代码
Symfony Docs

public function refreshUser(UserInterface $user)
{
    $class = get_class($user);
    if (!$this->supportsClass($class)) {
        throw new UnsupportedUserException(
            sprintf(
                'Instances of "%s" are not supported.',
                $class
            )
        );
    }

    return $this->find($user->getId());
}

我要检查的不仅仅是 ID

public function refreshUser(UserInterface $user)
{
    $class = get_class($user);
    $refreshedUser = $this->find($user->getPersoonId());
    if (!$this->supportsClass($class)) {
        throw new UnsupportedUserException(
            sprintf(
                'Instances of "%s" are not supported.',
                $class
            )
        );
    }
    if($refreshedUser->getUsername()!=$user->getUsername()&&$refreshedUser->getPassword()!=$user->getPassword()){
        throw new UsernameNotFoundException('Unable to find user');
    }

    return $refreshedUser;
}

如果需要这种情况,我将不胜感激对我的解决方案的评论。

感谢大家的时间和努力。