2011-09-22 20 views
7

我无法使身份验证正常工作,但它只会出现在非常特定的情况下。身份验证是通过第三方API完成的,因此我编写了自己的用户提供程序类,并且在该类内部有一些可以在API和Symfony之间同步数据的代码,作为该同步过程的一部分,它确定用户应具有哪些角色。 这样做后,它通过ManyToMany关系设置角色和用户之间的关系。在我的用户对象在Symfony2中无提示身份验证失败

的getRoles()方法获取角色对象从数据库中,并把它变成一个字符串数组,角色名称来自我的数据库,并全部以ROLE_。

如果我登录与应该有它工作正常,没有多余的角色,一个帐户,但如果我登录到一个帐户应该有角色我只是送回到登录屏幕,并没有错误消息。

我检查日志,看到这些项:

security.INFO: User "[email protected]" has been authenticated successfully [] [] 
event.DEBUG: Notified event "security.interactive_login" to listener "Pogo\MyBundle\Listener\LoginListener::onSecurityInteractivelogin". [] [] 
event.DEBUG: Listener "Symfony\Component\Security\Http\Firewall::onKernelRequest" stopped propagation of the event "kernel.request". [] [] 
event.DEBUG: Listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener" was not called for event "kernel.request". [] [] 
event.DEBUG: Listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener" was not called for event "kernel.request". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] [] 
security.DEBUG: Write SecurityContext in the session [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\SecurityBundle\EventListener\ResponseListener::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] [] 
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener::onEarlyKernelRequest". [] [] 
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] [] 
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] [] 
security.INFO: Populated SecurityContext with an anonymous Token [] [] 
event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException". [] [] 
security.DEBUG: Access denied (user is not fully authenticated); redirecting to authentication entry point [] [] 
security.DEBUG: Calling Authentication entry point [] [] 

我不明白它如何可以在顶部进行身份验证,然后尽快将检查它发现自己与一个匿名令牌防火墙这就是为什么它可能会让我回到登录屏幕。

我的防火墙/ ACCESS_CONTROL设置:

firewalls: 
    public: 
     pattern: /.* 
     anonymous: true 
     tessitura_login: 
      login_path: /account/login 
      check_path: /secure/login_check 
     logout: 
      path: /secure/logout 
      target:/
access_control: 
    - { path: ^/secure/.*, role: ROLE_USER } 
    - { path: ^/admin.*, role: ROLE_ADMIN } 
    - { path: ^/account/login/?, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY } 

任何帮助,这将大规模赞赏,我已经在这呆了几个小时,现在我彻底难倒。

+1

我不认为你找到了你的问题的答案? – Clint

+2

对不起,克林特,现在可能有点晚了,但事实证明,会议场太小了。该代码在会话中存储了相当多的Doctrine对象,这些对象不适合导致该错误的数据库字段 – pogo

回答

0

我也经历过同样的情况。当我的用户我日志检查什么角色,他有这样一对夫妇的语句:

if(true === $this->get('security.context')->isGranted('ROLE_MANAGER')){ 
    //return redirect 
} 
if(true === $this->get('security.context')->isGranted('ROLE_USER')){ 
    //return redirect 
} 
//throw error 

不时有人让用户在他们的脸上泛起了错误。我想这是因为同样的原因。用户不知何故被认证,但没有得到他们的角色。

我不能重现我自己的问题。我刚刚听到来自用户的错误报告。

0

我也经历过同样的情况。对我来说,那是因为在/ tmp分区已经客满,会议可以在服务器端存储和avter重定向到NEX

1

破碎的会话存储造成这对我来说。我正在使用PdoSessionHandler,令人失望的是它没有给出明确的错误或日志消息。

0

登录到我的系统时,其中会话配置存储在内存缓存,但memcached的没有运行我刚刚经历了同样的问题。如上所述,不幸的是它没有给出更好的错误信息。

希望帮助别人节省一些时间;-)

0

我曾与用户登录同样的问题我已经使用了索纳塔管理包,我还使用了与PdoSessionHandler

session.handler.pdo: 
    class:  Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler 
    arguments: ["@pdo", %pdo.db_options%] 
数据库会话

第一个问题我有,当我创建了一批具有很多的角色/权限在现场截断的数据,所以我改变我的角色与longtext场,改变了ROW_FORMAT=COMPRESSED

ALTER TABLE `fos_group` CHANGE `roles` `roles` LONGTEXT NOT NULL COMMENT '(DC2Type:array)'; 
ALTER TABLE `fos_group` 
    ENGINE=INNODB 
    ROW_FORMAT=COMPRESSED 
    KEY_BLOCK_SIZE=8; 

它的工作,并保存所有的角色/权限进入该领域的完整序列string.But用户无法与当时没有错误信息,我有审查的symfony生成的日志中app/logs目录有

登录

用户已经被认证成功的

,然后重定向到仪表板,但从仪表板作为

拒绝访问生成的日志(用户不是˚F ully认证)

的原因是会话数据被截断会话表,所以我改变我的会话表,以及和这个没有工作

ALTER TABLE `session` CHANGE `session_value` `session_value` LONGTEXT NOT NULL; 
ALTER TABLE `session` 
    ENGINE=INNODB 
    ROW_FORMAT=COMPRESSED 
    KEY_BLOCK_SIZE=8; 

我也更新my.ini文件,并改变了文件格式梭子鱼通过默认的文件格式是羚羊

[mysqld] 
innodb_file_per_table 
innodb_file_format = Barracuda 
2

得到时使用手机号码作为用户名和没有指定的用户名属性这场无声的故障问题方法,应该是:

public function refreshUser(UserInterface $customer) 
{ 
    $class = get_class($customer); 

    if(!$this->supportsClass($class)) { 
     throw new UnsupportedUserException("Instances of \"{$class}\" are not supported"); 
    } 

    return $this->loadUserByUsername($customer->getPhoneNumber()); // <-- This is it! 
} 

我想我不是唯一错过它的人,可能会有所帮助。