2017-07-31 7 views
0

私たちのアプリケーションでは、アプリケーションを保護するためにスプリングセキュリティを使用しています。次に、oauthトークン検証用のspring oauthセキュリティをサポートするrestコントローラを追加しました。spring oauth errorこのリソースにアクセスするには完全な認証が必要です

を助けてください春のOAuthセキュリティを追加した後、私は春のセキュリティ

<oauth> 
<error_description> 
Full authentication is required to access this resource 
</error_description> 
<error>unauthorized</error> 
</oauth> 

を使用して私の他のコントローラのために、次のエラーを取得しています私のコントローラのコード

@RestController 
@EnableResourceServer 
public class Controller extends BaseRestController{ 



    @RequestMapping(value="/api/v1/public/insertData", method=RequestMethod.POST) 
    ResponseEntity<?> insertTPQueueData(TitleProcurementQueue queue,Authentication authentication) { 
     return null; 
    } 

} 

です

+0

は、あなたがこの[ポスト](https://stackoverflow.com/questions/26881296/spring-security-を参照してくださいと仮定しますoauth2-full-authentication-is-access-this-resource)を同じ問題で使用します。あなたの設定で見逃していることを理解すると役に立ちます。 –

答えて

0

セキュリティをプロジェクトに組み込むとき、Cors、基本認証などのフィルタを実装します。 したがって、リソースにセキュリティを適用する方法をSpringに伝える必要があります。 enter link description here

は@EnableWebSecurity を持つクラスを作成し、このように構成する必要があります。

protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeRequests() 
     .antMatchers("/h2-console/**").permitAll() 
     .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()   
     .anyRequest().authenticated() 
     .and() 
      .httpBasic() 
     .csrf().disable(); 

    http.headers().frameOptions().sameOrigin(); 

} 
関連する問題