本文整理汇总了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));
}
}
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:17,代码来源:MyOAuth2RestTemplate.java
示例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 方法
}
开发者ID:h819,项目名称:spring-boot,代码行数:25,代码来源:Oauth2ClientRestTemplateTest.java
示例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);
}
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:19,代码来源:ClientCredentialsGrantTests.java
示例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);
}
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:27,代码来源:ClientCredentialsProviderTests.java
示例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()));
}
开发者ID:rhawan,项目名称:microservices-tcc-alfa,代码行数:8,代码来源:FeignOAuthInterceptor.java
示例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;
}
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:15,代码来源:UserApplication.java
示例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;
}
开发者ID:trustedanalytics,项目名称:user-management,代码行数:8,代码来源:RestTemplatesConfiguration.java
示例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;
}
开发者ID:johnpfield,项目名称:oauth2-cli,代码行数:14,代码来源:ConfigDingusResources.java
示例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()));
}
开发者ID:pivotal-cf,项目名称:identity-sample-apps,代码行数:8,代码来源:Application.java
示例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;
}
开发者ID:KaiHofstetter,项目名称:foosball-booking-client,代码行数:13,代码来源:OAuth2RestTemplatesConfig.java
示例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);
}
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:28,代码来源:ClientCredentialsProviderTests.java
示例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;
}
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:17,代码来源:ClientConfiguration.java
示例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;
}
开发者ID:johnpfield,项目名称:oauth2-cli,代码行数:7,代码来源:ConfigRestResources.java
示例15: ConfigClientCredentialsAccessTokenProvider
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider; //导入依赖的package包/类
@Bean
public ClientCredentialsAccessTokenProvider ConfigClientCredentialsAccessTokenProvider() {
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
return provider;
}
开发者ID:johnpfield,项目名称:oauth2-cli,代码行数:8,代码来源:ConfigRestResources.java
注:本文中的org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论