@Override public void configure(H http) throws Exception { getAuthenticationFilter().setConsumer(getConsumer()); super.configure(http); }
@Test public void testFilterOperation() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setServletPath(REQUEST_PATH); req.setRequestURI(REQUEST_PATH); req.setServerPort(8080); MockHttpServletResponse response = new MockHttpServletResponse(); req.setParameter("openid_identifier", " " + CLAIMED_IDENTITY_URL); req.setRemoteHost("www.example.com"); filter.setConsumer(new MockOpenIDConsumer() { public String beginConsumption(HttpServletRequest req, String claimedIdentity, String returnToUrl, String realm) throws OpenIDConsumerException { assertThat(claimedIdentity).isEqualTo(CLAIMED_IDENTITY_URL); assertThat(returnToUrl).isEqualTo(DEFAULT_TARGET_URL); assertThat(realm).isEqualTo("http://localhost:8080/"); return REDIRECT_URL; } }); FilterChain fc = mock(FilterChain.class); filter.doFilter(req, response, fc); assertThat(response.getRedirectedUrl()).isEqualTo(REDIRECT_URL); // Filter chain shouldn't proceed verify(fc, never()).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class)); }
@Test public void requestWhenOpenIDAndRememberMeConfiguredThenRememberMePassedToIdp() throws Exception { this.spring.configLocations(this.xml("WithRememberMe")).autowire(); OpenIDAuthenticationFilter openIDFilter = getFilter(OpenIDAuthenticationFilter.class); String openIdEndpointUrl = "http://testopenid.com?openid.return_to="; Set<String> returnToUrlParameters = new HashSet<>(); returnToUrlParameters.add(AbstractRememberMeServices.DEFAULT_PARAMETER); openIDFilter.setReturnToUrlParameters(returnToUrlParameters); OpenIDConsumer consumer = mock(OpenIDConsumer.class); when(consumer.beginConsumption(any(HttpServletRequest.class), anyString(), anyString(), anyString())) .then(invocation -> openIdEndpointUrl + invocation.getArgument(2)); openIDFilter.setConsumer(consumer); String expectedReturnTo = new StringBuilder("http://localhost/login/openid").append("?") .append(AbstractRememberMeServices.DEFAULT_PARAMETER) .append("=").append("on").toString(); this.mvc.perform(get("/")) .andExpect(status().isFound()) .andExpect(redirectedUrl("http://localhost/login")); this.mvc.perform(get("/login")) .andExpect(status().isOk()) .andExpect(content().string(containsString(AbstractRememberMeServices.DEFAULT_PARAMETER))); this.mvc.perform(get("/login/openid") .param(OpenIDAuthenticationFilter.DEFAULT_CLAIMED_IDENTITY_FIELD, "http://hey.openid.com/") .param(AbstractRememberMeServices.DEFAULT_PARAMETER, "on")) .andExpect(status().isFound()) .andExpect(redirectedUrl(openIdEndpointUrl + expectedReturnTo)); }
@Before public void setUp() throws Exception { filter = new OpenIDAuthenticationFilter(); filter.setConsumer(new MockOpenIDConsumer(REDIRECT_URL)); SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); filter.setAuthenticationSuccessHandler(new SavedRequestAwareAuthenticationSuccessHandler()); successHandler.setDefaultTargetUrl(DEFAULT_TARGET_URL); filter.setAuthenticationManager(new AuthenticationManager() { public Authentication authenticate(Authentication a) { return a; } }); filter.afterPropertiesSet(); }
@Override public void configure(H http) throws Exception { getAuthenticationFilter().setConsumer(getConsumer()); super.configure(http); }
@Override public void configure(H http) throws Exception { getAuthenticationFilter().setConsumer(getConsumer()); super.configure(http); }
@Override public void configure(H http) throws Exception { getAuthenticationFilter().setConsumer(getConsumer()); super.configure(http); }