NTO-2026-Backend-TeamTask-T.../src/main/java/com/example/nto/service/impl/CustomUserDetailsServiceImpl.java
2026-02-26 14:40:08 +03:00

24 lines
1.1 KiB
Java

package com.example.nto.service.impl;
import com.example.nto.entity.Employee;
import com.example.nto.exception.NoSuchUsernameException;
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;
import java.util.ArrayList;
public class CustomUserDetailsServiceImpl implements UserDetailsService {
@Autowired private EmployeeRepository employeeRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Employee employee = employeeRepository.findByUsername(username).orElseThrow(() -> new NoSuchUsernameException("No employee with " + username + " username!!!"));
return new org.springframework.security.core.userdetails.User(employee.getUsername(),
employee.getPassword(),
new ArrayList<>());
}
}