2017-04-27 14 views
0

私はスプリングブートアプリケーションで春のセキュリティを使用しており、私が作ったカスタムログインページを使用することはできません。私はデフォルトで設定コントローラを使わずにカスタムログインページを使いたいのではなく、application.propertiesから設定を変更したい。また、ログインが成功するまで他のページへのアクセスを拒否したいと思います。アプリケーションからログアウトするのを手伝ってください。設定なしでカスタムログインページにスプリングブートセキュリティを使用する方法は?

+0

私は設定を持っていないと私は設定または構成のためのapplication.propertiesファイルを使用せずに、カスタムログインページを使用することを求めています。 –

答えて

1

「Spring Security Reference」では、カスタムログインページの実装方法についてextensive guideが提供されています。

は、私はあなたが与えられたダムのデータベースを作成する必要がthis repo

+0

WebSecurityConfigurerAdapterクラスをonにする必要がありますか? WebSecurityConfigurerAdapterクラスの代わりにapplication.propertiesを使用できませんか? –

+0

**これは私が知っている 'application.properties' **だけで達成する方法はありません**、私は疑いがあります。 私が提案したアプローチは、春のチームが推奨する方法です。 –

0

Spring Security With Customn login Page

カスタムログインページと春のセキュリティの例も実装されているsitemash +休止と共に提供される

で一緒に小さな例を置きますreadmeファイルに記載されています。

3

最後に

@RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String login(Model model, String error, String logout) { 
     if (error != null) 
      model.addAttribute("errorMsg", "Your username and password are invalid."); 

     if (logout != null) 
      model.addAttribute("msg", "You have been logged out successfully."); 

     return "login"; 
} 

春を変更/ログインのRequestMappingでカスタムログインページを返すGETメソッドを追加し、カスタムのlogin.jsp

コントローラーで
<form method="POST" action="${contextPath}/login" class="form-signin"> 
     <h2 class="form-heading">Log in</h2> 

     <div class="form-group ${error != null ? 'has-error' : ''}"> 
      <span>${msg}</span> 
      <input name="username" type="text" class="form-control" placeholder="Username" 
        autofocus="true"/> 
      <input name="password" type="password" class="form-control" placeholder="Password"/> 
      <span>${errorMsg}</span> 

      <button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button> 
     </div> 

    </form> 

次の定義上記の要求マッピングを指定するセキュリティ構成

詳細説明と作業ソースコードSpring Boot Security - Creating a custom Login Page

関連する問題