本文整理汇总了Java中org.springframework.security.oauth2.client.DefaultOAuth2ClientContext类的典型用法代码示例。如果您正苦于以下问题:Java DefaultOAuth2ClientContext类的具体用法?Java DefaultOAuth2ClientContext怎么用?Java DefaultOAuth2ClientContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultOAuth2ClientContext类属于org.springframework.security.oauth2.client包,在下文中一共展示了DefaultOAuth2ClientContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oauth2ClientContext
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:19,代码来源:OAuth2RestOperationsConfiguration.java
示例2: testClientCredentialsRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的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: getCustomerAccountServiceRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean(name = "customerAccountServiceRestTemplate")
public RestOperations getCustomerAccountServiceRestTemplate() {
LOGGER.info("getCustomerAccountServiceRestTemplate()");
AccessTokenRequest atr = new DefaultAccessTokenRequest();
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(getResourceDetails(), new DefaultOAuth2ClientContext(atr));
// Setting the interceptors to add YaaS specific http header properties
List<ClientHttpRequestInterceptor> listOfInterceptors = new ArrayList<>();
listOfInterceptors.add(new YaasRequestInterceptor());
listOfInterceptors.add(new DebugClientHttpRequestInterceptor());
restTemplate.setInterceptors(listOfInterceptors);
// Setting the response error handler for the rest template
restTemplate.setErrorHandler(new CustomerAccountResponseErrorHandler());
return restTemplate;
}
示例4: testOAuthService
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Test
public void testOAuthService() {
ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
resource.setUsername("guest");
resource.setPassword("guest123");
resource.setAccessTokenUri("http://localhost:8080/oauth/token");
resource.setClientId("trustedclient");
resource.setClientSecret("trustedclient123");
resource.setGrantType("password");
DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource, clientContext);
Greet greet = restTemplate.getForObject("http://localhost:8080", Greet.class);
Assert.assertEquals("Hello World!", greet.getMessage());
}
开发者ID:PacktPublishing,项目名称:Microservices-Building-Scalable-Software,代码行数:18,代码来源:ApplicationTests.java
示例5: testConnectDirectlyToResourceServer
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的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);
}
示例6: testConnectDirectlyToResourceServer
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Test
public void testConnectDirectlyToResourceServer() throws Exception {
assertNotNull(existingToken.getRefreshToken());
// It won't be expired on the server, but we can force the client to refresh it
assertTrue(existingToken.isExpired());
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setExistingToken(existingToken);
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(request));
String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/user/message"), String.class);
assertEquals("Hello, Trusted User marissa", result);
assertFalse("Tokens match so there was no refresh", existingToken.equals(template.getAccessToken()));
}
示例7: withRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Test
public void withRestTemplate() {
OAuth2ProtectedResourceDetails resource = new AuthorizationCodeResourceDetails();
OAuth2ClientContext context = new DefaultOAuth2ClientContext();
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
token.setRefreshToken(new DefaultExpiringOAuth2RefreshToken("BAR", new Date(0L)));
context.setAccessToken(token);
this.services.setRestTemplate(new OAuth2RestTemplate(resource, context));
assertThat(this.services.loadAuthentication("FOO").getName()).isEqualTo("me");
assertThat(context.getAccessToken().getValue()).isEqualTo("FOO");
// The refresh token is still intact
assertThat(context.getAccessToken().getRefreshToken())
.isEqualTo(token.getRefreshToken());
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:15,代码来源:UserInfoTokenServicesRefreshTokenTests.java
示例8: withRestTemplateChangesState
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Test
public void withRestTemplateChangesState() {
OAuth2ProtectedResourceDetails resource = new AuthorizationCodeResourceDetails();
OAuth2ClientContext context = new DefaultOAuth2ClientContext();
context.setAccessToken(new DefaultOAuth2AccessToken("FOO"));
this.services.setRestTemplate(new OAuth2RestTemplate(resource, context));
assertThat(this.services.loadAuthentication("BAR").getName()).isEqualTo("me");
assertThat(context.getAccessToken().getValue()).isEqualTo("BAR");
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:10,代码来源:UserInfoTokenServicesRefreshTokenTests.java
示例9: getOAuthTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
private OAuth2RestTemplate getOAuthTemplate() {
ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
resource.setUsername("user-name");
resource.setPassword("user-password");
resource.setAccessTokenUri(createURL("/oauth/token"));
resource.setClientId("clientId");
resource.setClientSecret("clientSecret");
resource.setGrantType("password");
OAuth2RestTemplate oauthTemplate = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext());
return oauthTemplate;
}
示例10: getOAuthTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
private OAuth2RestTemplate getOAuthTemplate() {
ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
resource.setUsername("user-name");
resource.setPassword("user-password");
resource.setAccessTokenUri(createUrl("/oauth/token"));
resource.setClientId("clientId");
resource.setClientSecret("clientSecret");
resource.setGrantType("password");
OAuth2RestTemplate oauthTemplate = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext());
return oauthTemplate;
}
示例11: ConfigOAuth2RestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
public OAuth2RestTemplate ConfigOAuth2RestTemplate(ClientCredentialsResourceDetails resource, OAuth2AccessToken accessToken, List<HttpMessageConverter<?>> messageConverters) {
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessToken));
template.setMessageConverters(messageConverters);
return template;
}
示例12: gatewayRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public OAuth2RestTemplate gatewayRestTemplate() {
OAuth2RestTemplate template =
new OAuth2RestTemplate(gatewayDetails(), new DefaultOAuth2ClientContext(accessTokenRequest));
template.setAccessTokenProvider(accessTokenProvider);
return template;
}
示例13: restTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
@Lazy
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestOperations restTemplate() {
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
resource.setClientId("client");
resource.setAccessTokenUri("http://example.com/token");
resource.setUserAuthorizationUri("http://example.com/authorize");
return new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessTokenRequest));
}
示例14: facebookRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestTemplate facebookRestTemplate() {
OAuth2RestTemplate template = new OAuth2RestTemplate(facebook(), new DefaultOAuth2ClientContext(
accessTokenRequest));
MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON,
MediaType.valueOf("text/javascript")));
template.setMessageConverters(Arrays.<HttpMessageConverter<?>> asList(converter));
return template;
}
示例15: xviaRestTemplate
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; //导入依赖的package包/类
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestTemplate xviaRestTemplate() {
OAuth2RestTemplate template = new OAuth2RestTemplate(xvia(), new DefaultOAuth2ClientContext(
accessTokenRequest));
// FormOAuth2AccessTokenMessageConverter converter = new FormOAuth2AccessTokenMessageConverter();
// template.setMessageConverters(Arrays.<HttpMessageConverter<?>> asList(converter));
return template;
}