spring oauth error访问此资源需要完全身份验证

时间:2017-07-31 23:52:04

标签: java spring spring-security spring-oauth2

我们的应用程序使用spring安全性来保护应用程序,我刚刚添加了一个支持spring oauth安全性的休息控制器,用于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;
    }

}

添加spring oauth安全性后,我的其他控制器使用spring security

会出现以下错误
<oauth>
<error_description>
Full authentication is required to access this resource
</error_description>
<error>unauthorized</error>
</oauth>

请帮忙

1 个答案:

答案 0 :(得分:0)

当您在项目中使用安全性时,可以实现一些过滤器,如Cors,basic auth等。 所以你需要告诉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();

}