@Test void testLoadUserByUsernameUnknownUser() { String username = "unknownUser"; @SuppressWarnings("unchecked") Query<User> userQuery = mock(Query.class, RETURNS_SELF); doReturn(userQuery).when(dataService).query(USER, User.class); when(userQuery.eq(USERNAME, username).findOne()).thenReturn(null); Exception exception = assertThrows( UsernameNotFoundException.class, () -> userDetailsServiceImpl.loadUserByUsername(username)); assertThat(exception.getMessage()).containsPattern("unknown user 'unknownUser'"); }
@Override @RunAsSystem public UserDetails loadUserByUsername(String username) { User user = dataService .query(UserMetadata.USER, User.class) .eq(UserMetadata.USERNAME, username) .findOne(); if (user == null) { throw new UsernameNotFoundException("unknown user '" + username + "'"); } Collection<? extends GrantedAuthority> authorities = getAuthorities(user); return new org.springframework.security.core.userdetails.User( user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities); }
UserDetailsServiceImpl implements UserDetailsService { @Override @RunAsSystem public UserDetails loadUserByUsername(String username) { User user = dataService .query(UserMetadata.USER, User.class) .eq(UserMetadata.USERNAME, username) .findOne(); if (user == null) { throw new UsernameNotFoundException("unknown user '" + username + "'"); } Collection<? extends GrantedAuthority> authorities = getAuthorities(user); return new org.springframework.security.core.userdetails.User( user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities); } }
UserDetailsServiceImpl implements UserDetailsService { @Override @RunAsSystem public UserDetails loadUserByUsername(String username) { User user = dataService .query(UserMetadata.USER, User.class) .eq(UserMetadata.USERNAME, username) .findOne(); if (user == null) { throw new UsernameNotFoundException("unknown user '" + username + "'"); } Collection<? extends GrantedAuthority> authorities = getAuthorities(user); return new org.springframework.security.core.userdetails.User( user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities); } UserDetailsServiceImpl(
      DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper); }
UserDetailsServiceImpl implements UserDetailsService { @Override @RunAsSystem public UserDetails loadUserByUsername(String username) { User user = dataService .query(UserMetadata.USER, User.class) .eq(UserMetadata.USERNAME, username) .findOne(); if (user == null) { throw new UsernameNotFoundException("unknown user '" + username + "'"); } Collection<? extends GrantedAuthority> authorities = getAuthorities(user); return new org.springframework.security.core.userdetails.User( user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities); } UserDetailsServiceImpl(
      DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper); @Override @RunAsSystem UserDetails loadUserByUsername(String username); @RunAsSystem Collection<? extends GrantedAuthority> getAuthorities(User user); }
UserDetailsServiceImpl implements UserDetailsService { @Override @RunAsSystem public UserDetails loadUserByUsername(String username) { User user = dataService .query(UserMetadata.USER, User.class) .eq(UserMetadata.USERNAME, username) .findOne(); if (user == null) { throw new UsernameNotFoundException("unknown user '" + username + "'"); } Collection<? extends GrantedAuthority> authorities = getAuthorities(user); return new org.springframework.security.core.userdetails.User( user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities); } UserDetailsServiceImpl(
      DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper); @Override @RunAsSystem UserDetails loadUserByUsername(String username); @RunAsSystem Collection<? extends GrantedAuthority> getAuthorities(User user);  }