diff --git a/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java b/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java index cf8cdb3..511a8d9 100644 --- a/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java +++ b/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java @@ -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 = employeeRepository.findByEmail(email); + if (employee.isEmpty()) throw new UsernameNotFoundException("Employee not found!"); + return employee.get(); } }