【问题标题】:spring oauth error Full authentication is required to access this resourcespring oauth error 访问此资源需要完整的身份验证
【发布时间】:2018-01-07 16:16:52
【问题描述】:

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

请帮忙

【问题讨论】:

  • 假设您在同一问题上引用此post。了解您在配置中遗漏的内容可能会有所帮助。

标签: java spring spring-security spring-oauth2


【解决方案1】:

当您在项目中添加安全性时,请实施一些过滤器,例如 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();

}

【讨论】:

    猜你喜欢
    • 2018-08-14
    • 2016-11-11
    • 2016-07-21
    • 1970-01-01
    • 2016-10-03
    • 2015-04-15
    • 2015-01-08
    • 2018-09-11
    • 2019-01-01
    相关资源
    最近更新 更多