ConfigurableProviderManager extends ProviderManager implements UserDetailsService, AuthenticationItemConfigurationManager { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return loadUserDetails(username).map(userDetailsMapper) .orElseThrow(() -> new UsernameNotFoundException(username)); } ConfigurableProviderManager(); void reload(); @Override List<AuthenticationProvider> getProviders(); @Override UserDetails loadUserByUsername(String username); @Override Authentication authenticate(Authentication authentication); void reorder(String first,
                        String second); @Override void updateAuthenticationItems(AuthenticationItems items); @Override AuthenticationItems getAuthenticationItems(); @Override T getCustomAuthenticationItem(CustomAuthenticationItemMapper<T> mapper); @Override void putCustomAuthenticationItem(T customAuthenticationItem,
                                                CustomAuthenticationItemMapper<T> mapper); @Override void testCustomAuthenticationItem(T customAuthenticationItem,
                                                 CustomAuthenticationItemMapper<T> mapper,
                                                 Predicate<ApplicationContext> p); @EventListener({ ContextRefreshedEvent.class }) void contextRefreshedEvent(ContextRefreshedEvent e);  }
@Test public void testExternalUserShouldBeReplacedWhenExpired() { UserDto user = new UserDto(); user.setUsername(TEST_DUPLICATE_USER); user.setPassword("foobarpasswrod"); user.setSourceId("someExternalUserSourceId"); user.setLastUpdate(new Date()); strongboxUserManager.cacheExternalUserDetails("someExternalUserSourceId", new StrongboxUserDetails(user)); UserDetails userDetails = userDetailsService.loadUserByUsername(TEST_DUPLICATE_USER); assertThat(userDetails).isNotNull(); assertThat(userDetails).isInstanceOf(SpringSecurityUser.class); assertThat(((SpringSecurityUser)userDetails).getSourceId()).isEqualTo("someExternalUserSourceId"); expireUser(TEST_DUPLICATE_USER); userDetails = userDetailsService.loadUserByUsername(TEST_DUPLICATE_USER); assertThat(userDetails).isNotNull(); assertThat(userDetails.getUsername()).isEqualTo(TEST_DUPLICATE_USER); assertThat(userDetails).isInstanceOf(SpringSecurityUser.class); assertThat(((SpringSecurityUser)userDetails).getSourceId()).isEqualTo("yamlUserDetailService"); }
@Test public void testExternalUserShouldBeUpdatedWhenExpired() { assertThat(strongboxUserManager.findByUsername(TEST_USER)).isNull(); assertThat(userDetailsService.loadUserByUsername(TEST_USER)).isNotNull(); User externalUser = strongboxUserManager.findByUsername(TEST_USER); String externalUserId = ((UserEntry)externalUser).getObjectId(); assertThat(externalUser).isNotNull(); assertThat(externalUserId).isNotNull(); User externalUserToSave = externalUser; assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> orientDbUserService.save(externalUserToSave)) .withMessageMatching("Can't modify external users."); String newPassword = UUID.randomUUID().toString(); UserDto userToUpdate = new UserDto(); userToUpdate.setUsername(TEST_USER); userToUpdate.setPassword(newPassword); yamlUserService.updateAccountDetailsByUsername(new EncodedPasswordUser(userToUpdate, passwordEncoder)); expireUser(TEST_USER); assertThat(userDetailsService.loadUserByUsername(TEST_USER)).isNotNull(); externalUser = strongboxUserManager.findByUsername(TEST_USER); assertThat(externalUser).isNotNull(); assertThat(passwordEncoder.matches(newPassword, externalUser.getPassword())).isTrue(); assertThat(((UserEntry)externalUser).getObjectId()).isEqualTo(externalUserId); }