我试图获得Symfony2的我的安全的东西设置,我有它到目前为止的工作,但现在我需要做一些更花哨的东西.我目前正在使用处理PreAuthentication的所有内容(我使用第三方组件进行登录和会话管理).该部分与JMS安全捆绑包一起工作得很好.
现在我想要抓住投掷403s的用户,以便我可以将它们转发到我正在使用的第三方组件的登录页面.我认为我最好的办法是在异常监听器中添加一个异常处理程序.我正在查看AccessDeniedHandlerInterface.
编辑:我最后做了类似的事情.我创建了一个在kernel.exception事件上提示的服务.services.yml看起来像这样:
services:
kernel.listener.accessDenied:
class: Fully\Qualified\Namespace\Path\To\Class
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onAccessDeniedException }
Run Code Online (Sandbox Code Playgroud)
和它自己的课程:
<?php
namespace Fully\Qualified\Namespace\Path\To;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\Security\Core\Exception\AccessDeniedException;
class Class
{
public function onAccessDeniedException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
//Get the root cause of the exception.
while (null !== $exception->getPrevious()) {
$exception = $exception->getPrevious();
}
if ($exception instanceof AccessDeniedException) {
//Forward to third-party.
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试建立一个网页,我想在用户开始输入地址时使用谷歌建议的城市/州名称组合,它会自动完成城市和状态,就像谷歌地图一样.
如需参考,请访问以下URL:
当有人开始输入左上角的绿色A框时.它给你自动建议列表.
任何人都可以帮助我为我的网站做同样的事情吗?或者是否存在我可以使用的谷歌API?
谢谢