22 lines
808 B
Java
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);
|
|
}
|
|
}
|