クラス FormLoginConfigurer<H extends HttpSecurityBuilder<H>>

実装されたすべてのインターフェース:
SecurityConfigurer<DefaultSecurityFilterChain,H>

フォームベースの認証を追加します。すべての属性には妥当なデフォルトがあり、すべてのパラメーターはオプションです。loginPage(String) が指定されていない場合、デフォルトのログインページがフレームワークによって生成されます。

セキュリティフィルター

次のフィルターが読み込まれます

作成された共有オブジェクト

次の共有オブジェクトが入力されます

使用される共有オブジェクト

次の共有オブジェクトが使用されます。
導入:
3.2
  • コンストラクターの詳細

    • FormLoginConfigurer

      public FormLoginConfigurer()
      新しいインスタンスを作成します
      関連事項:
  • メソッドの詳細

    • loginPage

      public FormLoginConfigurer<H> loginPage(StringSE loginPage)

      ログインが必要な場合にユーザーを送信する URL を指定します。EnableWebSecurity で使用すると、この属性が指定されていない場合にデフォルトのログインページが生成されます。

      URL が指定されている場合、またはこれが EnableWebSecurity と組み合わせて使用されていない場合、ユーザーは指定された URL を処理してログインページを生成する必要があります。一般に、ログインページは、UsernamePasswordAuthenticationFilter を使用するために、次の要件を備えたリクエストを送信するフォームを作成する必要があります。

      login.jsp の例

      上記のルールが守られている限り、選択したテクノロジーでログインページをレンダリングできます。以下は、JSP を使用する際のクイックスタートとして、または別のビューテクノロジーに変換するためのベースラインとして使用できる login.jsp の例です。
       
       <c:url value="/login" var="loginProcessingUrl"/>
       <form action="${loginProcessingUrl}" method="post">
          <fieldset>
              <legend>Please Login</legend>
              <!-- use param.error assuming FormLoginConfigurer#failureUrl contains the query parameter error -->
              <c:if test="${param.error != null}">
                  <div>
                      Failed to login.
                      <c:if test="${SPRING_SECURITY_LAST_EXCEPTION != null}">
                        Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
                      </c:if>
                  </div>
              </c:if>
              <!-- the configured LogoutConfigurer#logoutSuccessUrl is /login?logout and contains the query param logout -->
              <c:if test="${param.logout != null}">
                  <div>
                      You have been logged out.
                  </div>
              </c:if>
              <p>
              <label for="username">Username</label>
              <input type="text" id="username" name="username"/>
              </p>
              <p>
              <label for="password">Password</label>
              <input type="password" id="password" name="password"/>
              </p>
              <!-- if using RememberMeConfigurer make sure remember-me matches RememberMeConfigurer#rememberMeParameter -->
              <p>
              <label for="remember-me">Remember Me?</label>
              <input type="checkbox" id="remember-me" name="remember-me"/>
              </p>
              <div>
                  <button type="submit" class="btn">Log in</button>
              </div>
          </fieldset>
       </form>
       

      他のデフォルトへの影響

      この値を更新すると、他の多くのデフォルト値にも影響します。例: formLogin() のみが指定された場合のデフォルト値は次のとおりです。
      • /login GET - the login form
      • /login POST - process the credentials and if valid authenticate the user
      • /login?error GET - redirect here for failed authentication attempts
      • /login?logout GET - redirect here after successfully logging out
      "/authenticate" がこのメソッドに渡された場合、以下に示すようにデフォルトが更新されます。
      • /authenticate GET - the login form
      • /authenticate POST - process the credentials and if valid authenticate the user
      • /authenticate?error GET - redirect here for failed authentication attempts
      • /authenticate?logout GET - redirect here after successfully logging out
      オーバーライド:
      クラス AbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,FormLoginConfigurer<H extends HttpSecurityBuilder<H>>,UsernamePasswordAuthenticationFilter>loginPage 
      パラメーター:
      loginPage - 認証が必要な場合にリダイレクトするログインページ (つまり、"/login")
      戻り値:
      追加のカスタマイズのための FormLoginConfigurer
    • usernameParameter

      public FormLoginConfigurer<H> usernameParameter(StringSE usernameParameter)
      認証を実行するときにユーザー名を探す HTTP パラメーター。デフォルトは "username" です。
      パラメーター:
      usernameParameter - 認証を実行するときにユーザー名を探す HTTP パラメーター
      戻り値:
      追加のカスタマイズのための FormLoginConfigurer
    • passwordParameter

      public FormLoginConfigurer<H> passwordParameter(StringSE passwordParameter)
      認証を実行するときにパスワードを探す HTTP パラメーター。デフォルトは "password" です。
      パラメーター:
      passwordParameter - 認証を実行するときにパスワードを探す HTTP パラメーター
      戻り値:
      追加のカスタマイズのための FormLoginConfigurer
    • failureForwardUrl

      public FormLoginConfigurer<H> failureForwardUrl(StringSE forwardUrl)
      フォワード認証失敗ハンドラー
      パラメーター:
      forwardUrl - 失敗した場合のターゲット URL
      戻り値:
      追加のカスタマイズのための FormLoginConfigurer
    • successForwardUrl

      public FormLoginConfigurer<H> successForwardUrl(StringSE forwardUrl)
      フォワード認証成功ハンドラー
      パラメーター:
      forwardUrl - 成功した場合のターゲット URL
      戻り値:
      追加のカスタマイズのための FormLoginConfigurer
    • init

      public void init(H http) throws ExceptionSE
      インターフェースからコピーされた説明: SecurityConfigurer
      SecurityBuilder を初期化します。ここでは、共有状態のみを作成および変更する必要がありますが、オブジェクトの構築に使用される SecurityBuilder のプロパティは作成および変更しないでください。これにより、構築時に SecurityConfigurer.configure(SecurityBuilder) メソッドが正しい共有オブジェクトを使用するようになります。ここで設定を適用する必要があります。
      次で指定:
      インターフェース SecurityConfigurer<DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>init 
      オーバーライド:
      クラス AbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,FormLoginConfigurer<H extends HttpSecurityBuilder<H>>,UsernamePasswordAuthenticationFilter>init 
      例外:
      ExceptionSE
    • createLoginProcessingUrlMatcher

      protected RequestMatcher createLoginProcessingUrlMatcher(StringSE loginProcessingUrl)
      クラスからコピーされた説明: AbstractAuthenticationFilterConfigurer
      loginProcessingUrl を指定して RequestMatcher を作成します
      次で指定:
      クラス AbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,FormLoginConfigurer<H extends HttpSecurityBuilder<H>>,UsernamePasswordAuthenticationFilter>createLoginProcessingUrlMatcher 
      パラメーター:
      loginProcessingUrl - loginProcessingUrl に基づいて RequestMatcher を作成します
      戻り値:
      loginProcessingUrl に基づいて使用する RequestMatcher