use of org.springframework.security.oauth2.client.resource.UserRedirectRequiredException in project spring-boot by spring-projects.
the class UserInfoTokenServicesTests method badToken.
@Test
public void badToken() {
this.services.setRestTemplate(this.template);
given(this.template.getForEntity(any(String.class), eq(Map.class))).willThrow(new UserRedirectRequiredException("foo:bar", Collections.<String, String>emptyMap()));
this.expected.expect(InvalidTokenException.class);
assertThat(this.services.loadAuthentication("FOO").getName()).isEqualTo("unknown");
}
use of org.springframework.security.oauth2.client.resource.UserRedirectRequiredException in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testRedirectToAuthorizationEndpoint.
@Test
public void testRedirectToAuthorizationEndpoint() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setCurrentUri("/come/back/soon");
resource.setUserAuthorizationUri("http://localhost/oauth/authorize");
try {
provider.obtainAccessToken(resource, request);
fail("Expected UserRedirectRequiredException");
} catch (UserRedirectRequiredException e) {
assertEquals("http://localhost/oauth/authorize", e.getRedirectUri());
assertEquals("/come/back/soon", e.getStateToPreserve());
}
}
use of org.springframework.security.oauth2.client.resource.UserRedirectRequiredException in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testTokenIsResetIfInvalid.
@Test
public void testTokenIsResetIfInvalid() throws Exception {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
token.setExpiration(new Date(System.currentTimeMillis() - 1000));
restTemplate.getOAuth2ClientContext().setAccessToken(token);
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider() {
@Override
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
throw new UserRedirectRequiredException("http://foo.com", Collections.<String, String>emptyMap());
}
});
try {
OAuth2AccessToken newToken = restTemplate.getAccessToken();
assertNotNull(newToken);
fail("Expected UserRedirectRequiredException");
} catch (UserRedirectRequiredException e) {
// planned
}
// context token should be reset as it clearly is invalid at this point
assertNull(restTemplate.getOAuth2ClientContext().getAccessToken());
}
use of org.springframework.security.oauth2.client.resource.UserRedirectRequiredException in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testRequiresAuthenticationButRedirected.
@Test(expected = UserRedirectRequiredException.class)
public void testRequiresAuthenticationButRedirected() throws Exception {
final AccessTokenRequest request = new DefaultAccessTokenRequest();
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider() {
@Override
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
throw new UserRedirectRequiredException("redirect test", request.toSingleValueMap());
}
}));
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
}
use of org.springframework.security.oauth2.client.resource.UserRedirectRequiredException in project spring-security-oauth by spring-projects.
the class OAuth2ClientContextFilterTests method testRedirectUri.
public void testRedirectUri(String redirect, Map<String, String> params, String result) throws Exception {
OAuth2ClientContextFilter filter = new OAuth2ClientContextFilter();
RedirectStrategy redirectStrategy = Mockito.mock(RedirectStrategy.class);
filter.setRedirectStrategy(redirectStrategy);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
UserRedirectRequiredException exception = new UserRedirectRequiredException(redirect, params);
filter.redirectUser(exception, request, response);
Mockito.verify(redirectStrategy).sendRedirect(request, response, result);
}
Aggregations