use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JdbcClientTokenServicesTests method testSaveAndRetrieveToken.
@Test
public void testSaveAndRetrieveToken() throws Exception {
OAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("FOO");
Authentication authentication = new UsernamePasswordAuthenticationToken("marissa", "koala");
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
resource.setClientId("client");
resource.setScope(Arrays.asList("foo", "bar"));
tokenStore.saveAccessToken(resource, authentication, accessToken);
OAuth2AccessToken result = tokenStore.getAccessToken(resource, authentication);
assertEquals(accessToken, result);
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JdbcClientTokenServicesTests method testSaveAndRetrieveTokenForClientCredentials.
@Test
public void testSaveAndRetrieveTokenForClientCredentials() throws Exception {
OAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("FOO");
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
resource.setClientId("client");
resource.setScope(Arrays.asList("foo", "bar"));
tokenStore.saveAccessToken(resource, null, accessToken);
OAuth2AccessToken result = tokenStore.getAccessToken(resource, null);
assertEquals(accessToken, result);
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromForm.
@Test
public void testGetAccessTokenFromForm() throws Exception {
final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(responseHeaders, "access_token=FOO");
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
setUpRestTemplate();
assertEquals(token, provider.obtainAccessToken(resource, request));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testRefreshAccessTokenKeepingOldValue.
@Test
public void testRefreshAccessTokenKeepingOldValue() throws Exception {
DefaultOAuth2AccessToken accessToken = getExpiredToken();
DefaultOAuth2AccessToken refreshedAccessToken = new DefaultOAuth2AccessToken("refreshed-access-token");
refreshedAccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("other-refresh-token"));
AccessTokenProviderChain chain = getTokenProvider(accessToken, refreshedAccessToken);
SecurityContextHolder.getContext().setAuthentication(user);
// Obtain a new Access Token
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
AccessTokenRequest request = new DefaultAccessTokenRequest();
OAuth2AccessToken newAccessToken = chain.refreshAccessToken(resource, accessToken.getRefreshToken(), request);
// gh-816
assertEquals(newAccessToken.getRefreshToken(), refreshedAccessToken.getRefreshToken());
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method getExpiredToken.
private DefaultOAuth2AccessToken getExpiredToken() {
Calendar tokenExpiry = Calendar.getInstance();
DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("access-token");
accessToken.setExpiration(tokenExpiry.getTime());
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refresh-token"));
return accessToken;
}
Aggregations