Search in sources :

Example 1 with ResourceOwnerPasswordAccessTokenProvider

use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider in project spring-security-oauth by spring-projects.

the class ResourceOwnerPasswordProviderTests method setupAccessTokenProvider.

@BeforeOAuth2Context
public void setupAccessTokenProvider() {
    ResourceOwnerPasswordAccessTokenProvider accessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider() {

        private ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();

        private ResponseErrorHandler errorHandler = super.getResponseErrorHandler();

        @Override
        protected ResponseErrorHandler getResponseErrorHandler() {
            return new DefaultResponseErrorHandler() {

                public void handleError(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    errorHandler.handleError(response);
                }
            };
        }

        @Override
        protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
            return new ResponseExtractor<OAuth2AccessToken>() {

                public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    return extractor.extractData(response);
                }
            };
        }
    };
    context.setAccessTokenProvider(accessTokenProvider);
}
Also used : DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ResponseExtractor(org.springframework.web.client.ResponseExtractor) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider) BeforeOAuth2Context(org.springframework.security.oauth2.client.test.BeforeOAuth2Context)

Example 2 with ResourceOwnerPasswordAccessTokenProvider

use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider in project spring-security-oauth by spring-projects.

the class AbstractResourceOwnerPasswordProviderTests method createAccessTokenProvider.

@Override
protected ResourceOwnerPasswordAccessTokenProvider createAccessTokenProvider() {
    ResourceOwnerPasswordAccessTokenProvider accessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider() {

        @Override
        protected ResponseErrorHandler getResponseErrorHandler() {
            final ResponseErrorHandler errorHandler = super.getResponseErrorHandler();
            return new DefaultResponseErrorHandler() {

                public void handleError(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    errorHandler.handleError(response);
                }
            };
        }

        @Override
        protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
            final ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();
            return new ResponseExtractor<OAuth2AccessToken>() {

                public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    return extractor.extractData(response);
                }
            };
        }
    };
    return accessTokenProvider;
}
Also used : DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ResponseExtractor(org.springframework.web.client.ResponseExtractor) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider)

Example 3 with ResourceOwnerPasswordAccessTokenProvider

use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider in project spring-security-oauth by spring-projects.

the class AbstractResourceOwnerPasswordProviderTests method setupAccessTokenProvider.

@BeforeOAuth2Context
public void setupAccessTokenProvider() {
    ResourceOwnerPasswordAccessTokenProvider accessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider() {

        @Override
        protected ResponseErrorHandler getResponseErrorHandler() {
            final ResponseErrorHandler errorHandler = super.getResponseErrorHandler();
            return new DefaultResponseErrorHandler() {

                public void handleError(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    errorHandler.handleError(response);
                }
            };
        }

        @Override
        protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
            final ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();
            return new ResponseExtractor<OAuth2AccessToken>() {

                public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
                    response.getHeaders();
                    response.getStatusCode();
                    tokenEndpointResponse = response;
                    return extractor.extractData(response);
                }
            };
        }
    };
    accessTokenProvider.setRequestFactory(context.getRestTemplate().getRequestFactory());
    context.setAccessTokenProvider(accessTokenProvider);
}
Also used : DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ResponseExtractor(org.springframework.web.client.ResponseExtractor) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider) BeforeOAuth2Context(org.springframework.security.oauth2.client.test.BeforeOAuth2Context)

Aggregations

ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)3 ResourceOwnerPasswordAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider)3 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)3 DefaultResponseErrorHandler (org.springframework.web.client.DefaultResponseErrorHandler)3 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)3 ResponseExtractor (org.springframework.web.client.ResponseExtractor)3 BeforeOAuth2Context (org.springframework.security.oauth2.client.test.BeforeOAuth2Context)2