问题:在我的登录控制器中,我确实获得了用户对象。但是当我去仪表板时,用户对象是空的。
SigninController
if ($this->isAuthUser($request)) {
$signinUser = $request->get('signin');
$token = new UsernamePasswordToken($signinUser, null, 'secured_area', $signinUser->getRoles());
$this->get("security.context")->setToken($token);
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
$session = $this->get('session');
$session->set('user', $signinUser->getUsername());
}
Security.yml
security:
providers:
in_memory:
memory: ~
access_control:
#- { path: ^/(signin|signup)?$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
firewalls:
secured_area:
pattern: ^/
anonymous: true
form_login:
login_path: /signin
check_path: _security_check
access_denied_url: signin
# logout:
# path: /signout
# #target: /
# invalidate_session: false
# delete_cookies:
# a: { path: null, domain: null }
# b: { path: null, domain: null }
# #handlers: [some.service.id, another.service.id]
# #success_handler: some.service.id
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
default:
anonymous: true
令牌对象:Signincontroller
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
[credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] =>
[providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
[user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Headset\Bundle\AccountsBundle\Entity\User Object
(
[email:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
[password:Headset\Bundle\AccountsBundle\Entity\User:private] => operator123#46
[oldPassword:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[id:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[userId:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[firstName:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[lastName:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[username:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
)
[roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
[0] => Symfony\Component\Security\Core\Role\Role Object
(
[role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
)
)
[authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
[attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
)
)
仪表板控制器
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
[credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] =>
[providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
[user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] =>
[roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
[0] => Symfony\Component\Security\Core\Role\Role Object
(
[role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
)
)
[authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
[attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
)
)
有人能弄明白是什么原因吗?
任何帮助都将受到高度赞赏......
答案 0 :(得分:0)
问题可能在于配置问题。根据用户提供商的一部分配置,您根本就没有任何用户。
security:
providers:
in_memory:
memory: ~
查看有关users loading
的symfony文档