Minipigs-Back/src/main/java/com/example/nto/websecurity/UserDetailsServiceImpl.java
2025-02-19 11:36:05 +03:00

22 lines
808 B
Java

package com.example.nto.websecurity;
import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private EmployeeRepository repository;
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
Employee employee = repository.findByLogin(s).orElseThrow(() -> new UsernameNotFoundException(s));
return new CustomUserDetails(employee);
}
}