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')
)
));
在Silex的2應用程序,我已經能夠驗證在login_check一個用戶的憑據,但隨後對重定向是可怕的(對我來說)運行例外「ContextListener.php行74沒有爲用戶沒有用戶提供 「的Symfony \分量\安全\核心\用戶\用戶」。Silex的「有用戶沒有用戶提供」如何配置安全
(我的 '標準' 用戶提供類)
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']);
},
(我在爲symfony1.2一個security.xml文件中看到了這一點,在這種配置提供的缺少什麼?)
providers:
main:
entity: { class: FredUtilisateurBundle:User, property: login }
是否有任何人誰可以幫我認證之後的「沒有用戶提供」的邏輯是什麼?