use of org.springframework.security.BadCredentialsException in project gocd by gocd.
the class OauthAuthenticationFilterTest method shouldContinueExecutingFilterChainEvenIfTokenAuthenticationFails.
@Test
public void shouldContinueExecutingFilterChainEvenIfTokenAuthenticationFails() throws IOException, ServletException {
when(req.getHeader(OauthAuthenticationFilter.AUTHORIZATION)).thenReturn("Token token=\"invalid-token\"");
when(authenticationManager.authenticate(new OauthAuthenticationToken("invalid-token"))).thenThrow(new BadCredentialsException("failed to auth"));
filter.doFilterHttp(req, res, chain);
verify(securityContext).setAuthentication(null);
verify(chain).doFilter(req, res);
//assertThat(logFixture.contains(Level.DEBUG, "Oauth authorization header: Token token=\"invalid-token\""), is(true)); //uncomment this to run it locally (this fails on build, we need to find out why). -Rajesh & JJ
//assertThat(logFixture.contains(Level.DEBUG, "Oauth authentication request for token: invalid-token failed: "), is(true)); //uncomment this to run it locally (this fails on build, we need to find out why). -Rajesh & JJ
}
use of org.springframework.security.BadCredentialsException in project gocd by gocd.
the class X509AuthoritiesPopulatorTest method shouldNotReturnUserDetailsIfCertificateHasNoOu.
@Test
public void shouldNotReturnUserDetailsIfCertificateHasNoOu() {
X509Certificate agentCertificate = new X509CertificateGenerator().createCertificateWithDn("CN=hostname").getFirstCertificate();
try {
populator.getUserDetails(agentCertificate);
Assert.fail("Oh dear. You should have thrown an exception, silly!");
} catch (BadCredentialsException ignored) {
}
}
use of org.springframework.security.BadCredentialsException in project gocd by gocd.
the class BasicProcessingFilterEntryPointTest method testShouldRender401WithWithHTMLWithNoAcceptHeader.
@Test
public void testShouldRender401WithWithHTMLWithNoAcceptHeader() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
new BasicProcessingFilterEntryPoint().commence(request, response, new BadCredentialsException("foo"));
assertEquals("Basic realm=\"GoCD\"", response.getHeader("WWW-Authenticate"));
assertEquals(401, response.getStatus());
assertEquals("foo", response.getErrorMessage());
}
Aggregations