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);
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project spring-security-oauth by spring-projects.
the class AbstractClientCredentialsProviderTests method createAccessTokenProvider.
@Override
protected AccessTokenProvider createAccessTokenProvider() {
return new ClientCredentialsAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
final ResponseErrorHandler delegate = super.getResponseErrorHandler();
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
responseHeaders = response.getHeaders();
responseStatus = response.getStatusCode();
delegate.handleError(response);
}
};
}
};
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project perry by ca-cwds.
the class NoStateUserInfoRestTemplateCustomizer method customize.
@Override
public void customize(OAuth2RestTemplate template) {
AuthorizationCodeAccessTokenProvider noStateAuthorizationCodeTokenProvider = new NoStateAuthorizationCodeTokenProvider();
noStateAuthorizationCodeTokenProvider.setInterceptors(Arrays.asList(new DebugRestTemplateInterceptor()));
noStateAuthorizationCodeTokenProvider.setStateMandatory(false);
template.setAccessTokenProvider(new AccessTokenProviderChain(Arrays.<AccessTokenProvider>asList(noStateAuthorizationCodeTokenProvider, new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())));
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider in project vorto by eclipse.
the class EidpUtils method proxiedAccessTokenProvider.
public static AccessTokenProvider proxiedAccessTokenProvider(String proxyHost, int proxyPort, String proxyUser, String proxyPassword) {
ClientHttpRequestFactory requestFactory = proxyAuthenticatedRequestFactory(proxyHost, proxyPort, proxyUser, proxyPassword);
AuthorizationCodeAccessTokenProvider authorizationCodeAccessTokenProvider = new AuthorizationCodeAccessTokenProvider();
authorizationCodeAccessTokenProvider.setRequestFactory(requestFactory);
ImplicitAccessTokenProvider implicitAccessTokenProvider = new ImplicitAccessTokenProvider();
implicitAccessTokenProvider.setRequestFactory(requestFactory);
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 testInvalidCredentialsWithFormAuthentication.
@Test
@OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false)
public void testInvalidCredentialsWithFormAuthentication() 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("Form realm"));
assertEquals(HttpStatus.UNAUTHORIZED, responseStatus);
}
Aggregations