我在同一个网站上有2个symfony项目,只是在apache上使用了别名。示例:
192.168.1.10/test1
192.168.1.10/test2
当我登录到test1时,我将登录到test2。这和注销是一样的。
下面是我的代码:App\Security\LoginFormAuthenticator
:
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator {
use TargetPathTrait;
public function __construct(private UrlGeneratorInterface $urlGenerator) {}
public function authenticate(Request $request): Passport {
// all logins checks
return new Passport(
new UserBadge($username, function () use ($username) {
return new MyUser($username);
}),
new CustomCredentials(function ($credentials, UserInterface $user) { return $user->getUserIdentifier() === $credentials; }, $username),
[
new RememberMeBadge() // pour le remember me
]
);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response {
return new RedirectResponse($this->urlGenerator->generate('index'));
}
protected function getLoginUrl(Request $request): string {
return $this->urlGenerator->generate("login"); // direction le login
}
}
App\Security\UserProvider
:
class UserProvider implements UserProviderInterface {
public function loadUserByIdentifier($name): UserInterface {
// never used
return new MyUser($name);
}
function refreshUser($user): UserInterface {
return $user;
}
function supportsClass(string $class): bool {
return true;
}
}
我的防火墙在security.yaml
:
security:
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
providers:
user_provider:
id: App\Security\UserProvider
firewalls:
main:
pattern: ^/
custom_authenticator: App\Security\LoginFormAuthenticator
entry_point: form_login
form_login:
login_path: login
check_path: login
remember_me:
secret: '%kernel.secret%' # required
lifetime: 604800
logout:
path: logout
remote_user:
provider: user_provider
Apache配置:
Alias /test<id> /dir/to/test<id>/public
<Directory /dir/to/test<id>/public>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
(note:为1或2,仅用于此处的示例)
如何防止两个别名的会话相同?
注意:test1
和test2
没有相同的环境变量。也许会有用
1条答案
按热度按时间epggiuax1#
您可以将会话的保存路径设置到框架配置中的不同位置