本文整理汇总了Java中org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider类的典型用法代码示例。如果您正苦于以下问题:Java ClientCredentialsAccessTokenProvider类的具体用法?Java ClientCredentialsAccessTokenProvider怎么用?Java ClientCredentialsAccessTokenProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientCredentialsAccessTokenProvider类属于org.springframework.security.oauth2.client.token.grant.client包,在下文中一共展示了ClientCredentialsAccessTokenProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MyOAuth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
public MyOAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
super(resource, context);
this.accessTokenProvider = new MyAccessTokenProviderChain(Arrays.asList(new AccessTokenProvider[]{new MyAuthorizationCodeAccessTokenProvider(),
new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(),
new ClientCredentialsAccessTokenProvider()}));
this.retryBadAccessTokens = true;
this.authenticator = new DefaultOAuth2RequestAuthenticator();
if(resource == null) {
throw new IllegalArgumentException("An OAuth2 resource must be supplied.");
} else {
this.resource = resource;
this.context = context;
this.setErrorHandler(new OAuth2ErrorHandler(resource));
}
}
示例2: testClientCredentialsRestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Test
public void testClientCredentialsRestTemplate() throws Exception {
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("4");
details.setClientId(client_id);
details.setClientSecret(client_secret);
details.setAccessTokenUri(access_token_uri);
// details.setScope(Arrays.asList("read write"));
OAuth2RestTemplate operations = new OAuth2RestTemplate(details,new DefaultOAuth2ClientContext());
// OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
operations.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
// OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails(),oAuth2ClientContext());
DefaultOAuth2AccessToken token=(DefaultOAuth2AccessToken)operations.getAccessToken();
token.setTokenType("Bearer");
System.out.println("client_id : " + client_id);
System.out.println("source_url : " + source_url);
// OAuth2RestOperations operations = restTemplate.clientCredentialsRestTemplate(client_id, client_secret, access_token_uri, scopes); // getForObject 发送 get 方法
System.out.println(JSON.toJSONString(operations.getForObject(source_url, JsonNode.class))); // getForObject 发送 get 方法
}
示例3: testConnectDirectlyToResourceServer
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Test
public void testConnectDirectlyToResourceServer() throws Exception {
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
resource.setClientId("my-client-with-registered-redirect");
resource.setId("sparklr");
resource.setScope(Arrays.asList("trust"));
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessToken));
String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/trusted/message"), String.class);
assertEquals("Hello, Trusted Client", result);
}
示例4: testInvalidCredentials
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Test
@OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false)
public void testInvalidCredentials() throws Exception {
context.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
responseHeaders = response.getHeaders();
responseStatus = response.getStatusCode();
}
};
}
});
try {
context.getAccessToken();
fail("Expected ResourceAccessException");
}
catch (Exception e) {
// ignore
}
// System.err.println(responseHeaders);
String header = responseHeaders.getFirst("WWW-Authenticate");
assertTrue("Wrong header: " + header, header.contains("Basic realm"));
assertEquals(HttpStatus.UNAUTHORIZED, responseStatus);
}
示例5: FeignOAuthInterceptor
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
public FeignOAuthInterceptor(OAuth2ClientContext oAuth2ClientContext) {
super(oAuth2ClientContext, null);
this.oAuth2ClientContext = oAuth2ClientContext;
this.accessTokenProvider = new AccessTokenProviderChain(Arrays.asList(new AuthorizationCodeAccessTokenProvider(),
new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(),
new ClientCredentialsAccessTokenProvider()));
}
示例6: loadBalancedOauth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@LoadBalanced
@Bean
public OAuth2RestTemplate loadBalancedOauth2RestTemplate(ClientCredentialsResourceDetails resource) {
ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(resource.getAccessTokenUri());
clientCredentialsResourceDetails.setClientId(resource.getClientId());
clientCredentialsResourceDetails.setClientSecret(resource.getClientSecret());
clientCredentialsResourceDetails.setClientAuthenticationScheme(resource.getClientAuthenticationScheme());
clientCredentialsResourceDetails.setScope(resource.getScope());
clientCredentialsResourceDetails.setGrantType(resource.getGrantType());
OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails);
auth2RestTemplate.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
return auth2RestTemplate;
}
示例7: loadBalancedOauth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@LoadBalanced
@Bean
public OAuth2RestTemplate loadBalancedOauth2RestTemplate(
ClientCredentialsResourceDetails resource) {
ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(resource.getAccessTokenUri());
clientCredentialsResourceDetails.setClientId(resource.getClientId());
clientCredentialsResourceDetails.setClientSecret(resource.getClientSecret());
clientCredentialsResourceDetails.setClientAuthenticationScheme(resource.getClientAuthenticationScheme());
clientCredentialsResourceDetails.setScope(resource.getScope());
clientCredentialsResourceDetails.setGrantType(resource.getGrantType());
OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails);
auth2RestTemplate.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
return auth2RestTemplate;
}
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:16,代码来源:LegacyEdgeApplication.java
示例8: clientRestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public OAuth2RestTemplate clientRestTemplate(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails clientCredentials) {
OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentials, oauth2ClientContext);
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
template.setAccessTokenProvider(provider);
return template;
}
示例9: ConfigDingus
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public Dingus ConfigDingus(ClientCredentialsResourceDetails resource,
ClientCredentialsAccessTokenProvider provider,
OAuth2AccessToken accessToken,
OAuth2RestTemplate template) {
Dingus dingus = new Dingus();
dingus.resource = resource;
dingus.provider = provider;
dingus.accessToken = accessToken;
dingus.template = template;
return dingus;
}
示例10: accessTokenProviderChain
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public AccessTokenProvider accessTokenProviderChain() {
return new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(
new OpenIDTokenProvider(),
new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()));
}
示例11: bookingClientCredentialClient
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public OAuth2RestOperations bookingClientCredentialClient() {
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setId("2");
resourceDetails.setClientId("Foosball Booking Read Client");
resourceDetails.setClientSecret("secret");
resourceDetails.setAccessTokenUri(ACCESS_TOKEN_URI);
OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
oAuth2RestTemplate.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
return oAuth2RestTemplate;
}
示例12: testInvalidCredentialsWithFormAuthentication
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Test
@OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false)
public void testInvalidCredentialsWithFormAuthentication() throws Exception {
resource.setClientAuthenticationScheme(AuthenticationScheme.form);
context.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
responseHeaders = response.getHeaders();
responseStatus = response.getStatusCode();
}
};
}
});
try {
context.getAccessToken();
fail("Expected ResourceAccessException");
}
catch (Exception e) {
// ignore
}
// System.err.println(responseHeaders);
String header = responseHeaders.getFirst("WWW-Authenticate");
assertTrue("Wrong header: " + header, header.contains("Form realm"));
assertEquals(HttpStatus.UNAUTHORIZED, responseStatus);
}
示例13: oauth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public OAuth2RestTemplate oauth2RestTemplate() {
OAuth2ProtectedResourceDetails resourceDetails = passwordResourceDetails();
OAuth2RestTemplate template = new OAuth2RestTemplate(resourceDetails,
oauth2ClientContext);
AccessTokenProviderChain provider = new AccessTokenProviderChain(
Arrays.asList(new ClientCredentialsAccessTokenProvider()));
provider.setClientTokenServices(clientTokenServices);
template.setAccessTokenProvider(provider);
return template;
}
示例14: ConfigOAuth2AccessToken
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public OAuth2AccessToken ConfigOAuth2AccessToken(ClientCredentialsAccessTokenProvider provider, ClientCredentialsResourceDetails resource) {
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
return accessToken;
}
示例15: ConfigClientCredentialsAccessTokenProvider
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public ClientCredentialsAccessTokenProvider ConfigClientCredentialsAccessTokenProvider() {
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
return provider;
}