Search in sources :

Example 36 with DefaultAccessTokenRequest

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

the class AccessTokenProviderChainTests method testSunnyDayWIthExpiredTokenAndValidRefreshToken.

@Test
public void testSunnyDayWIthExpiredTokenAndValidRefreshToken() throws Exception {
    AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
    accessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("EXP"));
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setExistingToken(accessToken);
    SecurityContextHolder.getContext().setAuthentication(user);
    OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
    assertNotNull(token);
}
Also used : DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)33 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)22 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)18 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)17 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)16 IOException (java.io.IOException)4 URI (java.net.URI)4 Date (java.util.Date)4 HttpMethod (org.springframework.http.HttpMethod)4 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)4 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)4 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)3 UserRedirectRequiredException (org.springframework.security.oauth2.client.resource.UserRedirectRequiredException)3 AuthorizationCodeResourceDetails (org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails)3 DefaultOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 HttpHeaders (org.springframework.http.HttpHeaders)2 DefaultOAuth2ClientContext (org.springframework.security.oauth2.client.DefaultOAuth2ClientContext)2 OAuth2ProtectedResourceDetails (org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails)2 ClientCredentialsResourceDetails (org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails)2