feat: added UserDetailsServiceImpl
This commit is contained in:
parent
f0b45b78e2
commit
a62f3f9c08
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user