2017-06-19 18 views
1

私はrest APIでintergrate Spring Securityを使用したいと思います。私は設定がすべてのルートをブロックするので問題があります。Spring Securityデフォルトのログインページを無効にする

マイ設定:

@Configuration 
@EnableResourceServer 
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter { 

    @Override 
    public void configure(HttpSecurity http) throws Exception { 
     http.csrf().disable(); 
     http.authorizeRequests() 
       .antMatchers("/").permitAll() 
       .antMatchers(HttpMethod.POST,"/api/getNews").hasRole("ADMIN"); 
    } 
} 

私はGET​​のスプリングリターンを望む

は、ログインフォーム

<html> 
    <head> 
     <title>Login Page</title> 
    </head> 
    <body onload='document.f.username.focus();'> 
     <h3>Login with Username and Password</h3> 
     <form name='f' action='/login' method='POST'> 
      <table> 
       <tr><td>User:</td><td><input type='text' name='username' value=''></td></tr> 
       <tr><td>Password:</td><td><input type='password' name='password'/></td></tr> 
       <tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr> 
       <input name="_csrf" type="hidden" value="5453a3c5-2573-4861-b777-d008b04863c3" /> 
      </table> 
     </form> 
    </body> 
</html> 

しかし、私は/を許可するためのルールを持っています。なぜ私のAPIにアクセスできないのですか?次のが見つかりました

+0

要求の取得 '.antMatchers(HttpMethod.GET、"/")。permitAll()' –

+0

これを使用していない可能性があります。 – lukassz

+0

'.antMatchers(HttpMethod.GET、"/* ")。permitAll()'? –

答えて

1

しかし、あなたが無効に匿名アクセスそれが動作しませんので、それはすべての認証されたユーザを意味permitAllを使用。

例を追加し、これが私の作品this

をお試しください:

http.csrf().disable() 
       .anonymous().authorities("ROLE_ANONYMOUS") 
       .and() 
       .authorizeRequests() 
       .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 
       .antMatchers(HttpMethod.GET, appConfigHolder.getSecurity().getLoginUrl()).permitAll() 

編集:

問題が春バージョンにありました。 v1.4.3.REALESEでは問題はありません。

+0

それでも同じ問題 – lukassz

+0

'web.ignoring()。antMatchers( "/")' –

+0

私はこのコードはコンパイルされませ編集した答え – lukassz

関連する問題