私はたとえばsymfonyの3に、私はドキュメントのようでしたHow to Load Security Users from the Databasesymfonyの3 - 認証
エンティティユーザーとスキーマデータベースの認証をやろうとしています。
public function indexAction(Request $request)
{
$session = $request->getSession();
$authenticationUtils = $this->get('security.authentication_utils');
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')){
return $this->redirect($this->generateUrl('admin_dashboard'));
}
return $this->render('default/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
'body_id' => "simple-page",
'last_username' => $lastUsername,
'error' => $error
]);
}
私はどのように与えるか: は私が_usernameを持っていると
コントローラーを_password、bcryptの、ログインフォームで平文
のsecurity.yml
security:
encoders:
AppBundle\Entity\User: plaintext
role_hierarchy:
ROLE_ADMIN: [ROLE_USER]
providers:
our_db_provider:
entity: { class: AppBundle:User, property: username }
firewalls:
main:
pattern: ^/
anonymous: ~
provider: our_db_provider
form_login:
login_path:/
check_path:/
logout:
path: /logout
target:/
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
をMD5で使用するパスワードを試してみましたログインに間違ったデータを取得する
exception 'Symfony\Component\Security\Core\Exception\BadCredentialsException' with message 'Bad credentials.'
私はそれを修正するので、私をadmin_dashboardにリダイレクトせず、エラーも返しません。デバッグ私はまだ匿名のままです
データベースで私はROLE_ADMINというロールを持っています。私たちはgetRolesでこれをUserエンティティに返しました。
どうしたのですか?
独自の認証システムを実装することができ、あなたは例外を持っていないのですか? – goto