Example usage for org.springframework.security.oauth2.client.token DefaultAccessTokenRequest setPreservedState

List of usage examples for org.springframework.security.oauth2.client.token DefaultAccessTokenRequest setPreservedState

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.token DefaultAccessTokenRequest setPreservedState.

Prototype

public void setPreservedState(Object state) 

Source Link

Usage

From source file:com.onedrive.api.OneDrive.java

public RestTemplate getRestTemplate() {
    if (restTemplate == null) {
        DefaultAccessTokenRequest accessTokenRequest = new DefaultAccessTokenRequest();
        accessTokenRequest.setAuthorizationCode(authorizationCode);
        accessTokenRequest.setPreservedState(new Object());
        accessTokenRequest.setExistingToken(getOAuth2AccessToken());
        restTemplate = new OAuth2RestTemplate(getResourceDetails(),
                new DefaultOAuth2ClientContext(accessTokenRequest));
        restTemplate.setErrorHandler(new OneDriveErrorHandler(restTemplate.getMessageConverters()));
        AccessTokenProviderChain provider = new AccessTokenProviderChain(
                Arrays.asList(new AuthorizationCodeAccessTokenProvider()));
        provider.setClientTokenServices(new InternalTokenServices(this));
        ((OAuth2RestTemplate) restTemplate).setAccessTokenProvider(provider);
        restTemplate.getMessageConverters().add(new MultipartRelatedHttpMessageConverter());
        for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
            if (mc instanceof MappingJackson2HttpMessageConverter) {
                objectMapper = ((MappingJackson2HttpMessageConverter) mc).getObjectMapper();
                objectMapper.setInjectableValues(new InjectableValues.Std().addValue(OneDrive.class, this));
                objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                SimpleModule module = new SimpleModule();
                module.addDeserializer(Date.class, new InternalDateDeserializer());
                objectMapper.registerModule(module);
            }//from  ww  w.  ja va2  s .co m
        }
    }
    return restTemplate;
}