Search in sources :

Example 1 with OAuth2ClientContextFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter 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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectStrategy(org.springframework.security.web.RedirectStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) UserRedirectRequiredException(org.springframework.security.oauth2.client.resource.UserRedirectRequiredException)

Example 2 with OAuth2ClientContextFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter in project spring-security-oauth by spring-projects.

the class ClientConfigurationTests method testAuthCodeRedirect.

@Test
public void testAuthCodeRedirect() throws Exception {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(ClientContext.class);
    context.refresh();
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(new OAuth2ClientContextFilter()).build();
    mvc.perform(MockMvcRequestBuilders.get("/photos")).andExpect(MockMvcResultMatchers.status().isFound()).andExpect(MockMvcResultMatchers.header().string("Location", CoreMatchers.startsWith("http://example.com/authorize")));
    context.close();
}
Also used : OAuth2ClientContextFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 OAuth2ClientContextFilter (org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter)1 UserRedirectRequiredException (org.springframework.security.oauth2.client.resource.UserRedirectRequiredException)1 RedirectStrategy (org.springframework.security.web.RedirectStrategy)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1