身份验证令牌kernel.request事件总是空的Symfony的2? [英] Authentication token always null in kernel.request event in Symfony 2?
问题描述
我特林写 kernel.request
事件基本听者的Symfony 2.服务定义为pretty简单的注解来自JMSDiExtraBundle。
存在的问题是, $上下文>为gettoken()
总是空即使用户被完全验证:
/ **
* @Service(request.set_messages_count_listener)
*
* /
类RequestListener
{ / **
* @var \\的Symfony \\分量\\ DependencyInjection \\ ContainerInterface
* /
私人$容器中; / **
* @InjectParams({容器= @注入(service_container)})
*
* /
公共职能__construct(ContainerInterface $容器)
{
$这个 - >集装箱= $容器中;
} / **
* @Observe(kernel.request,优先级= 255)
* /
公共职能onKernelRequest(GetResponseEvent $事件)
{
$环境= $这个 - >盛器>获取('security.context');
的var_dump($上下文>为gettoken());死();
}}
我觉得我的安全设置工作正常。可能是什么原因呢?
secured_area:
模式:^ /应用/
switch_user:真
form_login:
check_path:/应用/ login_check
login_path:/应用/登录
default_target_path:/应用/仪表板
always_use_default_target_path:真
登出:
路径:/演示/安全/注销#TODO
目标:/演示/#TODO访问控制:
- {路径:^ /应用/登录,角色:IS_AUTHENTICATED_ANONYMOUSLY}
- {路径:^ /应用/用户,角色:ROLE_MNG_USERS}
- {路径:^ /应用/信息,角色:ROLE_MNG_USERS}
- {路径:^ /应用/角色,角色:ROLE_MNG_PACKAGES_FEATURES}
- {路径:^ /应用/包,角色:ROLE_MNG_PACKAGES_FEATURES}
- {路径:^ /应用/,角色:ROLE_USER}
通过优先级= 255
,您的听众被称为安全防火墙之前(优先级= 8
,<一个href=\"https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml#L107\">look这里)。
尝试改变你的优先。
I'm tring to write a basic listener for kernel.request
event in Symfony 2. Service definition is pretty simple and annotations come from JMSDiExtraBundle.
The problems is that $context->getToken()
is always null even the user is fully authenticated:
/**
* @Service("request.set_messages_count_listener")
*
*/
class RequestListener
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
/**
* @InjectParams({"container" = @Inject("service_container")})
*
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* @Observe("kernel.request", priority = 255)
*/
public function onKernelRequest(GetResponseEvent $event)
{
$context = $this->container->get('security.context');
var_dump($context->getToken()); die();
}
}
I think my security setup is working fine. What could be the problem then?
secured_area:
pattern: ^/app/
switch_user: true
form_login:
check_path: /app/login_check
login_path: /app/login
default_target_path: /app/dashboard
always_use_default_target_path: true
logout:
path: /demo/secured/logout # TODO
target: /demo/ # TODO
access_control:
- { path: ^/app/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/app/users, roles: ROLE_MNG_USERS }
- { path: ^/app/messages, roles: ROLE_MNG_USERS }
- { path: ^/app/roles, roles: ROLE_MNG_PACKAGES_FEATURES }
- { path: ^/app/packages, roles: ROLE_MNG_PACKAGES_FEATURES }
- { path: ^/app/, roles: ROLE_USER }
With priority = 255
, your listener is called BEFORE the security firewall (priority = 8
, look here).
Try to change your priority.
这篇关于身份验证令牌kernel.request事件总是空的Symfony的2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!