use of org.springframework.security.oauth2.client.token.AccessTokenProviderChain in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method getTokenProvider.
private AccessTokenProviderChain getTokenProvider(DefaultOAuth2AccessToken accessToken, DefaultOAuth2AccessToken refreshedAccessToken) {
AccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
accessTokenProvider = spy(accessTokenProvider);
doReturn(accessToken).when(accessTokenProvider).obtainAccessToken(any(OAuth2ProtectedResourceDetails.class), any(AccessTokenRequest.class));
doReturn(refreshedAccessToken).when(accessTokenProvider).refreshAccessToken(any(OAuth2ProtectedResourceDetails.class), any(OAuth2RefreshToken.class), any(AccessTokenRequest.class));
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(accessTokenProvider));
return chain;
}
use of org.springframework.security.oauth2.client.token.AccessTokenProviderChain in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testSunnyDayClientCredentialsWithTokenServicesSave.
@Test
public void testSunnyDayClientCredentialsWithTokenServicesSave() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
chain.setClientTokenServices(clientTokenServices);
AccessTokenRequest request = new DefaultAccessTokenRequest();
resource = new ClientCredentialsResourceDetails();
resource.setId("resource");
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
Mockito.verify(clientTokenServices).saveAccessToken(resource, null, token);
}
use of org.springframework.security.oauth2.client.token.AccessTokenProviderChain in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testAnonymousUser.
@Test(expected = InsufficientAuthenticationException.class)
public void testAnonymousUser() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("foo", "bar", user.getAuthorities()));
AccessTokenRequest request = new DefaultAccessTokenRequest();
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
}
use of org.springframework.security.oauth2.client.token.AccessTokenProviderChain in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testSunnyDayWithExpiredTokenAndTokenServices.
@Test
public void testSunnyDayWithExpiredTokenAndTokenServices() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
chain.setClientTokenServices(clientTokenServices);
accessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
when(clientTokenServices.getAccessToken(resource, user)).thenReturn(accessToken);
AccessTokenRequest request = new DefaultAccessTokenRequest();
SecurityContextHolder.getContext().setAuthentication(user);
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
Mockito.verify(clientTokenServices).removeAccessToken(resource, user);
Mockito.verify(clientTokenServices).saveAccessToken(resource, user, token);
}
use of org.springframework.security.oauth2.client.token.AccessTokenProviderChain in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testSunnyDayWithTokenServicesSave.
@Test
public void testSunnyDayWithTokenServicesSave() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
chain.setClientTokenServices(clientTokenServices);
AccessTokenRequest request = new DefaultAccessTokenRequest();
SecurityContextHolder.getContext().setAuthentication(user);
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
Mockito.verify(clientTokenServices).saveAccessToken(resource, user, token);
}
Aggregations