两个文件夹中的Symfony2两个安装无意中共享用户

时间:2015-03-26 15:23:16

标签: php symfony

我有以下设置:

www.domain.com/application1 {单独的symfony安装& D B} www.domain.com/application2 {单独的symfony安装& DB}

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

我对这个问题感到不安,因为他们共享同一个主机,所以无法获得一个像样的工作解决方案,似乎在security.yml中使用Host限制是不可能的。

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时,它会失败。但登录后,他们可以看到两个应用程序。

2 个答案:

答案 0 :(得分:0)

自从我编写任何PHP(更不用说symfony)以来已经有一段时间了,但......

当我检查the docs always_authenticate_before_granting默认为false时,我注意到了。您可能希望在两个应用的security.yml的安全部分中将其更改为true

答案 1 :(得分:0)

如上所述,我最终解决了以下问题:

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;
}

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

感谢大家的时间和精力。