@Test void willThrowUsernameNotFoundException_WhenUserIsNotFound() { doThrow(NoSuchElementException.class).when(authServerUserReadService).getByUsername(USER_NAME); assertThrows(UsernameNotFoundException.class, () -> authServerUserDetailsService.loadUserByUsername(USER_NAME)); }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AuthServerUser authServerUser; try { authServerUser = authServerUserReadService.getByUsername(username); } catch (NoSuchElementException e) { throw new UsernameNotFoundException("Invalid credentials", e); } return org.springframework.security.core.userdetails.User.builder() .username(authServerUser.getUsername()) .password(authServerUser.getEncodedPassword()) .disabled(authServerUser.isDisabled()) .roles() .build(); }
AuthServerUserDetailsService implements AuthenticationServerUserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AuthServerUser authServerUser; try { authServerUser = authServerUserReadService.getByUsername(username); } catch (NoSuchElementException e) { throw new UsernameNotFoundException("Invalid credentials", e); } return org.springframework.security.core.userdetails.User.builder() .username(authServerUser.getUsername()) .password(authServerUser.getEncodedPassword()) .disabled(authServerUser.isDisabled()) .roles() .build(); } }
AuthServerUserDetailsService implements AuthenticationServerUserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AuthServerUser authServerUser; try { authServerUser = authServerUserReadService.getByUsername(username); } catch (NoSuchElementException e) { throw new UsernameNotFoundException("Invalid credentials", e); } return org.springframework.security.core.userdetails.User.builder() .username(authServerUser.getUsername()) .password(authServerUser.getEncodedPassword()) .disabled(authServerUser.isDisabled()) .roles() .build(); } @Autowired  AuthServerUserDetailsService(AuthServerUserReadService authServerUserReadService); }
AuthServerUserDetailsService implements AuthenticationServerUserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AuthServerUser authServerUser; try { authServerUser = authServerUserReadService.getByUsername(username); } catch (NoSuchElementException e) { throw new UsernameNotFoundException("Invalid credentials", e); } return org.springframework.security.core.userdetails.User.builder() .username(authServerUser.getUsername()) .password(authServerUser.getEncodedPassword()) .disabled(authServerUser.isDisabled()) .roles() .build(); } @Autowired  AuthServerUserDetailsService(AuthServerUserReadService authServerUserReadService); @Override UserDetails loadUserByUsername(String username); }
AuthServerUserDetailsService implements AuthenticationServerUserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AuthServerUser authServerUser; try { authServerUser = authServerUserReadService.getByUsername(username); } catch (NoSuchElementException e) { throw new UsernameNotFoundException("Invalid credentials", e); } return org.springframework.security.core.userdetails.User.builder() .username(authServerUser.getUsername()) .password(authServerUser.getEncodedPassword()) .disabled(authServerUser.isDisabled()) .roles() .build(); } @Autowired  AuthServerUserDetailsService(AuthServerUserReadService authServerUserReadService); @Override UserDetails loadUserByUsername(String username);  }