use of org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration in project spring-security-oauth by spring-projects.
the class AbstractResourceOwnerPasswordProviderTests method testTokenObtainedWithHeaderAuthentication.
@Test
@OAuth2ContextConfiguration(ResourceOwner.class)
public void testTokenObtainedWithHeaderAuthentication() throws Exception {
assertEquals(HttpStatus.OK, http.getStatusCode("/admin/beans"));
int expiry = context.getAccessToken().getExpiresIn();
assertTrue("Expiry not overridden in config: " + expiry, expiry < 1000);
assertEquals(new MediaType("application", "json", Charset.forName("UTF-8")), tokenEndpointResponse.getHeaders().getContentType());
}
use of org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testPostForTokenWithForm.
/**
* tests the basic provider with form based client credentials
*/
@Test
@OAuth2ContextConfiguration(FormClientCredentials.class)
public void testPostForTokenWithForm() throws Exception {
OAuth2AccessToken token = context.getAccessToken();
assertNull(token.getRefreshToken());
}
use of org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testInvalidCredentialsWithFormAuthentication.
@Test
@OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false)
public void testInvalidCredentialsWithFormAuthentication() throws Exception {
context.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
responseHeaders = response.getHeaders();
responseStatus = response.getStatusCode();
}
};
}
});
try {
context.getAccessToken();
fail("Expected ResourceAccessException");
} catch (Exception e) {
// ignore
}
// System.err.println(responseHeaders);
String header = responseHeaders.getFirst("WWW-Authenticate");
assertTrue("Wrong header: " + header, header.contains("Form realm"));
assertEquals(HttpStatus.UNAUTHORIZED, responseStatus);
}
use of org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration in project spring-security-oauth by spring-projects.
the class ResourceOwnerPasswordProviderTests method testCheckToken.
@Test
@OAuth2ContextConfiguration(ResourceOwner.class)
public void testCheckToken() throws Exception {
TestRestTemplate template = new TestRestTemplate("my-trusted-client", "");
ResponseEntity<String> response = template.getForEntity(http.getUrl("/oauth/check_token?token={token}"), String.class, context.getAccessToken().getValue());
assertEquals(HttpStatus.OK, response.getStatusCode());
}
use of org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration in project spring-security-oauth by spring-projects.
the class AbstractAuthorizationCodeProviderTests method testUnauthenticatedAuthorizationRespondsUnauthorized.
@Test
@OAuth2ContextConfiguration(resource = MyTrustedClient.class, initialize = false)
public void testUnauthenticatedAuthorizationRespondsUnauthorized() throws Exception {
AccessTokenRequest request = context.getAccessTokenRequest();
request.setCurrentUri("http://anywhere");
request.add(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
try {
String code = accessTokenProvider.obtainAuthorizationCode(context.getResource(), request);
assertNotNull(code);
fail("Expected UserRedirectRequiredException");
} catch (HttpClientErrorException e) {
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
}
}
Aggregations