2017-05-13 6 views
0

AdvancedUserInterfaceの実装には、UserエンティティのisEnabledメソッドがあります。しかし、セッションに格納されているユーザープロパティ。再ログインするまでユーザーを無効にすることはできません。symfonyのセキュリティで即座にユーザを無効にする

だから私はユーザーIDで明確な特定のユーザーセッションが必要です。 または、シリアル化されたユーザーデータをリフレッシュするためのチェックデータベースが必要です。

私は正しい方法と方法は何ですか?

+0

奇妙行くI'ts。 Navicatでdbのis_activeフィールドを更新してページを更新すると、ユーザーがログアウトしているのがわかります。しかし、私は、無効になっているユーザーエンティティis_activeフィールドの外観をnavicatで更新しようとしましたが、ユーザーはまだログインしています。 – levye

+1

私は答えがこれだと思います、http://stackoverflow.com/a/27987723/2078929 –

+0

問題 – ghazi2008

答えて

0

私はFOSUserBundleと同じ問題を抱えていました。私はユーザーを無効にしますが、ログインしていれば既存のセッションで続行できます。ディセーブルは、再度ログインしようとしたときにのみ有効になりました。

これを回避するには、Security Voterを使用してこれを行う別の方法が見つかりました。私はあなたが " - > isGranted"チェッカーを呼び出すたびに実行されるカスタムの投票者を作成しました。私はさまざまなROLEレベルのすべてのページでisGrantedをチェックします。次に、この投票者は、ユーザがisEnabledかどうかをチェックします。投票者が投票に失敗して投票に失敗した場合、ユーザはログイン画面に戻ります。

マイカスタム投票者:

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; 
    } 
} 
関連する問題