use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testMissingSecurityContext.
@Test
public void testMissingSecurityContext() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
AccessTokenRequest request = new DefaultAccessTokenRequest();
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
// If there is no authentication to store it with a token is still acquired if
// possible
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testRefreshAccessTokenReplacingNullValue.
@Test
public void testRefreshAccessTokenReplacingNullValue() throws Exception {
DefaultOAuth2AccessToken accessToken = getExpiredToken();
DefaultOAuth2AccessToken refreshedAccessToken = new DefaultOAuth2AccessToken("refreshed-access-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-712
assertEquals(newAccessToken.getRefreshToken(), accessToken.getRefreshToken());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JaxbOAuth2AccessTokenMessageConverterTests method readAccessToken.
@Test
public void readAccessToken() throws IOException {
when(inputMessage.getBody()).thenReturn(createInputStream(OAUTH_ACCESSTOKEN));
OAuth2AccessToken token = converter.read(OAuth2AccessToken.class, inputMessage);
assertTokenEquals(accessToken, token);
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JaxbOAuth2AccessTokenMessageConverterTests method assertTokenEquals.
private static void assertTokenEquals(OAuth2AccessToken expected, OAuth2AccessToken actual) {
assertEquals(expected.getTokenType(), actual.getTokenType());
assertEquals(expected.getValue(), actual.getValue());
OAuth2RefreshToken expectedRefreshToken = expected.getRefreshToken();
if (expectedRefreshToken == null) {
assertNull(actual.getRefreshToken());
} else {
assertEquals(expectedRefreshToken.getValue(), actual.getRefreshToken().getValue());
}
assertEquals(expected.getScope(), actual.getScope());
Date expectedExpiration = expected.getExpiration();
if (expectedExpiration == null) {
assertNull(actual.getExpiration());
} else {
assertEquals(expectedExpiration.getTime(), actual.getExpiration().getTime());
}
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class TokenEndpointTests method testGetAccessTokenWithNoClientId.
@Test
public void testGetAccessTokenWithNoClientId() throws HttpRequestMethodNotSupportedException {
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth2Utils.GRANT_TYPE, "authorization_code");
OAuth2AccessToken expectedToken = new DefaultOAuth2AccessToken("FOO");
when(tokenGranter.grant(Mockito.eq("authorization_code"), Mockito.any(TokenRequest.class))).thenReturn(expectedToken);
@SuppressWarnings("unchecked") Map<String, String> anyMap = Mockito.any(Map.class);
when(authorizationRequestFactory.createTokenRequest(anyMap, Mockito.any(ClientDetails.class))).thenReturn(createFromParameters(parameters));
clientAuthentication = new UsernamePasswordAuthenticationToken(null, null, Collections.singleton(new SimpleGrantedAuthority("ROLE_CLIENT")));
ResponseEntity<OAuth2AccessToken> response = endpoint.postAccessToken(clientAuthentication, parameters);
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
OAuth2AccessToken body = response.getBody();
assertEquals(body, expectedToken);
assertTrue("Wrong body: " + body, body.getTokenType() != null);
}
Aggregations