use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeResourceDetailsTests method testGetOverrideRedirectUri.
@Test
public void testGetOverrideRedirectUri() {
details.setPreEstablishedRedirectUri("http://anywhere.com");
details.setUseCurrentUri(false);
DefaultAccessTokenRequest request = new DefaultAccessTokenRequest();
request.setCurrentUri("http://nowhere.com");
assertEquals("http://anywhere.com", details.getRedirectUri(request));
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeResourceDetailsTests method testGetDefaultRedirectUri.
@Test
public void testGetDefaultRedirectUri() {
details.setPreEstablishedRedirectUri("http://anywhere.com");
DefaultAccessTokenRequest request = new DefaultAccessTokenRequest();
request.setCurrentUri("http://nowhere.com");
assertEquals("http://nowhere.com", details.getRedirectUri(request));
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class ImplicitAccessTokenProviderTests method testRedirectNotSpecified.
@Test(expected = IllegalStateException.class)
public void testRedirectNotSpecified() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
provider.obtainAccessToken(resource, request);
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class OAuth2ContextSetup method initializeIfNecessary.
private void initializeIfNecessary(FrameworkMethod method, final Object target) {
final TestClass testClass = new TestClass(target.getClass());
OAuth2ContextConfiguration contextConfiguration = findOAuthContextConfiguration(method, testClass);
if (contextConfiguration == null) {
// Nothing to do
return;
}
this.initializeAccessToken = contextConfiguration.initialize();
this.resource = creatResource(target, contextConfiguration);
final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeOAuth2Context.class);
if (!befores.isEmpty()) {
logger.debug("Running @BeforeOAuth2Context methods");
for (FrameworkMethod before : befores) {
RestOperations savedServerClient = clientHolder.getRestTemplate();
OAuth2ContextConfiguration beforeConfiguration = findOAuthContextConfiguration(before, testClass);
if (beforeConfiguration != null) {
OAuth2ProtectedResourceDetails resource = creatResource(target, beforeConfiguration);
AccessTokenRequest beforeRequest = new DefaultAccessTokenRequest();
beforeRequest.setAll(parameters);
OAuth2RestTemplate client = createRestTemplate(resource, beforeRequest);
clientHolder.setRestTemplate(client);
}
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAll(parameters);
this.client = createRestTemplate(this.resource, request);
List<FrameworkMethod> list = Arrays.asList(before);
try {
new RunBefores(new Statement() {
public void evaluate() {
}
}, list, target).evaluate();
} catch (AssumptionViolatedException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (AssertionError e) {
throw e;
} catch (Throwable e) {
logger.debug("Exception in befores", e);
Assert.assertThat(e, CoreMatchers.not(CoreMatchers.anything()));
} finally {
clientHolder.setRestTemplate(savedServerClient);
}
}
}
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeGrantTests method testAttemptedTokenAcquisitionWithNoRedirect.
@Test
public void testAttemptedTokenAcquisitionWithNoRedirect() throws Exception {
AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
try {
OAuth2AccessToken token = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
fail("Expected UserRedirectRequiredException");
assertNotNull(token);
} catch (UserRedirectRequiredException e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.contains("A redirect is required"));
}
}
Aggregations