use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-boot by spring-projects.
the class UserInfoTokenServicesRefreshTokenTests method withRestTemplateChangesState.
@Test
public void withRestTemplateChangesState() {
OAuth2ProtectedResourceDetails resource = new AuthorizationCodeResourceDetails();
OAuth2ClientContext context = new DefaultOAuth2ClientContext();
context.setAccessToken(new DefaultOAuth2AccessToken("FOO"));
this.services.setRestTemplate(new OAuth2RestTemplate(resource, context));
assertThat(this.services.loadAuthentication("BAR").getName()).isEqualTo("me");
assertThat(context.getAccessToken().getValue()).isEqualTo("BAR");
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken 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.common.DefaultOAuth2AccessToken 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.DefaultOAuth2AccessToken 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));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class DefaultOAuth2RequestAuthenticatorTests method addsAccessToken.
@Test
public void addsAccessToken() {
context.setAccessToken(new DefaultOAuth2AccessToken("FOO"));
BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
authenticator.authenticate(resource, context, request);
String header = request.getHeaders().getFirst("Authorization");
assertEquals("bearer FOO", header);
}
Aggregations