我们在Spring Integration项目中使用Spring Security和Oauth2,我们在出站网关中使用这种方法。
默认情况下,每次发出请求时,Oaut2RestTemplate都会获得一个新令牌?
如果没有,我们如何管理刷新?
这是我们的代码:
<int-http:outbound-gateway id="aisleDataToOSPGateway"
request-channel="aisleDataToOSPChannel"
rest-template="oauth2RestTemplate"
url="${osp.aisle.rest.url}/{id}"
http-method="PUT"
expected-response-type="java.lang.String"
header-mapper="headerMapper"
reply-channel="ospRestAisleOutputChannel">
<int-http:uri-variable name="id" expression="headers['AISLE_ID']" />
</int-http:outbound-gateway>
@EnableOAuth2Client
@Configuration
public class RipOauth2Config {
@Bean
@ConfigurationProperties("security.oauth2.client")
public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
return new ClientCredentialsResourceDetails();
}
@Bean
@Primary
public OAuth2RestTemplate oauth2RestTemplate(ClientCredentialsResourceDetails clientCredentialsResourceDetails) {
OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentialsResourceDetails);
template.setRetryBadAccessTokens(true);
template.setErrorHandler(new OspResponseErrorHandler(clientCredentialsResourceDetails));
return template;
}
}