我有以下设置:
www.domain.com/application1{separate symfony installation&DB}www.domain.com/application2{separate symfony installation&DB}
两个应用程序都有不同的用户,但是,如果user_id为1的用户登录到应用程序1,然后将URL更改为www.domain.com/application2,则如果应用程序2中存在具有相同id的有效用户,则允许他登录。
我对此感到困惑,无法找到一个像样的工作解决方案,因为它们共享同一个主机,似乎在安全方面使用了主机限制。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
这两个秘密不同,用户名和密码也不同。当尝试与应用程序1中的用户一起登录应用程序2时,它会失败。但一旦登录,他们就可以看到这两个应用程序。
我已经有一段时间没有写任何PHP了(更不用说symfony了),但是。。。
当我检查文档时,我注意到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;
}
如果需要这种情况,我将非常感谢对我的解决方案的评论。
感谢大家的时间和努力。