Ignore:
Timestamp:
05/06/25 00:44:02 (12 days ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
e48199a
Parents:
142c0f8
Message:

Normalization needed to continue, till here done

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/UserServiceImpl.java

    r142c0f8 rb67dfd3  
    1616import org.openqa.selenium.InvalidArgumentException;
    1717import org.springframework.http.HttpStatus;
     18import org.springframework.security.core.userdetails.UserDetails;
     19import org.springframework.security.core.userdetails.UserDetailsService;
     20import org.springframework.security.core.userdetails.UsernameNotFoundException;
    1821import org.springframework.security.crypto.password.PasswordEncoder;
    1922import org.springframework.stereotype.Service;
     
    2528@RequiredArgsConstructor
    2629@Service
    27 public class UserServiceImpl implements UserService {
     30public class UserServiceImpl implements UserService, UserDetailsService {
    2831    private final UserRepository userRepository;
    2932    private final UserMapperImpl userMapper;
     
    7881        return userRepository.findById(userId).orElseThrow(()->new InvalidArgumentException("Invalid user Id"));
    7982    }
     83
     84    @Override
     85    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
     86        User user = userRepository.findByEmail(email)
     87                .orElseThrow(()-> new UsernameNotFoundException("User not found"));
     88        return org.springframework.security.core.userdetails.User
     89                .withUsername(user.getEmail())
     90                .password(user.getPassword())
     91                .authorities(user.getRole().name()) // adjust if needed
     92                .build();
     93    }
    8094}
Note: See TracChangeset for help on using the changeset viewer.