
高度なセキュリティ
Custom authenticator、voter、security expression、CSRF 保護、XSS 防止、rate limiting、本番環境のハードニング、JWT/OAuth2 の設定ミス
1Symfony 6 以降で custom authenticator が実装しなければならないインターフェースはどれですか?
Symfony 6 以降で custom authenticator が実装しなければならないインターフェースはどれですか?
回答
Symfony 6 以降では、custom authenticator は Security HTTP コンポーネントの AuthenticatorInterface を実装する必要があります。このインターフェースは supports()、authenticate()、onAuthenticationSuccess()、onAuthenticationFailure() の各メソッドと、オプションで createToken() を定義します。これは Symfony 4/5 で使われていた古い Guard システムを置き換えるものです。
2custom authenticator における supports() メソッドの役割は何ですか?
custom authenticator における supports() メソッドの役割は何ですか?
回答
supports() メソッドは、その authenticator が現在のリクエストを処理すべきかどうかを判断します。Request を受け取り、ブール値を返します。true の場合、authenticate() メソッドが呼び出され、続いて onAuthenticationSuccess() または onAuthenticationFailure() が呼び出されます。これにより、同じ firewall 上で複数の authenticator を有効にし、それぞれが特定の認証タイプを処理できるようになります。
3custom authenticator の authenticate() メソッドは成功時に何を返すべきですか?
custom authenticator の authenticate() メソッドは成功時に何を返すべきですか?
回答
authenticate() メソッドは、UserBadge(ユーザー識別子)と credentials badge を含む Passport オブジェクトを返さなければなりません。Passport には CsrfTokenBadge や RememberMeBadge などの追加の badge を含めることもできます。Symfony はこの Passport を使って認証 token を作成し、UserProvider を介してユーザーを読み込みます。
特定のリソースへのアクセスを制御するためのカスタム Voter はどのように定義しますか?
厳格なセキュリティを必要とするアプリケーションには、どの AccessDecisionManager 戦略が推奨されますか?
+19 面接問題