feat(auth): switch CustomUserDetailsService to email-based lookup
loadUserByUsername now calls findByEmail and returns email as the Spring Security principal name. Tests updated to assert email identity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -29,24 +29,22 @@ public class CustomUserDetailsService implements UserDetailsService {
|
||||
private final AppUserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
AppUser appUser = userRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new UsernameNotFoundException("User nicht gefunden: " + username));
|
||||
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
||||
AppUser appUser = userRepository.findByEmail(email)
|
||||
.orElseThrow(() -> new UsernameNotFoundException("User nicht gefunden: " + email));
|
||||
|
||||
// Collect all permissions from all groups; warn about any that don't match a known Permission enum value
|
||||
var authorities = appUser.getGroups().stream()
|
||||
.flatMap(group -> group.getPermissions().stream())
|
||||
.peek(p -> {
|
||||
if (!KNOWN_PERMISSIONS.contains(p)) {
|
||||
log.warn("Unknown permission '{}' found in database for user '{}' — it will be granted but never matched by @RequirePermission", p, appUser.getUsername());
|
||||
log.warn("Unknown permission '{}' found in database for user '{}' — it will be granted but never matched by @RequirePermission", p, appUser.getEmail());
|
||||
}
|
||||
})
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Rückgabe des Standard Spring Security User Objekts
|
||||
return new User(
|
||||
appUser.getUsername(),
|
||||
appUser.getEmail(),
|
||||
appUser.getPassword(),
|
||||
appUser.isEnabled(),
|
||||
true, true, true,
|
||||
|
||||
Reference in New Issue
Block a user