ajax – symfony2 security – 禁用登录路径并显示禁止
我试图阻止重定向登录页面,当用户试图访问没有令牌的页面时,我有单页应用程序,我只在防火墙下放置ajax请求,当用户正在执行没有令牌的ajax时,我希望ajax返回禁止例外所以我将能够在客户端捕获它
目前,ajax返回“Found”,因为请求被重定向到登录页面 到目前为止我还没有在cookbook中找到解决方案我不想使用api令牌,只发送异常而不是重定向到登录 解决方法
您需要为防火墙定义一个entry_point,以便您返回未经授权的响应.有关入口点的信息可以在文档
here中找到.我将复制段落,以备将来请求时使用.
因此,为了让您这样做,您必须创建一个将被定义为服务的类. 它应该如下所示: namespace MyBundleService; use SymfonyComponentHttpFoundationRequest; use SymfonyComponentHttpFoundationResponse; use SymfonyComponentSecurityHttpEntryPointAuthenticationEntryPointInterface; use SymfonyComponentSecurityCoreExceptionAuthenticationException; class CustomEntryPoint implements AuthenticationEntryPointInterface { public function start(Request $request,AuthenticationException $authException = null) { $response = new Response("",Response::HTTP_UNAUTHORIZED); return $response; } } 并在您的services.yml文件中 services: service.entry_point: class: MyBundleServiceCustomEntryPoint 最后将服务ID service.entry_point传递给security.yml文件的防火墙部分中的entry_point选项. 这应该可以解决问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |