在symfony security中立即禁用用户

在symfony security中立即禁用用户,symfony,symfony-security,Symfony,Symfony Security,AdvancedUserInterface实现已启用用户实体的方法。但用户属性存储在会话中。在重新登录之前,禁用用户不会起作用 因此,我需要按用户id清除特定的用户会话。 或者,我需要检查数据库以刷新序列化的用户数据 正确的方法是什么?我该怎么做?我在FOSUserBundle上也遇到了同样的问题,我会禁用一个用户,但如果他们登录,他们可以在现有会话下继续。禁用仅在他们尝试再次登录时生效 为了解决这个问题,我找到了一种不同的方法,使用。我创建了一个自定义投票者,每次调用“->isgrated”检

AdvancedUserInterface实现已启用用户实体的方法。但用户属性存储在会话中。在重新登录之前,禁用用户不会起作用

因此,我需要按用户id清除特定的用户会话。 或者,我需要检查数据库以刷新序列化的用户数据


正确的方法是什么?我该怎么做?

我在FOSUserBundle上也遇到了同样的问题,我会禁用一个用户,但如果他们登录,他们可以在现有会话下继续。禁用仅在他们尝试再次登录时生效

为了解决这个问题,我找到了一种不同的方法,使用。我创建了一个自定义投票者,每次调用“->isgrated”检查器时都会运行该投票者。我在每一页上检查不同角色级别的isgrated。然后,该投票者检查用户是否已启用,如果他们不是投票者,则投票失败并拒绝该用户,并将其返回登录屏幕

我的自定义投票者:

namespace AppBundle\Security;

use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
 * Purpose: A Voter that checks if the user is still enabled. Default FOSUserBundle behavior allows disabled users to
 *          continue under their existing session. This voter is designed to prevent that
 * Created by PhpStorm.
 * User: Matt Emerson
 * Date: 2/17/2018
 * Time: 1:24 PM
 */

class userVoter extends Voter
{
    protected function supports($attribute, $subject)
    {
        //this Voter is always available
        return true;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $user = $token->getUser();

        if (!$user instanceof User) {
            // the user must be logged in; if not, deny access
            return false;
        } elseif ($user->isEnabled() === false) {
            // the user is not enabled; deny access
            return false;
        }
        //otherwise return true
        return true;
    }
}

我在FOSUserBundle中也遇到了同样的问题,我会禁用一个用户,但如果他们登录,他们可以在现有会话下继续。禁用仅在他们尝试再次登录时生效

为了解决这个问题,我找到了一种不同的方法,使用。我创建了一个自定义投票者,每次调用“->isgrated”检查器时都会运行该投票者。我在每一页上检查不同角色级别的isgrated。然后,该投票者检查用户是否已启用,如果他们不是投票者,则投票失败并拒绝该用户,并将其返回登录屏幕

我的自定义投票者:

namespace AppBundle\Security;

use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
 * Purpose: A Voter that checks if the user is still enabled. Default FOSUserBundle behavior allows disabled users to
 *          continue under their existing session. This voter is designed to prevent that
 * Created by PhpStorm.
 * User: Matt Emerson
 * Date: 2/17/2018
 * Time: 1:24 PM
 */

class userVoter extends Voter
{
    protected function supports($attribute, $subject)
    {
        //this Voter is always available
        return true;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $user = $token->getUser();

        if (!$user instanceof User) {
            // the user must be logged in; if not, deny access
            return false;
        } elseif ($user->isEnabled() === false) {
            // the user is not enabled; deny access
            return false;
        }
        //otherwise return true
        return true;
    }
}

我有点怪了。当我用navicat更新数据库中的is_active字段并刷新页面时,我看到用户已注销。但我尝试了在navicat中持久禁用的用户实体是活动字段,但用户仍然登录。我想答案是,你可以检查一下,你可以解释更多你的问题,我有点奇怪。当我用navicat更新数据库中的is_active字段并刷新页面时,我看到用户已注销。但我尝试了在navicat中持久禁用用户实体为活动字段的外观更新,但用户仍然登录。我猜答案是这样的,您可以检查您是否可以解释更多问题