use of org.springframework.security.BadCredentialsException in project gocd by gocd.
the class LdapUserSearch method searchForUser.
public DirContextOperations searchForUser(String username) {
SecurityConfig securityConfig = goConfigService.security();
if (!securityConfig.isSecurityEnabled()) {
return null;
}
LdapConfig ldapConfig = securityConfig.ldapConfig();
RuntimeException lastFoundException = null;
BaseConfig failedBaseConfig = null;
for (BaseConfig baseConfig : ldapConfig.getBasesConfig()) {
if (lastFoundException != null && !(lastFoundException instanceof BadCredentialsException)) {
logger.warn(String.format("The ldap configuration for search base '%s' is invalid", failedBaseConfig.getValue()), lastFoundException);
}
FilterBasedLdapUserSearch search = getFilterBasedLdapUserSearch(baseConfig.getValue(), ldapConfig.searchFilter());
search.setSearchSubtree(true);
// timeout after five seconds
search.setSearchTimeLimit(5000);
try {
return search.searchForUser(username);
} catch (UsernameNotFoundException e) {
failedBaseConfig = baseConfig;
lastFoundException = new BadCredentialsException("Bad credentials");
} catch (RuntimeException e) {
failedBaseConfig = baseConfig;
lastFoundException = e;
}
}
if (lastFoundException != null) {
throw lastFoundException;
}
throw new RuntimeException("No LDAP Search Bases are configured.");
}
use of org.springframework.security.BadCredentialsException in project gocd by gocd.
the class LdapAuthenticationTest method assertFailedAuthentication.
private void assertFailedAuthentication(String userName, String password) {
Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
try {
ldapAuthenticationProvider.authenticate(authentication);
fail("Expected authentication to fail for user: " + userName);
} catch (BadCredentialsException e) {
}
}
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 AuthenticationProcessingFilterTest method shouldNotSetSecurityExceptionMessageOnSessionWhenBadCredentialsExceptionIsThrownBySpring.
@Test
public void shouldNotSetSecurityExceptionMessageOnSessionWhenBadCredentialsExceptionIsThrownBySpring() throws Exception {
filter.onUnsuccessfulAuthentication(request, null, new BadCredentialsException("foobar"));
assertThat(session.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY), is(nullValue()));
}
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