LoginSignup
0
0

More than 5 years have passed since last update.

Spring Securityを使いたい②

Posted at

認証処理

登録されたユーザーをどこかに登録しておいて、ログインで入力された値と照合する
データベースに登録でフォームで入力したい

認証処理のアーキテクチャ

1.SecurityFilterのAuthenticationFilterにユーザ名とパスワードが渡される
2.AuthenticationFilterはAuthenticationManagerインターフェースの認証メソッドを呼び出す
3.ProviderManager(AuthenticationManagerインターフェースの実装クラス)は認証処理をAuthenticationProviderインターフェイスの実装クラス(DaoAuthenticationProvider)に任せる

AuthenticationFilter

認証方式を決める人
今回はフォーム認証を選択したい

AuthenticationManager

AuthenticationFilterからの連絡を受ける電話機

ProviderManager

AuthenticationManagerを使う人
コールセンターみたいなもので、処理をAuthenticationProvederに伝える機関

AuthenticationProvider

ProvederManagerからの連絡を受ける電話機

DaoAuthenticationProvider

AuthenticationProviderから処理の連絡があれば処理を受ける

以下、フォーム認証の流れ

1.UsernamePasswordAuthenticationFilterがクライアントからリクエスト(ユーザ名、パスワード)を受け取る
2.UsernamePasswordAuthenticationFilterがAuthenticationManagerに認証処理を連絡する
3.AuthenticationManagerから連絡が返ってくる
4.UsernamePasswordAuthenticationFilterは成功・失敗で処理を振り分ける(成功時はAuthenticationSuccessHandler、失敗時はAuthenticationFailureHandlerへ)

xmlによるフォーム認証を使う設定
security-config.xml
<sec:http>
    中身
    <sec:form-login />
</sec:http>

この記述でフォーム認証が有効になる
※特に何も設定しなければ、"/login"にGETでアクセスするとデフォルトのログインページが表示されて、ログインボタンを押すと"/login"に対してPOSTでアクセスするようになっている

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0