简体   繁体   中英

spring oauth error Full authentication is required to access this resource

Our application is using spring security to secure the application,i just added one rest controller which supporting spring oauth security, for oauth token validation, will be called by some other application following are my controller code

@RestController
@EnableResourceServer
public class Controller extends BaseRestController{



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

}

after adding spring oauth security i am getting following error for my other controller using spring security

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

Please help

When you put security in your project spring implement some filters, like Cors, basic auth etc.. So you need to tell spring how apply security in your resources. enter link description here

need to create a class with @EnableWebSecurity and configure like this:

    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();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM