Php 自定义身份验证成功处理程序
当用户登录到我的站点时,我尝试执行自定义操作/请求 我发现一个话题非常接近 我实施了适合我的配置和Silex v2的答案解决方案:Php 自定义身份验证成功处理程序,php,symfony,silex,Php,Symfony,Silex,当用户登录到我的站点时,我尝试执行自定义操作/请求 我发现一个话题非常接近 我实施了适合我的配置和Silex v2的答案解决方案: $app['security.authentication.success_handler.secured'] = function($app) { $handler = new Model\DefaultAuthenticationSuccessHandler( $app['security.http_utils'], $a
$app['security.authentication.success_handler.secured'] = function($app) {
$handler = new Model\DefaultAuthenticationSuccessHandler(
$app['security.http_utils'],
$app['security.firewalls']['secured']['form']
);
$handler->setProviderKey('secured');
return $handler;
};
$app['security.authentication.failure_handler.secured'] = function($app) {
return new Model\DefaultAuthenticationFailureHandler(
$app,
$app['security.http_utils'],
$app['security.firewalls']['secured']['form'],
$app['logger']
);
};
DefaultAuthenticationFailureHandler.php
namespace Model;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler as BaseDefaultAuthenticationFailureHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class DefaultAuthenticationFailureHandler extends BaseDefaultAuthenticationFailureHandler
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return parent::onAuthenticationFailure($request, $exception);
}
}
namespace Model;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler as BaseDefaultAuthenticationSuccessHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class DefaultAuthenticationSuccessHandler extends BaseDefaultAuthenticationSuccessHandler
{
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
return parent::onAuthenticationSuccess($request, $token);
}
}
DefaultAuthenticationSuccessHandler.php
namespace Model;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler as BaseDefaultAuthenticationFailureHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class DefaultAuthenticationFailureHandler extends BaseDefaultAuthenticationFailureHandler
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return parent::onAuthenticationFailure($request, $exception);
}
}
namespace Model;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler as BaseDefaultAuthenticationSuccessHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class DefaultAuthenticationSuccessHandler extends BaseDefaultAuthenticationSuccessHandler
{
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
return parent::onAuthenticationSuccess($request, $token);
}
}
但当我登录到该站点时,出现了一个错误:
ContextErrorException in DebugClassLoader.php line 194:
Warning: class_implements(): Class does not exist and could not be loaded
in DebugClassLoader.php line 194
at ErrorHandler->handleError('2', 'class_implements(): Class does not exist and could not be loaded', 'C:\xampp\htdocs\www\MY-Target\vendor\symfony\debug\DebugClassLoader.php', '194', array('class' => 'Symfony\Component\Security\Core\Exception\AuthenticationException', 'file' => 'C:\xampp\htdocs\www\MY-Target\vendor\composer/../symfony/security\Core\Exception\AuthenticationException.php', 'exists' => true, 'refl' => object(ReflectionClass), 'name' => 'Symfony\Component\Security\Core\Exception\AuthenticationException', 'notice' => array(), 'len' => '8', 'ns' => 'Symfony\', 'parent' => '', 'parentInterfaces' => array(), 'deprecatedInterfaces' => array()))
at class_implements('') in DebugClassLoader.php line 194
at DebugClassLoader->loadClass('Symfony\Component\Security\Core\Exception\AuthenticationException')
at spl_autoload_call('Symfony\Component\Security\Core\Exception\AuthenticationException') in BadCredentialsException.php line 20
at require_once('C:\xampp\htdocs\www\MY-Target\vendor\symfony\security\Core\Exception\BadCredentialsException.php') in DebugClassLoader.php line 142
at DebugClassLoader->loadClass('Symfony\Component\Security\Core\Exception\BadCredentialsException')
at spl_autoload_call('Symfony\Component\Security\Core\Exception\BadCredentialsException') in DaoAuthenticationProvider.php line 67
at DaoAuthenticationProvider->checkAuthentication(object(User), object(UsernamePasswordToken)) in UserAuthenticationProvider.php line 86
at UserAuthenticationProvider->authenticate(object(UsernamePasswordToken)) in AuthenticationProviderManager.php line 80
at AuthenticationProviderManager->authenticate(object(UsernamePasswordToken)) in UsernamePasswordFormAuthenticationListener.php line 93
at UsernamePasswordFormAuthenticationListener->attemptAuthentication(object(Request)) in AbstractAuthenticationListener.php line 146
at AbstractAuthenticationListener->handle(object(GetResponseEvent)) in Firewall.php line 69
at Firewall->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
at call_user_func(array(object(Firewall), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher)) in WrappedListener.php line 61
at WrappedListener->__invoke(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
at call_user_func(object(WrappedListener), object(GetResponseEvent), 'kernel.request', object(EventDispatcher)) in EventDispatcher.php line 174
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(GetResponseEvent)) in EventDispatcher.php line 43
at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in TraceableEventDispatcher.php line 136
at TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in HttpKernel.php line 129
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 496
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index_dev.php line 22
所以Silex似乎没有发现类AuthenticationException,但我不知道为什么。也许问题来自其他地方
谢谢你的帮助你能显示你的两个处理程序的代码吗?是的,我刚刚更新了我的帖子。你也能发布
composer show
的输出吗?你能显示你的两个处理程序的代码吗?是的,我刚刚更新了我的帖子。你也能发布composer show
的输出吗?