LogsearchLdapAuthenticationProvider extends
  LogsearchAbstractAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthLdapEnabled()) { logger.debug("Ldap auth is disabled"); return authentication; } try { LdapAuthenticationProvider authProvider = loadLdapAuthenticationProvider(); if (authProvider != null) { return authProvider.authenticate(authentication); } else { return authentication; } } catch (AuthenticationException e) { logger.info("Got exception during LDAP authentication attempt", e); Throwable cause = e.getCause(); if (cause != null) { if ((cause != e) && (cause instanceof org.springframework.ldap.AuthenticationException)) { logger.warn( "Looks like LDAP manager credentials (that are used for " + "connecting to LDAP server) are invalid.", e); } } } catch (CommunicationException e) { logger.error(e); } catch (Exception e) { logger.error(e, e.getCause()); } if (authentication != null && !authentication.isAuthenticated()) { logger.warn("Ldap authentication failed. username=" + authentication.getName() + ", details=" + authentication.getDetails()); throw new BadCredentialsException("Invalid credentials!!"); } return authentication; } LogsearchLdapAuthenticationProvider(); @PostConstruct void postConstruct(); @Override Authentication authenticate(Authentication authentication);  }
@Test public void testAuthenticationDisabled() { expect(mockAuthPropsConfig.isAuthLdapEnabled()).andReturn(false); replay(mockAuthPropsConfig); Authentication authentication = new TestingAuthenticationToken("principal", "credentials"); assertSame(provider.authenticate(authentication), authentication); verify(mockAuthPropsConfig); }