2016-11-15 4 views
0
$app->register(new SecurityServiceProvider(), array(
    'security.firewalls' => array(
     'admin' => array(
      'pattern' => '^/', 
      'form' => array(
       'login_path' => '/login', 
       'check_path' => '/login_check', 
       'always_use_default_target_path' => true, 
       'default_target_path' => '/profile' 
      ), 
      'logout' => true, 
      'anonymous' => true, 
      'users' => function() use ($app) { 
       return new \App\UserProvider($app['dbs']['mysql']); 
      }, 
     ), 
    ), 
'security.access_rules' => array(
    array('^/profile', 'ROLE_USER') 
) 
)); 

を設定したが、その後、リダイレクトで恐ろしい(私にとっては)ランタイムであるために、「ユーザーのためのユーザー・プロバイダがありません」例外はsymfony \コンポーネント\セキュリティ\コア\ユーザー\ユーザー "「ContextListener.phpライン74ユーザーのためのユーザー・プロバイダがありません"。サイレックスは、どのように私はlogin_checkのユーザーの資格情報を認証することができましたサイレックス2アプリケーションでは、セキュリティ

(私の '標準' ユーザープロバイダクラス)

class UserProvider implements UserProviderInterface { 
private $conn; 

public function __construct(Connection $conn) 
{ 
    $this->conn = $conn; 
} 
public function loadUserByUsername($username) 
{ 

    // $app['monolog']->addInfo(sprintf("User '%s' registered.", $username)); 

    $stmt = $this->conn->executeQuery('SELECT * FROM users_wet4 WHERE email = ?', array(strtolower($username))); 

    if (!$user = $stmt->fetch()) { 
     throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); 
    } 

    return new User($user['email'], $user['password'], explode(',', $user['roles']), true, true, true, true); 

} 
public function refreshUser(UserInterface $user) 
{ 
    if (!$user instanceof \App\Security\User) { 
     throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); 
    } 

    return $this->loadUserByUsername($user->getUsername()); 
} 
public function supportsClass($class) 
{ 
    return $class === 'Symfony\Component\Security\Core\User\User'; 
} 
} 

私は」この問題のすべてのインスタンスが検索されています。 symfonyのインストールには、カスタム・ユーザー・プロバイダを指すようにセキュリティを設定しているが、私は違った上記の方法よりもサイレックスのための任意の例を見ていない:

'users' => function() use ($app) { 
      return new \App\UserProvider($app['dbs']['mysql']); 
     }, 

(私はsymfonyのためのsecurity.xmlファイルでこれを見てきました、プロバイダの設定のこの種は何が欠けているのですか?)

providers: 
    main: 
     entity: { class: FredUtilisateurBundle:User, property: login } 

は、認証された後「ノーユーザープロバイダ」のロジックで私を助けることができる人はいますか?

if (!$user instanceof \App\Security\User) { 

ばかりされている必要がありますユーザー:

答えて

0

は、[OK]を問題は、実際にここにあった、それを解決しました。

if (!$user instanceof User) { 

または作成したカスタムユーザーのいずれかです。

\App\MyUser 
関連する問題