我正在尝试调用oauth API,此调用由我的主API在内部进行,
我创建了一个resttemplate类 -
@EnableOAuth2Client
@Configuration
public class MonkeyRestTemplate {
@Autowired
Environment env;
public OAuth2RestTemplate oauth2RestTemplate() {
ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(env.getRequiredProperty("monkey.api.accessToken.url"));
clientCredentialsResourceDetails.setClientId(env.getRequiredProperty("monkey.api.client.id"));
clientCredentialsResourceDetails.setClientSecret(env.getRequiredProperty("monkey.api.client.secret"));
return new OAuth2RestTemplate(clientCredentialsResourceDetails);
}
}
这是我的控制器类 -
@RestController
@RequestMapping("/monkeyinfo")
public class MonkeyApiService {
@Autowired
private MonkeyRestTemplate oauth2RestTemplate;
@Autowired
private Environment env;
@RequestMapping(value = "/oauth2", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, headers="Accept=application/json" )
public MonkeyMain getProducts(@RequestBody String holder) {
ResponseEntity<MonkeyMain> forEntity = oauth2RestTemplate.oauth2RestTemplate().getForEntity(env.getProperty("monkey.bananainfo.POST.uri"),
MonkeyMain.class);
System.out.println(forEntity.getBody());
return forEntity.getBody();
}
}
MonkeyMain.class
是我对Marshall / Unmarshall Json身体的主要模特课。
但是当调用此API时,我会收到403 forbidden
状态 -
Warning RequestContextHolder has a NULL RequestContext, therefore we are returning a NullRequestContext, therefore not all features may work as desired.
org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource
请指导。