2017-03-24 3 views
0

私はJEEプロジェクトで、Spring Bootフレームワークを使用しています。 認証のために、私はSpring Securityを使用し、テンプレート内のページを指定しました。 localhost:8080/INDEX.HTMLまたはI 2つの文字localhost/index.httmlを追加し、ページがauthantificationなしで表示さん:URLに大文字のスプリングセキュリティマッピング

protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeRequests() 
      .antMatchers("/login").permitAll() 
      .antMatchers("/token", "/index", "/index.html", "/main", "/main.html", "/main2", "/main2.html", "/recent1", "/recent1.html", "/recent2", "/recent2.html").hasRole("USER"); 

    http 
     .csrf() 
      .disable() 
     .formLogin() 
      .loginPage("/login") 
      .failureUrl("/login?error=true") 
      .defaultSuccessUrl("/index"); 

    http 
     .logout() 
      .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
      .logoutSuccessUrl("/login"); 
} 

問題は、私は、アプリケーションを実行し、私のような大文字とURLを書いたとき、ということです。

+0

このソリューションの.antMatchers( "/ login"、 "/ LOGIN")を使用できます。もう一つはこのようなものです。 –

答えて

-1

私が正しく理解していれば、ここでの目的のロジックは次のとおりです。

  1. /loginは、他のすべてのページが "で固定する必要が
  2. (何の役割は必須ではない)春のセキュリティで保護する必要はありません。 USER "の役割を果たす。

これを実装するには、次のことを試みることができる:

@Override 
public void configure(WebSecurity web) throws Exception { 
    // configuring here URLs for which security filters 
    // will be disabled (this is equivalent to using 
    // security="none") 
    web 
     .ignoring() 
      .antMatchers(
        "/login" 
      ) 
    ; 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests().anyRequest().hasRole("USER"); 

    http.csrf().disable().formLogin() 
      .loginPage("/login").failureUrl("/login?error=true") 
      .defaultSuccessUrl("/index"); 

    http.logout() 
      .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
      .logoutSuccessUrl("/login"); 
} 

だから、項目1(/login上の保障なし)configure(WebSecurity)に移動し、項目2は、元configure(HttpSecurity)に残されています。

+0

返信いただきありがとうございます。はい、すべてのページが保護されています。問題は、/ INDEX(大文字)を置くとログインが表示されず、認証なしで直接インデックスを呼び出すことです。 –

+0

設定では、すべてのページ( '/ index'、'/index.html'を含む)をリストし、それらのセキュリティ属性を設定します。しかし、あなたは '他のすべてのもの'の場合には属性を設定しません。 'INDEX.HTML'と' index.httml'は '/ index'マッチャーとマッチしませんので、セキュリティは適用されません。私の答えの 'anyRequest()'設定は、**すべてのURL **(ただし/ login)での認証を要求するSpring Securityに指示します。 –

関連する問題