use of org.springframework.security.oauth2.common.OAuth2AccessToken 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.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JdbcClientTokenServicesTests method testSaveAndRemoveToken.
@Test
public void testSaveAndRemoveToken() 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);
tokenStore.removeAccessToken(resource, authentication);
// System.err.println(new JdbcTemplate(db).queryForList("select * from oauth_client_token"));
OAuth2AccessToken result = tokenStore.getAccessToken(resource, authentication);
assertNull(result);
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2AccessTokenSupportTests method testRetrieveTokenFormEncoded.
@Test
public void testRetrieveTokenFormEncoded() throws Exception {
// SECOAUTH-306: no need to set message converters
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
response.setBody("access_token=FOO");
response.setHeaders(responseHeaders);
OAuth2AccessToken retrieveToken = support.retrieveToken(request, resource, form, requestHeaders);
assertEquals(accessToken, retrieveToken);
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2AccessTokenSupportTests method testRequestNotEnhanced.
@Test
public void testRequestNotEnhanced() throws Exception {
request.set("foo", "bar");
response.setBody(objectMapper.writeValueAsString(accessToken));
OAuth2AccessToken retrieveToken = support.retrieveToken(request, resource, form, requestHeaders);
assertEquals(null, form.get("foo"));
assertEquals(accessToken, retrieveToken);
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromJson.
@Test
public void testGetAccessTokenFromJson() throws Exception {
final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
resource.setAccessTokenUri("http://localhost/oauth/token");
request.setPreservedState(new Object());
setUpRestTemplate();
assertEquals(token, provider.obtainAccessToken(resource, request));
}
Aggregations