use of org.springframework.security.oauth2.client.DefaultOAuth2ClientContext in project spring-boot by spring-projects.
the class UserInfoTokenServicesRefreshTokenTests method withRestTemplateChangesState.
@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");
}
use of org.springframework.security.oauth2.client.DefaultOAuth2ClientContext in project spring-security-oauth by spring-projects.
the class ClientCredentialsGrantTests method testConnectDirectlyToResourceServer.
@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);
}
use of org.springframework.security.oauth2.client.DefaultOAuth2ClientContext in project spring-security-oauth by spring-projects.
the class RefreshTokenGrantTests method testConnectDirectlyToResourceServer.
@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()));
}
use of org.springframework.security.oauth2.client.DefaultOAuth2ClientContext in project paascloud-master by paascloud.
the class OAuth2FeignAutoConfiguration method oAuth2RestTemplate.
/**
* O auth 2 rest template o auth 2 rest template.
*
* @return the o auth 2 rest template
*/
@Bean("paascloudOAuth2RestTemplate")
public OAuth2RestTemplate oAuth2RestTemplate() {
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails(), new DefaultOAuth2ClientContext());
oAuth2RestTemplate.setRequestFactory(new Netty4ClientHttpRequestFactory());
return oAuth2RestTemplate;
}
use of org.springframework.security.oauth2.client.DefaultOAuth2ClientContext in project spring-cloud-security by spring-cloud.
the class OAuth2FeignRequestInterceptorTests method tryToAcquireToken.
@Test(expected = OAuth2AccessDeniedException.class)
public void tryToAcquireToken() {
oAuth2FeignRequestInterceptor = new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), new BaseOAuth2ProtectedResourceDetails());
OAuth2AccessToken oAuth2AccessToken = oAuth2FeignRequestInterceptor.getToken();
Assert.assertTrue(oAuth2AccessToken.getValue() + " Must be null", oAuth2AccessToken.getValue() == null);
}
Aggregations