Search in sources :

Example 6 with AccessTokenRequiredException

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());
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) AccessTokenRequiredException(org.springframework.security.oauth2.client.http.AccessTokenRequiredException) IOException(java.io.IOException) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 7 with AccessTokenRequiredException

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) AccessTokenRequiredException(org.springframework.security.oauth2.client.http.AccessTokenRequiredException) IOException(java.io.IOException) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) URI(java.net.URI) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 8 with AccessTokenRequiredException

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) {
    }
}
Also used : AccessTokenRequiredException(org.springframework.security.oauth2.client.http.AccessTokenRequiredException) Test(org.junit.Test)

Aggregations

AccessTokenRequiredException (org.springframework.security.oauth2.client.http.AccessTokenRequiredException)6 Test (org.junit.Test)3 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)3 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)3 IOException (java.io.IOException)2 URI (java.net.URI)2 HttpMethod (org.springframework.http.HttpMethod)2 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)2 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)2 OAuth2AccessDeniedException (org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException)2 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 HttpMessageConversionException (org.springframework.http.converter.HttpMessageConversionException)1 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 UserDeniedAuthorizationException (org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException)1