LdapCustomAuthenticationProvider extends LdapAuthenticationProvider { @Override protected UserDetails createUserDetails(LdapUserDetails ldapUser, String username, String password) { Principal principalFromDB = (Principal) userDetailsService.loadUserByUsername(username); return mergeUsers(ldapUser, principalFromDB, password); } LdapCustomAuthenticationProvider(LdapAuthenticator authenticator,
                                            LdapAuthoritiesPopulator authoritiesPopulator); void setUserDetailsService(UserDetailsService userDetailsService);  }
@Test public void shouldCallLoadUserFromServiceWhenCreateUserDetailsIsCalled(){ User user = getUserForTest(); Principal principal = mock(Principal.class); when(userDetailsService.loadUserByUsername(USERNAME)).thenReturn(principal); when(principal.getUser()).thenReturn(user); when(principal.getAuthorities()).thenReturn(new GrantedAuthority[1]); when(ldapUserDetails.getAttributes()).thenReturn(mock(Attributes.class)); sut.createUserDetails(ldapUserDetails, USERNAME, PASSWORD); verify(userDetailsService).loadUserByUsername(USERNAME); verify(ldapUserDetails).isEnabled(); }