use of org.springframework.security.AuthenticationManager in project gocd by gocd.
the class BasicAuthenticationFilterTest method shouldConvey_itsBasicProcessingFilter.
@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[] { false };
filter.setAuthenticationManager(new AuthenticationManager() {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
return new UsernamePasswordAuthenticationToken("school-principal", "u can be principal if you know this!");
}
});
assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
MockHttpServletRequest httpRequest = new MockHttpServletRequest();
httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("loser:boozer".getBytes()));
filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}
use of org.springframework.security.AuthenticationManager in project gocd by gocd.
the class PreAuthenticatedRequestsProcessingFilterTest method setUp.
@Before
public void setUp() throws Exception {
request = mock(HttpServletRequest.class);
response = mock(HttpServletResponse.class);
filterChain = mock(FilterChain.class);
authenticationManager = mock(AuthenticationManager.class);
authorizationExtension = mock(AuthorizationExtension.class);
configService = mock(GoConfigService.class);
filter = new PreAuthenticatedRequestsProcessingFilter(authorizationExtension, configService);
securityConfig = new SecurityConfig();
filter.setAuthenticationManager(authenticationManager);
filter.setFilterProcessesUrl("^/go/plugin/([\\w\\-.]+)/authenticate$");
stub(configService.security()).toReturn(securityConfig);
stub(request.getHeaderNames()).toReturn(Collections.emptyEnumeration());
}
Aggregations