2017-07-31 67 views
0

我們的應用程序使用spring安全來保護應用程序,我剛添加了一個支持spring oauth安全性的rest控制器,用於oauth令牌驗證,將由其他一些應用程序調用是春天加入OAuth安全我使用彈簧安全得到下面的錯誤我的其他控制器後,我的控制器代碼spring oauth error訪問此資源需要完整身份驗證

@RestController 
@EnableResourceServer 
public class Controller extends BaseRestController{ 



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

} 

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

請幫助

+0

假設你參考這個[文章](https://stackoverflow.com/questions/26881296/spring-security- oauth2-full-authentication-is-required-to-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(); 

} 
相關問題