Search in sources :

Example 6 with BadCredentialsException

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
}
Also used : BadCredentialsException(org.springframework.security.BadCredentialsException) Test(org.junit.Test)

Example 7 with BadCredentialsException

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) {
    }
}
Also used : BadCredentialsException(org.springframework.security.BadCredentialsException) X509Certificate(java.security.cert.X509Certificate) X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator) Test(org.junit.Test)

Example 8 with BadCredentialsException

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());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BadCredentialsException(org.springframework.security.BadCredentialsException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

BadCredentialsException (org.springframework.security.BadCredentialsException)8 Test (org.junit.Test)4 User (org.springframework.security.userdetails.User)2 LdapConfig (com.thoughtworks.go.config.LdapConfig)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)1 X509CertificateGenerator (com.thoughtworks.go.security.X509CertificateGenerator)1 OauthDataSource (com.thoughtworks.go.server.oauth.OauthDataSource)1 OauthAuthenticationToken (com.thoughtworks.go.server.security.OauthAuthenticationToken)1 X509Certificate (java.security.cert.X509Certificate)1 Matcher (java.util.regex.Matcher)1 X500Principal (javax.security.auth.x500.X500Principal)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 Authentication (org.springframework.security.Authentication)1 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)1 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)1 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)1 UserDetails (org.springframework.security.userdetails.UserDetails)1 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)1