- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Symfony 从 2.8 升级到 3.4,并且我有一个身份验证监听器。
监听器的构造器
public function __construct(EntityManager $entityManager, SessionInterface $session, Security $security, LoggerInterface $logger, Redis $redis, $secret)
{
$this->entityManager = $entityManager;
$this->session = $session;
$this->security = $security;
$this->logger = $logger;
$this->redis = $redis;
$this->secret = $secret;
}
public function onRequest(GetResponseEvent $event)
{
//Validate token
//Get Authorization Header
$headers = $event->getRequest()->headers;
$authHeader = $headers->get('Authorization');
//Check if Header value starts with 'Bearer'
if($this->startsWith($authHeader, self::$BEARER_HEADER)) {
// Allow request to be processed by controllers
//token handler
} else {
$securityContext = $this->security;
if ($securityContext->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
return;
} else {
throw new SessionTimeoutException();
}
}
}
app.token_listener:
class: Insead\MIMBundle\Listener\AuthTokenListener
arguments: ["@doctrine.orm.entity_manager", "@session", "@security.helper", "@logger", "@redis.authtoken", "%secret%"]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 0 }
'access_control' => array(
array('path' => '^/api/(.*?)/login', 'role'=>'IS_AUTHENTICATED_ANONYMOUSLY'),
)
GENERAL EXCEPTION: The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. in
/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php line 55
Exception caught by Listener::
[
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Security.php",
"line": 65,
"function": "isGranted",
"class": "Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker",
"type": "->",
"args": [
"IS_AUTHENTICATED_ANONYMOUSLY",
null
]
},
{
"file": "/var/www/src/Insead/MIMBundle/Listener/AuthTokenListener.php",
"line": 135,
"function": "isGranted",
"class": "Symfony\\Component\\Security\\Core\\Security",
"type": "->",
"args": [
"IS_AUTHENTICATED_ANONYMOUSLY"
]
},
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
"line": 212,
"function": "onRequest",
"class": "Insead\\MIMBundle\\Listener\\AuthTokenListener",
"type": "->",
"args": [
null,
"kernel.request",
null
]
},
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
"line": 44,
"function": "doDispatch",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"args": [
[
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onRequest"
],
[
null,
"onController"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"configure"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onKernelRequest"
],
[
null,
"onRequest"
]
],
"kernel.request",
null
]
},
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
"line": 127,
"function": "dispatch",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"args": [
"kernel.request",
null
]
},
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
"line": 68,
"function": "handleRaw",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"args": [
{
"attributes": null,
"request": null,
"query": null,
"server": null,
"files": null,
"cookies": null,
"headers": null
},
1
]
},
{
"file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php",
"line": 200,
"function": "handle",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"args": [
{
"attributes": null,
"request": null,
"query": null,
"server": null,
"files": null,
"cookies": null,
"headers": null
},
1,
true
]
},
{
"file": "/var/www/web/app.php",
"line": 29,
"function": "handle",
"class": "Symfony\\Component\\HttpKernel\\Kernel",
"type": "->",
"args": [
{
"attributes": null,
"request": null,
"query": null,
"server": null,
"files": null,
"cookies": null,
"headers": null
}
]
}
]
最佳答案
我相信这是已被弃用/删除的安全上下文。 isGranted 需要在授权检查器上调用
return $this->get('security.authorization_checker');
// get the service from the container or pass it in via injection
$authChecker = $this->get('security.authorization_checker');
if ($authChecker->isGranted('IS...')) { ... }
关于php - Symfony 2.8 -> 3.4 升级 IsGranted ('IS_AUTHENTICATED_ANONYMOUSLY' ) 引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56338792/
假设有某些路由字符串,例如受防火墙保护的“/path/index.html”,如何检查当前用户是否能够访问它? 提前致谢! 对不起,我应该更明确一点:我有一个路由名称数组,我构建了一个菜单。许多具有不
我发现在 Symfony 中我可以使用注释以一种干净的方式向我的 Controller 方法添加额外的功能,这真的很方便。例如: /** * @Route("/{id}") * @IsGrante
任何人都可以解释以下 c# 行为吗?我已经编写了一个小型控制台应用程序来了解 CAS,但我似乎无法理解为什么以下代码行会像它们那样工作: string[] myRoles = new string[]
有时,我有一个页面,我想对不同规则的复杂组合使用react,这些规则总共只是一件事:“当前用户可以执行此操作吗?”。 目前,大多数检查都直接在我的 Controller 内进行,因此我可以: if($
在我的应用程序中测试角色时,我发现了 SecurityContext 的函数 isGranted。它工作得很好,但现在我需要检查不是当前用户的用户的角色,所以 isGranted 对我不起作用。 我一
我目前正在为我的应用程序创建单元测试,但这是我第一次这样做。 我想测试这个功能: /** * This method search if the user is already in a team
我正在开发一个 Symfony2 应用程序,我们想在其中引入 Security Voters . DX 计划(jay!)给我们带来了the simpler version这种机制,所以我想使用它。关于
我正在将 Symfony 从 2.8 升级到 3.4,并且我有一个身份验证监听器。 监听器的构造器 public function __construct(EntityManager $entit
我在 Symfony 2 项目中使用 SonataAdminBundle 和 SonataUserBundle。安装的包是: $ composer show | grep symfony friend
我是一名优秀的程序员,十分优秀!