use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project spring-security-oauth by spring-projects.
the class AbstractClientCredentialsProviderTests method testInvalidCredentials.
@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) {
// System.err.println(responseHeaders);
// ignore
}
String header = responseHeaders.getFirst("WWW-Authenticate");
assertTrue("Wrong header: " + header, header.contains("Basic realm"));
assertEquals(HttpStatus.UNAUTHORIZED, responseStatus);
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider 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.token.grant.client.ClientCredentialsAccessTokenProvider in project perry by ca-cwds.
the class NoStateUserInfoRestTemplateCustomizerTest method testCustomize.
@Test
public void testCustomize() throws Exception {
NoStateUserInfoRestTemplateCustomizer noStateUserInfoRestTemplateCustomizer = new NoStateUserInfoRestTemplateCustomizer();
OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(new AuthorizationCodeResourceDetails());
noStateUserInfoRestTemplateCustomizer.customize(oAuth2RestTemplate);
AccessTokenProviderChain accessTokenProvider = getFieldValue(oAuth2RestTemplate, "accessTokenProvider", AccessTokenProviderChain.class);
assert accessTokenProvider != null;
List list = getFieldValue(accessTokenProvider, "chain", List.class);
assert list.size() == 4;
assert list.stream().anyMatch(o -> o instanceof ImplicitAccessTokenProvider);
assert list.stream().anyMatch(o -> o instanceof ResourceOwnerPasswordAccessTokenProvider);
assert list.stream().anyMatch(o -> o instanceof ClientCredentialsAccessTokenProvider);
assert list.stream().anyMatch(o -> o instanceof NoStateAuthorizationCodeTokenProvider);
NoStateAuthorizationCodeTokenProvider noStateAuthorizationCodeTokenProvider = (NoStateAuthorizationCodeTokenProvider) list.stream().filter(o -> o instanceof NoStateAuthorizationCodeTokenProvider).findFirst().get();
assert !getFieldValue(noStateAuthorizationCodeTokenProvider, "stateMandatory", Boolean.class);
List interceptors = getFieldValue(noStateAuthorizationCodeTokenProvider, "interceptors", List.class);
assert interceptors.size() == 1;
assert interceptors.stream().anyMatch(o -> o instanceof DebugRestTemplateInterceptor);
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project vorto by eclipse.
the class EidpUtils method accessTokenProvider.
public static AccessTokenProvider accessTokenProvider() {
AuthorizationCodeAccessTokenProvider authorizationCodeAccessTokenProvider = new AuthorizationCodeAccessTokenProvider();
ImplicitAccessTokenProvider implicitAccessTokenProvider = new ImplicitAccessTokenProvider();
return new AccessTokenProviderChain(Arrays.<AccessTokenProvider>asList(authorizationCodeAccessTokenProvider, implicitAccessTokenProvider, new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()));
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testInvalidCredentials.
@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);
}
Aggregations