use of org.springframework.security.oauth2.client.http.AccessTokenRequiredException in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testNoRetryAccessDeniedExceptionForNoExistingToken.
@Test(expected = AccessTokenRequiredException.class)
public void testNoRetryAccessDeniedExceptionForNoExistingToken() throws Exception {
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
throw new AccessTokenRequiredException(resource);
}
});
restTemplate.doExecute(new URI("http://foo"), HttpMethod.GET, new NullRequestCallback(), new SimpleResponseExtractor());
}
use of org.springframework.security.oauth2.client.http.AccessTokenRequiredException in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testRetryAccessDeniedException.
@Test
public void testRetryAccessDeniedException() throws Exception {
final AtomicBoolean failed = new AtomicBoolean(false);
restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken("TEST"));
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
if (!failed.get()) {
failed.set(true);
throw new AccessTokenRequiredException(resource);
}
return request;
}
});
Boolean result = restTemplate.doExecute(new URI("http://foo"), HttpMethod.GET, new NullRequestCallback(), new SimpleResponseExtractor());
assertTrue(result);
}
use of org.springframework.security.oauth2.client.http.AccessTokenRequiredException in project spring-security-oauth by spring-projects.
the class OAuth2ClientAuthenticationProcessingFilterTests method testUnsuccessfulAuthentication.
@Test
public void testUnsuccessfulAuthentication() throws IOException, ServletException {
try {
filter.unsuccessfulAuthentication(null, null, new AccessTokenRequiredException("testing", null));
fail("AccessTokenRedirectException must be thrown");
} catch (AccessTokenRequiredException ex) {
}
}
Aggregations