feat: added UserDetailsServiceImpl

This commit is contained in:
Petr Rudichev 2025-02-19 15:29:59 +03:00
parent f0b45b78e2
commit a62f3f9c08

View File

@ -1,14 +1,24 @@
package com.example.nto.service.impl;
import com.example.nto.domain.entity.Employee;
import com.example.nto.repository.EmployeeRepository;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {
private final EmployeeRepository employeeRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return null;
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
Optional<Employee> employee = employeeRepository.findByEmail(email);
if (employee.isEmpty()) throw new UsernameNotFoundException("Employee not found!");
return employee.get();
}
}