use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testAppendQueryParameter.
/**
* tests appendQueryParameter
*/
@Test
public void testAppendQueryParameter() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search?type=checkin"), token);
assertEquals("https://graph.facebook.com/search?type=checkin&bearer_token=12345", appended.toString());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testNewTokenAcquiredIfExpired.
@Test
public void testNewTokenAcquiredIfExpired() throws Exception {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
token.setExpiration(new Date(System.currentTimeMillis() - 1000));
restTemplate.getOAuth2ClientContext().setAccessToken(token);
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
OAuth2AccessToken newToken = restTemplate.getAccessToken();
assertNotNull(newToken);
assertTrue(!token.equals(newToken));
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken 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.common.OAuth2AccessToken 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.common.OAuth2AccessToken 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